aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/user')
-rw-r--r--src/kernel/user/nullfs.c2
-rw-r--r--src/kernel/user/syscall.c79
-rw-r--r--src/kernel/user/vfs.c39
3 files changed, 118 insertions, 2 deletions
diff --git a/src/kernel/user/nullfs.c b/src/kernel/user/nullfs.c
index a44e4b3..534b0ba 100644
--- a/src/kernel/user/nullfs.c
+++ b/src/kernel/user/nullfs.c
@@ -294,7 +294,7 @@ bool nullfs_d_stat(fs_node_ptr n, stat_t *st) {
st->access = FM_READDIR
| (d->fs->can_create ? FM_DCREATE : 0)
| (d->fs->can_move ? FM_DMOVE : 0)
- | (d->fs->can_delete ? FM_DUNLINK : 0);
+ | (d->fs->can_delete ? FM_DDELETE : 0);
st->size = 0;
for (nullfs_item_t *i = d->items_list; i != 0; i = i->next)
diff --git a/src/kernel/user/syscall.c b/src/kernel/user/syscall.c
index bcf6ef4..3def3b5 100644
--- a/src/kernel/user/syscall.c
+++ b/src/kernel/user/syscall.c
@@ -29,6 +29,7 @@ static char* sc_copy_string(uint32_t s, uint32_t slen) {
// THE SYSCALLS CODE !! //
// ==================== //
+// ---- Related to the current process's execution
static uint32_t exit_sc(sc_args_t args) {
dbg_printf("Proc %d exit with code %d\n", current_process()->pid, args.a);
@@ -58,6 +59,8 @@ static uint32_t dbg_print_sc(sc_args_t args) {
return 0;
}
+// ---- Memory management related
+
static uint32_t mmap_sc(sc_args_t args) {
return mmap(current_process(), (void*)args.a, args.b, args.c);
}
@@ -78,6 +81,8 @@ static uint32_t munmap_sc(sc_args_t args) {
return munmap(current_process(), (void*)args.a);
}
+// ---- Accessing the VFS - filesystems
+
static uint32_t create_sc(sc_args_t args) {
bool ret = false;
@@ -175,6 +180,8 @@ end_stat:
return ret;
}
+// ---- Accessing the VFS - files
+
static uint32_t open_sc(sc_args_t args) {
int ret = 0;
@@ -260,6 +267,62 @@ static uint32_t get_mode_sc(sc_args_t args) {
return file_get_mode(h);
}
+// ---- Managing file systems
+
+static uint32_t make_fs_sc(sc_args_t args) {
+ return -1; // TODO
+}
+
+static uint32_t fs_add_src_sc(sc_args_t args) {
+ return -1; //TODO
+}
+
+static uint32_t fs_subfs_sc(sc_args_t args) {
+ return -1; //TODO
+}
+
+static uint32_t rm_fs_sc(sc_args_t args) {
+ return -1; //TODO
+}
+
+// ---- Spawning new processes & giving them ressources
+
+static uint32_t new_proc_sc(sc_args_t args) {
+ return -1; //TODO
+}
+
+static uint32_t bind_fs_sc(sc_args_t args) {
+ return -1; //TODO
+}
+
+static uint32_t bind_subfs_sc(sc_args_t args) {
+ return -1; //TODO
+}
+
+static uint32_t bind_fd_sc(sc_args_t args) {
+ return -1; //TODO
+}
+
+static uint32_t proc_exec_sc(sc_args_t args) {
+ return -1; //TODO
+}
+
+static uint32_t proc_status_sc(sc_args_t args) {
+ return -1; //TODO
+}
+
+static uint32_t proc_kill_sc(sc_args_t args) {
+ return -1; //TODO
+}
+
+static uint32_t proc_wait_sc(sc_args_t args) {
+ return -1; //TODO
+}
+
+static uint32_t proc_wait_any_sc(sc_args_t args) {
+ return -1; //TODO
+}
+
// ====================== //
// SYSCALLS SETUP ROUTINE //
// ====================== //
@@ -288,6 +351,21 @@ void setup_syscall_table() {
sc_handlers[SC_STAT_OPEN] = stat_open_sc;
sc_handlers[SC_IOCTL] = ioctl_sc;
sc_handlers[SC_GET_MODE] = get_mode_sc;
+
+ sc_handlers[SC_MAKE_FS] = make_fs_sc;
+ sc_handlers[SC_FS_ADD_SRC] = fs_add_src_sc;
+ sc_handlers[SC_SUBFS] = fs_subfs_sc;
+ sc_handlers[SC_RM_FS] = rm_fs_sc;
+
+ sc_handlers[SC_NEW_PROC] = new_proc_sc;
+ sc_handlers[SC_BIND_FS] = bind_fs_sc;
+ sc_handlers[SC_BIND_SUBFS] = bind_subfs_sc;
+ sc_handlers[SC_BIND_FD] = bind_fd_sc;
+ sc_handlers[SC_PROC_EXEC] = proc_exec_sc;
+ sc_handlers[SC_PROC_STATUS] = proc_status_sc;
+ sc_handlers[SC_PROC_KILL] = proc_kill_sc;
+ sc_handlers[SC_PROC_WAIT] = proc_wait_sc;
+ sc_handlers[SC_PROC_WAIT_ANY] = proc_wait_any_sc;
}
void syscall_handler(registers_t *regs) {
@@ -304,6 +382,7 @@ void syscall_handler(registers_t *regs) {
.e = regs->edi};
regs->eax = h(args);
} else {
+ dbg_printf("Unimplemented syscall %d\n", regs->eax);
regs->eax = -1;
}
}
diff --git a/src/kernel/user/vfs.c b/src/kernel/user/vfs.c
index 1c841f7..15f37cc 100644
--- a/src/kernel/user/vfs.c
+++ b/src/kernel/user/vfs.c
@@ -6,6 +6,11 @@
// FILESYSTEM DRIVER REGISTERING //
// ============================= //
+static fs_ops_t no_fs_ops = {
+ .shutdown = 0,
+ .add_source = 0,
+};
+
typedef struct fs_driver {
const char* name;
fs_driver_ops_t *ops;
@@ -37,6 +42,8 @@ fs_t *make_fs(const char* drv_name, fs_handle_t *source, const char* opts) {
if (fs->root == 0) goto fail;
fs->refs = 1;
+ fs->from_fs = 0;
+ fs->ok_modes = FM_ALL_MODES;
fs->root->refs = 1;
fs->root->fs = fs;
fs->root->parent = 0;
@@ -60,6 +67,27 @@ fail:
return 0;
}
+fs_t *fs_subfs(fs_t *fs, const char* root, int ok_modes) {
+ fs_node_t* new_root = fs_walk_path(fs->root, root);
+ if (new_root == 0) return 0;
+
+ fs_t *subfs = (fs_t*)malloc(sizeof(fs_t));
+ if (subfs == 0) return 0;
+
+ subfs->refs = 1;
+ subfs->from_fs = fs;
+ subfs->ok_modes = ok_modes & fs->ok_modes;
+
+ subfs->ops = &no_fs_ops;
+ subfs->data = 0;
+
+ subfs->root = new_root;
+
+ ref_fs(fs);
+
+ return subfs;
+}
+
bool fs_add_source(fs_t *fs, fs_handle_t *source, const char* opts) {
return fs->ops->add_source && fs->ops->add_source(fs->data, source, opts);
}
@@ -72,7 +100,8 @@ void unref_fs(fs_t *fs) {
fs->refs--;
if (fs->refs == 0) {
unref_fs_node(fs->root);
- fs->ops->shutdown(fs->data);
+ if (fs->ops->shutdown) fs->ops->shutdown(fs->data);
+ if (fs->from_fs) unref_fs(fs->from_fs);
free(fs);
}
}
@@ -260,6 +289,8 @@ fs_node_t* fs_walk_path_except_last(fs_node_t* from, const char* path, char* las
// DOING THINGS IN FILESYSTEMS //
bool fs_create(fs_t *fs, const char* file, int type) {
+ if (!(fs->ok_modes & FM_DCREATE)) return false;
+
char name[DIR_MAX];
fs_node_t *n = fs_walk_path_except_last(fs->root, file, name);
if (n == 0) return false;
@@ -273,6 +304,8 @@ bool fs_create(fs_t *fs, const char* file, int type) {
}
bool fs_delete(fs_t *fs, const char* file) {
+ if (!(fs->ok_modes & FM_DDELETE)) return false;
+
char name[DIR_MAX];
fs_node_t* n = fs_walk_path_except_last(fs->root, file, name);
@@ -292,6 +325,8 @@ bool fs_delete(fs_t *fs, const char* file) {
}
bool fs_move(fs_t *fs, const char* from, const char* to) {
+ if (!(fs->ok_modes & FM_DMOVE)) return false;
+
char old_name[DIR_MAX];
fs_node_t *old_parent = fs_walk_path_except_last(fs->root, from, old_name);
if (old_parent == 0) return false;
@@ -369,6 +404,8 @@ bool fs_stat(fs_t *fs, const char* file, stat_t *st) {
// =================== //
fs_handle_t* fs_open(fs_t *fs, const char* file, int mode) {
+ if (mode & ~fs->ok_modes) return 0;
+
fs_node_t *n = fs_walk_path(fs->root, file);
if (n == 0 && (mode & FM_CREATE)) {
if (fs_create(fs, file, FT_REGULAR)) {