Rework the ioctl() syscall, clean up arguments
This commit is contained in:
@ -12,16 +12,17 @@
|
|||||||
#define IOCTL_MP_MAX 0xff
|
#define IOCTL_MP_MAX 0xff
|
||||||
#define IOCTL_PATH_MAX VFS_PATH_MAX
|
#define IOCTL_PATH_MAX VFS_PATH_MAX
|
||||||
|
|
||||||
int32_t SYSCALL3(sys_ioctl, ioh1, cmd1, optsptr1) {
|
int32_t SYSCALL5(sys_ioctl, ioh1, cmd1, arg1, arg2, arg3) {
|
||||||
uint64_t ioh = ioh1;
|
uint64_t ioh = ioh1;
|
||||||
uint64_t cmd = cmd1;
|
uint64_t cmd = cmd1;
|
||||||
int32_t ret = E_BADIO;
|
int32_t ret = E_BADIO;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case IOCTL_OPENF: {
|
case IOCTL_OPENF: {
|
||||||
IOCtlOF *ioctlof = (IOCtlOF *)(void *)optsptr1;
|
const char *opath = (const char *)arg1;
|
||||||
|
uint64_t oflags = arg2;
|
||||||
if (ioctlof == NULL) {
|
|
||||||
|
if (opath == NULL) {
|
||||||
ret = E_INVALIDARGUMENT;
|
ret = E_INVALIDARGUMENT;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@ -29,14 +30,9 @@ int32_t SYSCALL3(sys_ioctl, ioh1, cmd1, optsptr1) {
|
|||||||
char mp[IOCTL_MP_MAX];
|
char mp[IOCTL_MP_MAX];
|
||||||
char path[IOCTL_PATH_MAX];
|
char path[IOCTL_PATH_MAX];
|
||||||
|
|
||||||
if (ioctlof->path == NULL) {
|
path_parse(opath, mp, path);
|
||||||
ret = E_INVALIDARGUMENT;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
path_parse(ioctlof->path, mp, path);
|
VfsObj *vobj = vfs_open(mp, path, oflags);
|
||||||
|
|
||||||
VfsObj *vobj = vfs_open(mp, path, ioctlof->flags);
|
|
||||||
if (vobj == NULL) {
|
if (vobj == NULL) {
|
||||||
ret = E_NOENTRY;
|
ret = E_NOENTRY;
|
||||||
goto done;
|
goto done;
|
||||||
@ -82,14 +78,11 @@ int32_t SYSCALL3(sys_ioctl, ioh1, cmd1, optsptr1) {
|
|||||||
ret = E_OK;
|
ret = E_OK;
|
||||||
} break;
|
} break;
|
||||||
case IOCTL_WRITE: {
|
case IOCTL_WRITE: {
|
||||||
IOCtlWF *ioctlwf = (IOCtlWF *)(void *)optsptr1;
|
const uint8_t *const buffer = (const uint8_t *const)arg1;
|
||||||
|
size_t len = (size_t)arg2;
|
||||||
|
size_t off = (size_t)arg3;
|
||||||
|
|
||||||
if (ioctlwf == NULL) {
|
if (buffer == NULL) {
|
||||||
ret = E_INVALIDARGUMENT;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ioctlwf->buffer == NULL) {
|
|
||||||
ret = E_INVALIDARGUMENT;
|
ret = E_INVALIDARGUMENT;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@ -110,17 +103,14 @@ int32_t SYSCALL3(sys_ioctl, ioh1, cmd1, optsptr1) {
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = vobj->write(vobj, ioctlwf->buffer, ioctlwf->len, ioctlwf->off);
|
ret = vobj->write(vobj, buffer, len, off);
|
||||||
} break;
|
} break;
|
||||||
case IOCTL_READ: {
|
case IOCTL_READ: {
|
||||||
IOCtlRF *ioctlrf = (IOCtlRF *)(void *)optsptr1;
|
uint8_t *const buffer = (uint8_t *const)arg1;
|
||||||
|
size_t len = (size_t)arg2;
|
||||||
|
size_t off = (size_t)arg3;
|
||||||
|
|
||||||
if (ioctlrf == NULL) {
|
if (buffer == NULL) {
|
||||||
ret = E_INVALIDARGUMENT;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ioctlrf->buffer == NULL) {
|
|
||||||
ret = E_INVALIDARGUMENT;
|
ret = E_INVALIDARGUMENT;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@ -141,7 +131,7 @@ int32_t SYSCALL3(sys_ioctl, ioh1, cmd1, optsptr1) {
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = vobj->read(vobj, ioctlrf->buffer, ioctlrf->len, ioctlrf->off);
|
ret = vobj->read(vobj, buffer, len, off);
|
||||||
} break;
|
} break;
|
||||||
default: {
|
default: {
|
||||||
ret = E_INVALIDARGUMENT;
|
ret = E_INVALIDARGUMENT;
|
||||||
|
@ -4,6 +4,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "syscall.h"
|
#include "syscall.h"
|
||||||
|
|
||||||
int32_t SYSCALL3(sys_ioctl, ioh1, cmd1, optsptr1);
|
int32_t SYSCALL5(sys_ioctl, ioh1, cmd1, arg1, arg2, arg3);
|
||||||
|
|
||||||
#endif // SYSCALL_IOCTL_H_
|
#endif // SYSCALL_IOCTL_H_
|
||||||
|
@ -20,21 +20,4 @@ enum {
|
|||||||
IOCTL_F_MAKE = 1<<2,
|
IOCTL_F_MAKE = 1<<2,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *path;
|
|
||||||
int32_t flags;
|
|
||||||
} IOCtlOF;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const uint8_t *const buffer;
|
|
||||||
size_t len;
|
|
||||||
size_t off;
|
|
||||||
} IOCtlWF;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint8_t *const buffer;
|
|
||||||
size_t len;
|
|
||||||
size_t off;
|
|
||||||
} IOCtlRF;
|
|
||||||
|
|
||||||
#endif // SHARE_SYSDEFS_IOCTL_H_
|
#endif // SHARE_SYSDEFS_IOCTL_H_
|
||||||
|
@ -5,25 +5,7 @@
|
|||||||
#include <sysdefs/syscall.h>
|
#include <sysdefs/syscall.h>
|
||||||
#include <syscall/syscall.h>
|
#include <syscall/syscall.h>
|
||||||
|
|
||||||
int32_t ioctl(uint64_t ioh, uint64_t cmd, void *extra) {
|
int32_t ioctl(uint64_t ioh, uint64_t cmd, uint64_t arg1, uint64_t arg2, uint64_t arg3) {
|
||||||
return syscall(SYS_IOCTL, ioh, cmd, (uint64_t)extra, 0, 0, 0);
|
return syscall(SYS_IOCTL, ioh, cmd, arg1, arg2, arg3, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ioctl_openfile(const char *path, uint64_t flags) {
|
|
||||||
IOCtlOF cfg = { .path = path, .flags = flags };
|
|
||||||
return ioctl(IOCTL_NOHANDLE, IOCTL_OPENF, &cfg);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t ioctl_writefile(int32_t ioh, const uint8_t *const buffer, size_t len, size_t off) {
|
|
||||||
IOCtlWF cfg = { .buffer = buffer, .len = len, .off = off };
|
|
||||||
return ioctl(ioh, IOCTL_WRITE, &cfg);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t ioctl_readfile(int32_t ioh, uint8_t *const buffer, size_t len, size_t off) {
|
|
||||||
IOCtlRF cfg = { .buffer = buffer, .len = len, off = off };
|
|
||||||
return ioctl(ioh, IOCTL_READ, &cfg);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t ioctl_closefile(int32_t ioh) {
|
|
||||||
return ioctl(ioh, IOCTL_CLOSEF, NULL);
|
|
||||||
}
|
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
int32_t ioctl(uint64_t ioh, uint64_t cmd, void *extra);
|
#define IOCTL_PATH(p) ((uint64_t)(p))
|
||||||
int32_t ioctl_openfile(const char *path, uint64_t flags);
|
#define IOCTL_BUF(b) ((uint64_t)(b))
|
||||||
int32_t ioctl_writefile(int32_t ioh, const uint8_t *const buffer, size_t len, size_t off);
|
#define IOCTL_SIZE(sz) ((uint64_t)(sz))
|
||||||
int32_t ioctl_readfile(int32_t ioh, uint8_t *const buffer, size_t len, size_t off);
|
#define IOCTL_OFF(off) ((uint64_t)(off))
|
||||||
int32_t ioctl_closefile(int32_t ioh);
|
|
||||||
|
int32_t ioctl(uint64_t ioh, uint64_t cmd, uint64_t arg1, uint64_t arg2, uint64_t arg3);
|
||||||
|
|
||||||
#endif // ULIB_SYSTEM_IOCTL_H_
|
#endif // ULIB_SYSTEM_IOCTL_H_
|
||||||
|
@ -13,17 +13,22 @@ void main(void) {
|
|||||||
debugprint(ANSIQ_SCR_CLR_ALL);
|
debugprint(ANSIQ_SCR_CLR_ALL);
|
||||||
debugprint(ANSIQ_CUR_SET(0, 0));
|
debugprint(ANSIQ_CUR_SET(0, 0));
|
||||||
|
|
||||||
int32_t ioh = ioctl_openfile("base:/hello.txt", IOCTL_F_WRITE | IOCTL_F_READ | IOCTL_F_MAKE);
|
int32_t ioh = ioctl(IOCTL_NOHANDLE,
|
||||||
|
IOCTL_OPENF,
|
||||||
char *text = "Hello from the filesystem";
|
(uint64_t)"base:/hello.txt",
|
||||||
ioctl_writefile(ioh, (const uint8_t *const)text, string_len(text), 0);
|
IOCTL_F_WRITE | IOCTL_F_READ | IOCTL_F_MAKE,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
char *text = "Hello from FS";
|
||||||
|
ioctl(ioh, IOCTL_WRITE, (uint64_t)text, string_len(text), 0);
|
||||||
|
|
||||||
char buf[0x100] = {0};
|
char buf[0x100] = {0};
|
||||||
ioctl_readfile(ioh, (uint8_t *const)buf, string_len(text), 0);
|
ioctl(ioh, IOCTL_READ, (uint64_t)buf, string_len(text), 0);
|
||||||
|
|
||||||
uprintf("FILE: %s\n", buf);
|
uprintf("file contents: %s\n", buf);
|
||||||
|
|
||||||
ioctl_closefile(ioh);
|
ioctl(ioh, IOCTL_CLOSEF, 0, 0, 0);
|
||||||
|
|
||||||
uprintf("Hello world using uprintf\n");
|
uprintf("Hello world using uprintf\n");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user