Rework the ioctl() syscall, clean up arguments
This commit is contained in:
@ -12,16 +12,17 @@
|
||||
#define IOCTL_MP_MAX 0xff
|
||||
#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 cmd = cmd1;
|
||||
int32_t ret = E_BADIO;
|
||||
|
||||
switch (cmd) {
|
||||
case IOCTL_OPENF: {
|
||||
IOCtlOF *ioctlof = (IOCtlOF *)(void *)optsptr1;
|
||||
|
||||
if (ioctlof == NULL) {
|
||||
const char *opath = (const char *)arg1;
|
||||
uint64_t oflags = arg2;
|
||||
|
||||
if (opath == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
@ -29,14 +30,9 @@ int32_t SYSCALL3(sys_ioctl, ioh1, cmd1, optsptr1) {
|
||||
char mp[IOCTL_MP_MAX];
|
||||
char path[IOCTL_PATH_MAX];
|
||||
|
||||
if (ioctlof->path == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
path_parse(opath, mp, path);
|
||||
|
||||
path_parse(ioctlof->path, mp, path);
|
||||
|
||||
VfsObj *vobj = vfs_open(mp, path, ioctlof->flags);
|
||||
VfsObj *vobj = vfs_open(mp, path, oflags);
|
||||
if (vobj == NULL) {
|
||||
ret = E_NOENTRY;
|
||||
goto done;
|
||||
@ -82,14 +78,11 @@ int32_t SYSCALL3(sys_ioctl, ioh1, cmd1, optsptr1) {
|
||||
ret = E_OK;
|
||||
} break;
|
||||
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) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (ioctlwf->buffer == NULL) {
|
||||
if (buffer == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
@ -110,17 +103,14 @@ int32_t SYSCALL3(sys_ioctl, ioh1, cmd1, optsptr1) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = vobj->write(vobj, ioctlwf->buffer, ioctlwf->len, ioctlwf->off);
|
||||
ret = vobj->write(vobj, buffer, len, off);
|
||||
} break;
|
||||
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) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (ioctlrf->buffer == NULL) {
|
||||
if (buffer == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
@ -141,7 +131,7 @@ int32_t SYSCALL3(sys_ioctl, ioh1, cmd1, optsptr1) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = vobj->read(vobj, ioctlrf->buffer, ioctlrf->len, ioctlrf->off);
|
||||
ret = vobj->read(vobj, buffer, len, off);
|
||||
} break;
|
||||
default: {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
|
@ -4,6 +4,6 @@
|
||||
#include <stdint.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_
|
||||
|
Reference in New Issue
Block a user