Redesign VFS around handles

This commit is contained in:
2026-02-22 13:57:41 +01:00
parent b571e2dbd3
commit 85872b856b
10 changed files with 210 additions and 196 deletions

View File

@@ -324,35 +324,16 @@ DEFINE_SYSCALL (sys_open) {
return SYSRESULT (vfs_open (proc->procgroup, mountpoint, subpath));
}
/* int close (char* path) */
/* int close (int handle) */
DEFINE_SYSCALL (sys_close) {
uintptr_t uvaddr_path = a1;
int handle = (int)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));
return SYSRESULT (vfs_close (proc->procgroup, handle));
}
/* int read (char* path, size_t off, uint8_t* buffer, size_t size) */
/* int read (int handle, size_t off, uint8_t* buffer, size_t size) */
DEFINE_SYSCALL (sys_read) {
uintptr_t uvaddr_path = a1;
int handle = (int)a1;
size_t off = (size_t)a2;
uintptr_t uvaddr_buffer = a3;
size_t size = (size_t)a4;
@@ -362,31 +343,12 @@ DEFINE_SYSCALL (sys_read) {
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));
return SYSRESULT (vfs_read (proc->procgroup, handle, buffer, off, size));
}
/* int describe (char* path, struct desc* desc) */
/* int describe (int handle, struct desc* desc) */
DEFINE_SYSCALL (sys_describe) {
uintptr_t uvaddr_path = a1;
int handle = (int)a1;
uintptr_t uvaddr_desc = a2;
struct desc* desc = sys_get_user_buffer (proc, uvaddr_desc, sizeof (struct desc));
@@ -394,26 +356,7 @@ DEFINE_SYSCALL (sys_describe) {
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));
return SYSRESULT (vfs_describe (proc->procgroup, handle, desc));
}
/* int get_procgroup (int pid) */