Implement VFS syscalls
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m29s

This commit is contained in:
2026-02-15 21:34:07 +01:00
parent 0f5bd48328
commit 7726fd2f00
19 changed files with 307 additions and 31 deletions

View File

@@ -248,7 +248,7 @@ DEFINE_SYSCALL (sys_exec) {
if (!path_parse (path, mountpoint, &subpath))
return SYSRESULT (-ST_BAD_PATH);
struct proc* new = proc_from_file (mountpoint, subpath);
struct proc* new = proc_from_file (proc->procgroup, mountpoint, subpath);
if (new == NULL)
return SYSRESULT (-ST_EXEC_ERROR);
@@ -261,6 +261,125 @@ DEFINE_SYSCALL (sys_exec) {
return SYSRESULT (pid);
}
/* int open (char* path) */
DEFINE_SYSCALL (sys_open) {
uintptr_t uvaddr_path = a1;
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
uintptr_t out_paddr;
spin_lock (&proc->procgroup->lock);
out_paddr = mm_v2p (&proc->procgroup->pd, uvaddr_path);
spin_unlock (&proc->procgroup->lock);
if (out_paddr == 0)
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
const char* path = (const char*)((uintptr_t)hhdm->offset + out_paddr);
char mountpoint[fieldsizeof (struct vfs_mountpoint, key)];
const char* subpath = NULL;
if (!path_parse (path, mountpoint, &subpath))
return SYSRESULT (-ST_BAD_PATH);
return SYSRESULT (vfs_open (proc->procgroup, mountpoint, subpath));
}
/* int close (char* path) */
DEFINE_SYSCALL (sys_close) {
uintptr_t uvaddr_path = a1;
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
uintptr_t out_paddr;
spin_lock (&proc->procgroup->lock);
out_paddr = mm_v2p (&proc->procgroup->pd, uvaddr_path);
spin_unlock (&proc->procgroup->lock);
if (out_paddr == 0)
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
const char* path = (const char*)((uintptr_t)hhdm->offset + out_paddr);
char mountpoint[fieldsizeof (struct vfs_mountpoint, key)];
const char* subpath = NULL;
if (!path_parse (path, mountpoint, &subpath))
return SYSRESULT (-ST_BAD_PATH);
return SYSRESULT (vfs_close (proc->procgroup, mountpoint, subpath));
}
/* int read (char* path, size_t off, uint8_t* buffer, size_t size) */
DEFINE_SYSCALL (sys_read) {
uintptr_t uvaddr_path = a1;
size_t off = (size_t)a2;
uintptr_t uvaddr_buffer = a3;
size_t size = (size_t)a4;
uint8_t* buffer = sys_get_user_buffer (proc, uvaddr_buffer, size);
if (buffer == NULL)
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
uintptr_t out_paddr;
spin_lock (&proc->procgroup->lock);
out_paddr = mm_v2p (&proc->procgroup->pd, uvaddr_path);
spin_unlock (&proc->procgroup->lock);
if (out_paddr == 0)
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
const char* path = (const char*)((uintptr_t)hhdm->offset + out_paddr);
char mountpoint[fieldsizeof (struct vfs_mountpoint, key)];
const char* subpath = NULL;
if (!path_parse (path, mountpoint, &subpath))
return SYSRESULT (-ST_BAD_PATH);
return SYSRESULT (vfs_read (proc->procgroup, mountpoint, subpath, buffer, off, size));
}
/* int describe (char* path, struct fs_desc_buffer* desc) */
DEFINE_SYSCALL (sys_describe) {
uintptr_t uvaddr_path = a1;
uintptr_t uvaddr_desc = a2;
struct fs_desc_buffer* desc =
sys_get_user_buffer (proc, uvaddr_desc, sizeof (struct fs_desc_buffer));
if (desc == NULL)
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
uintptr_t out_paddr;
spin_lock (&proc->procgroup->lock);
out_paddr = mm_v2p (&proc->procgroup->pd, uvaddr_path);
spin_unlock (&proc->procgroup->lock);
if (out_paddr == 0)
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
const char* path = (const char*)((uintptr_t)hhdm->offset + out_paddr);
char mountpoint[fieldsizeof (struct vfs_mountpoint, key)];
const char* subpath = NULL;
if (!path_parse (path, mountpoint, &subpath))
return SYSRESULT (-ST_BAD_PATH);
return SYSRESULT (vfs_describe (proc->procgroup, mountpoint, subpath, desc));
}
static syscall_handler_func_t handler_table[] = {
[SYS_QUIT] = &sys_quit,
[SYS_TEST] = &sys_test,
@@ -275,6 +394,10 @@ static syscall_handler_func_t handler_table[] = {
[SYS_MUTEX_UNLOCK] = &sys_mutex_unlock,
[SYS_DEVICE_DO] = &sys_device_do,
[SYS_EXEC] = &sys_exec,
[SYS_OPEN] = &sys_open,
[SYS_CLOSE] = &sys_close,
[SYS_READ] = &sys_read,
[SYS_DESCRIBE] = &sys_describe,
};
syscall_handler_func_t syscall_find_handler (int syscall_num) {