Simple file IO with the ioctl syscall
This commit is contained in:
@ -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))))
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user