From 21ff32de5401d638930972142df83b02ba0eb493 Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Tue, 28 Apr 2026 00:20:25 +0200 Subject: [PATCH] Remove vfs_volume_open() and vfs_volume_close() --- kernel/amd64/proc.c | 1 - kernel/fs/vfs.c | 81 ---------------------------------------- kernel/fs/vfs.h | 7 ---- kernel/proc/proc.c | 9 ----- kernel/proc/proc.h | 2 +- kernel/syscall/syscall.c | 16 +------- 6 files changed, 3 insertions(+), 113 deletions(-) diff --git a/kernel/amd64/proc.c b/kernel/amd64/proc.c index 677f5fe..7fec6f2 100644 --- a/kernel/amd64/proc.c +++ b/kernel/amd64/proc.c @@ -125,7 +125,6 @@ void proc_cleanup(struct proc* proc, struct reschedule_ctx* rctx) { procgroup_detach(proc->procgroup, proc, rctx); - vfs_volume_close(proc, proc->cwv, rctx); proc_free_pid(proc->pid); /* clean the process */ free(proc); diff --git a/kernel/fs/vfs.c b/kernel/fs/vfs.c index e1ba570..24c90f3 100644 --- a/kernel/fs/vfs.c +++ b/kernel/fs/vfs.c @@ -164,10 +164,6 @@ int vfs_volume_delete(const char* key) { return -ST_NOT_FOUND; } - if (volume->locked) { - return -ST_TRY_AGAIN; - } - hash_delete(&volume_table, key, strlen_null(key), hash, lengthof(volume_table.volume_buckets), volume_buckets, struct vfs_volume, volume_table_link, key, found_link); @@ -178,61 +174,12 @@ int vfs_volume_delete(const char* key) { return ret; } -int vfs_volume_open(struct proc* proc, const char* volume_name, struct reschedule_ctx* rctx) { - struct vfs_volume* volume = vfs_find_volume(volume_name); - - if (volume == NULL) - return -ST_NOT_FOUND; - - if (!volume->locked) { - volume->locked = true; - volume->owner = proc; - return ST_OK; - } else { - proc_sq_suspend(proc, &volume->sq, rctx, NULL, NULL); - return ST_OK; - } -} - -int vfs_volume_close(struct proc* proc, const char* volume_name, struct reschedule_ctx* rctx) { - struct vfs_volume* volume = vfs_find_volume(volume_name); - - if (volume == NULL) - return -ST_NOT_FOUND; - - if (volume->locked && volume->owner != proc) { - return -ST_PERMISSION_ERROR; - } - - struct list_node_link* node = volume->sq.proc_list; - - if (node) { - struct proc_sq_entry* sq_entry = list_entry(node, struct proc_sq_entry, sq_link); - struct proc* resumed_proc = sq_entry->proc; - - volume->owner = resumed_proc; - volume->locked = true; - - proc_sq_resume(resumed_proc, sq_entry, rctx, 0); - return ST_OK; - } - - volume->locked = false; - volume->owner = NULL; - - return ST_OK; -} - int vfs_format(struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name) { struct vfs_volume* volume = vfs_find_volume(volume_name); if (volume == NULL) return -ST_NOT_FOUND; - if (volume->locked && volume->owner != proc) { - return -ST_PERMISSION_ERROR; - } - return volume->driver_ops.format(volume, proc, rctx); } @@ -243,10 +190,6 @@ int vfs_read_file(struct proc* proc, struct reschedule_ctx* rctx, const char* vo if (volume == NULL) return -ST_NOT_FOUND; - if (volume->locked && volume->owner != proc) { - return -ST_PERMISSION_ERROR; - } - return volume->driver_ops.read_file(volume, proc, rctx, path, buffer, off, size); } @@ -257,10 +200,6 @@ int vfs_write_file(struct proc* proc, struct reschedule_ctx* rctx, const char* v if (volume == NULL) return -ST_NOT_FOUND; - if (volume->locked && volume->owner != proc) { - return -ST_PERMISSION_ERROR; - } - return volume->driver_ops.write_file(volume, proc, rctx, path, buffer, off, size, flags); } @@ -271,10 +210,6 @@ int vfs_create_file(struct proc* proc, struct reschedule_ctx* rctx, const char* if (volume == NULL) return -ST_NOT_FOUND; - if (volume->locked && volume->owner != proc) { - return -ST_PERMISSION_ERROR; - } - return volume->driver_ops.create_file(volume, proc, rctx, path); } @@ -285,10 +220,6 @@ int vfs_describe(struct proc* proc, struct reschedule_ctx* rctx, const char* vol if (volume == NULL) return -ST_NOT_FOUND; - if (volume->locked && volume->owner != proc) { - return -ST_PERMISSION_ERROR; - } - return volume->driver_ops.describe(volume, proc, rctx, path, desc); } @@ -299,10 +230,6 @@ int vfs_read_dir_entry(struct proc* proc, struct reschedule_ctx* rctx, const cha if (volume == NULL) return -ST_NOT_FOUND; - if (volume->locked && volume->owner != proc) { - return -ST_PERMISSION_ERROR; - } - return volume->driver_ops.read_dir_entry(volume, proc, rctx, path, entry, entry_num); } @@ -313,10 +240,6 @@ int vfs_create_dir(struct proc* proc, struct reschedule_ctx* rctx, const char* v if (volume == NULL) return -ST_NOT_FOUND; - if (volume->locked && volume->owner != proc) { - return -ST_PERMISSION_ERROR; - } - return volume->driver_ops.create_dir(volume, proc, rctx, path); } @@ -327,10 +250,6 @@ int vfs_remove(struct proc* proc, struct reschedule_ctx* rctx, const char* volum if (volume == NULL) return -ST_NOT_FOUND; - if (volume->locked && volume->owner != proc) { - return -ST_PERMISSION_ERROR; - } - return volume->driver_ops.remove(volume, proc, rctx, path); } diff --git a/kernel/fs/vfs.h b/kernel/fs/vfs.h index e9f4579..1a317f9 100644 --- a/kernel/fs/vfs.h +++ b/kernel/fs/vfs.h @@ -23,9 +23,6 @@ struct vfs_volume { char key[VOLUME_MAX]; struct hash_node_link volume_table_link; int fs_type; - struct proc* owner; - bool locked; - struct proc_suspension_q sq; struct { int (*mount)(struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, bool format); @@ -68,10 +65,6 @@ int vfs_create_volume(struct proc* proc, struct reschedule_ctx* rctx, const char int vfs_volume_delete(const char* key); -int vfs_volume_open(struct proc* proc, const char* volume, struct reschedule_ctx* rctx); - -int vfs_volume_close(struct proc* proc, const char* volume, struct reschedule_ctx* rctx); - int vfs_format(struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name); int vfs_read_file(struct proc* proc, struct reschedule_ctx* rctx, const char* volume, diff --git a/kernel/proc/proc.c b/kernel/proc/proc.c index 0c14b01..d4fdbeb 100644 --- a/kernel/proc/proc.c +++ b/kernel/proc/proc.c @@ -173,34 +173,25 @@ struct proc* proc_from_file(struct proc* proc1, const char* volume, const char* struct desc desc; int ret; - if ((ret = vfs_volume_open(proc1, volume, rctx)) < 0) - return NULL; - if ((ret = vfs_describe(proc1, rctx, volume, path, &desc)) < 0) { - vfs_volume_close(proc1, volume, rctx); return NULL; } if (desc.type != FS_FILE) { - vfs_volume_close(proc1, volume, rctx); return NULL; } uint8_t* temp_buffer = malloc(desc.size); if (temp_buffer == NULL) { - vfs_volume_close(proc1, volume, rctx); return NULL; } if ((ret = vfs_read_file(proc1, rctx, volume, path, temp_buffer, 0, desc.size)) < 0) { free(temp_buffer); - vfs_volume_close(proc1, volume, rctx); return NULL; } - vfs_volume_close(proc1, volume, rctx); - if (!proc_check_elf(temp_buffer)) { free(temp_buffer); return NULL; diff --git a/kernel/proc/proc.h b/kernel/proc/proc.h index 3f56fb2..061e7b9 100644 --- a/kernel/proc/proc.h +++ b/kernel/proc/proc.h @@ -44,9 +44,9 @@ struct proc { struct cpu* cpu; int state; uintptr_t uvaddr_argument; - char cwv[VOLUME_MAX]; struct proc_suspension_q done_sq; char name[PATH_MAX + VOLUME_MAX]; + char cwv[VOLUME_MAX]; }; void proc_sched(bool user); diff --git a/kernel/syscall/syscall.c b/kernel/syscall/syscall.c index 8ac9873..2b0e993 100644 --- a/kernel/syscall/syscall.c +++ b/kernel/syscall/syscall.c @@ -415,11 +415,6 @@ DEFINE_SYSCALL(sys_volume_open) { const char* volume = (const char*)((uintptr_t)hhdm->offset + out_paddr); - int ret = vfs_volume_open(proc, volume, rctx); - - if (ret < 0) - return SYSRESULT(ret); - strncpy(proc->cwv, volume, VOLUME_MAX); return SYSRESULT(ST_OK); @@ -427,16 +422,9 @@ DEFINE_SYSCALL(sys_volume_open) { /* int volume_close (void) */ DEFINE_SYSCALL(sys_volume_close) { - char cwv[VOLUME_MAX]; - memcpy(cwv, proc->cwv, sizeof(proc->cwv)); + memset(proc->cwv, 0, sizeof(proc->cwv)); - int ret = vfs_volume_close(proc, cwv, rctx); - - if (ret == ST_OK) { - memset(proc->cwv, 0, sizeof(proc->cwv)); - } - - return SYSRESULT(ret); + return SYSRESULT(ST_OK); } /* int read_file (char* path, size_t off, uint8_t* buffer, size_t size) */