aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/user')
-rw-r--r--src/kernel/user/syscall.c10
-rw-r--r--src/kernel/user/vfs.c13
2 files changed, 22 insertions, 1 deletions
diff --git a/src/kernel/user/syscall.c b/src/kernel/user/syscall.c
index 8a2cf18..6fdd633 100644
--- a/src/kernel/user/syscall.c
+++ b/src/kernel/user/syscall.c
@@ -263,6 +263,15 @@ static uint32_t stat_open_sc(sc_args_t args) {
return file_stat(h, o);
}
+static uint32_t ioctl_open_sc(sc_args_t args) {
+ fs_handle_t *h = proc_read_fd(current_process(), args.a);
+ if (h == 0) return -1;
+
+ void* data = (void*)args.c;
+ if (data >= (void*)K_HIGHHALF_ADDR) return -1;
+ return file_ioctl(h, args.b, data);
+}
+
static uint32_t get_mode_sc(sc_args_t args) {
fs_handle_t *h = proc_read_fd(current_process(), args.a);
if (h == 0) return 0;
@@ -296,6 +305,7 @@ void setup_syscall_table() {
sc_handlers[SC_WRITE] = write_sc;
sc_handlers[SC_READDIR] = readdir_sc;
sc_handlers[SC_STAT_OPEN] = stat_open_sc;
+ sc_handlers[SC_IOCTL_OPEN] = ioctl_open_sc;
sc_handlers[SC_GET_MODE] = get_mode_sc;
}
diff --git a/src/kernel/user/vfs.c b/src/kernel/user/vfs.c
index a5d56ef..ab49553 100644
--- a/src/kernel/user/vfs.c
+++ b/src/kernel/user/vfs.c
@@ -356,7 +356,7 @@ bool fs_stat(fs_t *fs, const char* file, stat_t *st) {
int fs_ioctl(fs_t *fs, const char* file, int command, void* data) {
fs_node_t* n = fs_walk_path(&fs->root, file);
- if (n == 0) return false;
+ if (n == 0) return -1;
mutex_lock(&n->lock);
int ret = (n->ops->ioctl ? n->ops->ioctl(n->data, command, data) : -1);
@@ -461,6 +461,17 @@ bool file_stat(fs_handle_t *f, stat_t *st) {
return ret;
}
+int file_ioctl(fs_handle_t *f, int command, void* data) {
+ if (!(f->mode & FM_IOCTL)) return -1;
+
+ mutex_lock(&f->node->lock);
+ int ret = -1;
+ if (f->node->ops->ioctl) ret = f->node->ops->ioctl(f->node->data, command, data);
+ mutex_unlock(&f->node->lock);
+
+ return ret;
+}
+
bool file_readdir(fs_handle_t *f, dirent_t *d) {
if (!(f->mode & FM_READDIR)) return 0;