Simple file IO with the ioctl syscall

This commit is contained in:
2025-09-05 19:56:27 +02:00
parent f42c4b7e44
commit fb5e88a175
16 changed files with 299 additions and 6 deletions

View File

@ -1,5 +1,5 @@
CFLAGS := -ffreestanding -Wall -Wextra -g -fcommon -nostdinc \
-isystem $(ROOT)/std/include -isystem $(ROOT)/ulib
-isystem $(ROOT)/std/include -isystem $(ROOT)/ulib -isystem $(ROOT)/share
CURRENT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

View File

@ -1,6 +1,23 @@
#include <system/system.h>
#include <sysdefs/ioctl.h>
#include <string/string.h>
void main(void) {
sys_debugprint("Hello world from userspace in C");
debugprint("Hello world from userspace in C");
IOCtlOF ioctlof = { .path = "base:/hello.txt", .flags = IOCTL_F_WRITE | IOCTL_F_READ | IOCTL_F_MAKE };
int32_t ioh = ioctl(IOCTL_NOHANDLE, IOCTL_OPENF, &ioctlof);
char *text = "Write to a file";
IOCtlWF ioctlwf = { .buffer = text, .len = string_len(text), .off = 0 };
ioctl(ioh, IOCTL_WRITE, &ioctlwf);
char buf[0x100];
IOCtlRF ioctlrf = { .buffer = buf, .len = string_len(text), .off = 0 };
ioctl(ioh, IOCTL_READ, &ioctlrf);
debugprint(buf);
ioctl(ioh, IOCTL_CLOSEF, NULL);
}