Implement an ATA driver, Add vfsmount/vfsunmount syscalls
This commit is contained in:
@ -10,6 +10,7 @@
|
||||
#include "sched.h"
|
||||
#include "devctl.h"
|
||||
#include "randcrypto.h"
|
||||
#include "vfs.h"
|
||||
|
||||
int32_t SYSCALL1(sys_debugprint, string) {
|
||||
char *p = (char *)string;
|
||||
@ -27,4 +28,6 @@ SyscallFn SYSCALL_TABLE[SYSCALLS_MAX] = {
|
||||
[SYS_SCHEDRELEASE] = &sys_schedrelease,
|
||||
[SYS_DEVCTL] = &sys_devctl,
|
||||
[SYS_RAND] = &sys_rand,
|
||||
[SYS_VFSMOUNT] = &sys_vfsmount,
|
||||
[SYS_VFSUNMOUNT] = &sys_vfsunmount,
|
||||
};
|
||||
|
||||
63
kernel/syscall/vfs.c
Normal file
63
kernel/syscall/vfs.c
Normal file
@ -0,0 +1,63 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include "hal/hal.h"
|
||||
#include "syscall.h"
|
||||
#include "vfs.h"
|
||||
#include "errors.h"
|
||||
#include "sysdefs/devctl.h"
|
||||
#include "vfs/vfs.h"
|
||||
#include "spinlock/spinlock.h"
|
||||
#include "dev/dev.h"
|
||||
#include "proc/proc.h"
|
||||
#include "storedev/storedev.h"
|
||||
|
||||
int32_t SYSCALL4(sys_vfsmount, mountpoint1, fstypestr1, devid1, format1) {
|
||||
int32_t ret = E_OK;
|
||||
char *mountpoint = (char *)mountpoint1;
|
||||
char *fstypestr = (char *)fstypestr1;
|
||||
Dev_t *dev = (Dev_t *)devid1;
|
||||
bool format = (bool)format1;
|
||||
|
||||
if (mountpoint == NULL) { ret = E_INVALIDARGUMENT; goto done; }
|
||||
if (fstypestr == NULL) { ret = E_INVALIDARGUMENT; goto done; }
|
||||
if (dev == NULL) { ret = E_INVALIDARGUMENT; goto done; }
|
||||
|
||||
if (*dev >= PROC_DEVHANDLES_MAX) { ret = E_INVALIDARGUMENT; goto done; }
|
||||
|
||||
int32_t fstype;
|
||||
|
||||
if (hal_strcmp(fstypestr, "LittleFS") == 0) {
|
||||
fstype = VFS_LITTLEFS;
|
||||
} else {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
|
||||
spinlock_acquire(&PROCS.spinlock);
|
||||
Proc *proc = PROCS.current;
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
|
||||
Dev *dp = proc->devs[*dev];
|
||||
if (dp == NULL) { ret = E_NOENTRY; goto done; }
|
||||
|
||||
StoreDev *sd = (StoreDev *)dp->extra;
|
||||
if (sd != NULL && sd->_magic != STOREDEV_MAGIC) { ret = E_NOENTRY; goto done; }
|
||||
|
||||
ret = vfs_mount(mountpoint, fstype, sd, format);
|
||||
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t SYSCALL1(sys_vfsunmount, mountpoint1) {
|
||||
int32_t ret = E_OK;
|
||||
char *mountpoint = (char *)mountpoint1;
|
||||
|
||||
if (mountpoint == NULL) { ret = E_INVALIDARGUMENT; goto done; }
|
||||
|
||||
ret = vfs_unmount(mountpoint);
|
||||
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
11
kernel/syscall/vfs.h
Normal file
11
kernel/syscall/vfs.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef SYSCALL_VFS_H_
|
||||
#define SYSCALL_VFS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "syscall.h"
|
||||
|
||||
int32_t SYSCALL4(sys_vfsmount, mountpoint1, fstypestr1, devid1, format1);
|
||||
int32_t SYSCALL1(sys_vfsunmount, mountpoint1);
|
||||
|
||||
#endif // SYSCALL_VFS_H_
|
||||
Reference in New Issue
Block a user