Volume-centric VFS implementation
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m41s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m41s
This commit is contained in:
@@ -4,10 +4,11 @@
|
||||
#include <fs/vfs.h>
|
||||
#include <libk/assert.h>
|
||||
#include <libk/fieldlengthof.h>
|
||||
#include <libk/fieldsizeof.h>
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <limine/requests.h>
|
||||
#include <mm/pmm.h>
|
||||
#include <path_defs.h>
|
||||
#include <proc/mail.h>
|
||||
#include <proc/mutex.h>
|
||||
#include <proc/proc.h>
|
||||
@@ -260,9 +261,10 @@ DEFINE_SYSCALL (sys_device_do) {
|
||||
return SYSRESULT (ret);
|
||||
}
|
||||
|
||||
/* int exec (char* path) */
|
||||
/* int exec (char* volume, char* path) */
|
||||
DEFINE_SYSCALL (sys_exec) {
|
||||
uintptr_t uvaddr_path = a1;
|
||||
uintptr_t uvaddr_volume = a1;
|
||||
uintptr_t uvaddr_path = a2;
|
||||
|
||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||
|
||||
@@ -277,13 +279,16 @@ DEFINE_SYSCALL (sys_exec) {
|
||||
|
||||
const char* path = (const char*)((uintptr_t)hhdm->offset + out_paddr);
|
||||
|
||||
char mountpoint[fieldsizeof (struct vfs_mountpoint, key)];
|
||||
const char* subpath = NULL;
|
||||
spin_lock (&proc->procgroup->lock);
|
||||
out_paddr = mm_v2p (&proc->procgroup->pd, uvaddr_volume);
|
||||
spin_unlock (&proc->procgroup->lock);
|
||||
|
||||
if (!path_parse (path, mountpoint, &subpath))
|
||||
return SYSRESULT (-ST_BAD_PATH);
|
||||
if (out_paddr == 0)
|
||||
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
|
||||
|
||||
struct proc* new = proc_from_file (proc->procgroup, mountpoint, subpath);
|
||||
const char* volume = (const char*)((uintptr_t)hhdm->offset + out_paddr);
|
||||
|
||||
struct proc* new = proc_from_file (proc, volume, path, rctx);
|
||||
|
||||
if (new == NULL)
|
||||
return SYSRESULT (-ST_EXEC_ERROR);
|
||||
@@ -296,9 +301,56 @@ DEFINE_SYSCALL (sys_exec) {
|
||||
return SYSRESULT (pid);
|
||||
}
|
||||
|
||||
/* int open (char* path) */
|
||||
DEFINE_SYSCALL (sys_open) {
|
||||
/* int volume_open (char* volume) */
|
||||
DEFINE_SYSCALL (sys_volume_open) {
|
||||
uintptr_t uvaddr_volume = 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_volume);
|
||||
spin_unlock (&proc->procgroup->lock);
|
||||
|
||||
if (out_paddr == 0)
|
||||
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
|
||||
|
||||
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);
|
||||
|
||||
spin_lock (&proc->lock);
|
||||
strncpy (proc->cwv, volume, VOLUME_MAX);
|
||||
spin_unlock (&proc->lock);
|
||||
|
||||
return SYSRESULT (ST_OK);
|
||||
}
|
||||
|
||||
/* int volume_close (void) */
|
||||
DEFINE_SYSCALL (sys_volume_close) {
|
||||
spin_lock (&proc->lock);
|
||||
|
||||
int ret = vfs_volume_close (proc, proc->cwv, rctx);
|
||||
|
||||
if (ret == ST_OK) {
|
||||
memset (proc->cwv, 0, sizeof (proc->cwv));
|
||||
}
|
||||
|
||||
spin_unlock (&proc->lock);
|
||||
|
||||
return SYSRESULT (ret);
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||
|
||||
@@ -313,48 +365,46 @@ DEFINE_SYSCALL (sys_open) {
|
||||
|
||||
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 (int handle) */
|
||||
DEFINE_SYSCALL (sys_close) {
|
||||
int handle = (int)a1;
|
||||
|
||||
return SYSRESULT (vfs_close (proc->procgroup, handle));
|
||||
}
|
||||
|
||||
/* int read (int handle, size_t off, uint8_t* buffer, size_t size) */
|
||||
DEFINE_SYSCALL (sys_read) {
|
||||
int handle = (int)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);
|
||||
|
||||
return SYSRESULT (vfs_read (proc->procgroup, handle, buffer, off, size));
|
||||
spin_lock (&proc->lock);
|
||||
int ret = vfs_read (proc, proc->cwv, path, buffer, off, size, rctx);
|
||||
spin_unlock (&proc->lock);
|
||||
|
||||
return SYSRESULT (ret);
|
||||
}
|
||||
|
||||
/* int describe (int handle, struct desc* desc) */
|
||||
/* int describe (char* path, struct desc* desc) */
|
||||
DEFINE_SYSCALL (sys_describe) {
|
||||
int handle = (int)a1;
|
||||
uintptr_t uvaddr_path = a1;
|
||||
uintptr_t uvaddr_desc = a2;
|
||||
|
||||
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);
|
||||
|
||||
struct desc* desc = sys_get_user_buffer (proc, uvaddr_desc, sizeof (struct desc));
|
||||
|
||||
if (desc == NULL)
|
||||
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
|
||||
|
||||
return SYSRESULT (vfs_describe (proc->procgroup, handle, desc));
|
||||
spin_lock (&proc->lock);
|
||||
int ret = vfs_describe (proc, proc->cwv, path, desc, rctx);
|
||||
spin_unlock (&proc->lock);
|
||||
|
||||
return SYSRESULT (ret);
|
||||
}
|
||||
|
||||
/* int get_procgroup (int pid) */
|
||||
@@ -386,8 +436,8 @@ 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_VOLUME_OPEN] = &sys_volume_open,
|
||||
[SYS_VOLUME_CLOSE] = &sys_volume_close,
|
||||
[SYS_READ] = &sys_read,
|
||||
[SYS_DESCRIBE] = &sys_describe,
|
||||
[SYS_MAIL_SEND] = &sys_mail_send,
|
||||
|
||||
Reference in New Issue
Block a user