124 lines
3.2 KiB
C
124 lines
3.2 KiB
C
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
#include "syscall/syscall.h"
|
|
#include "syscall/vfs.h"
|
|
#include "sysdefs/dev.h"
|
|
#include "sysdefs/vfs.h"
|
|
#include "vfs/vfs.h"
|
|
#include "spinlock/spinlock.h"
|
|
#include "dev/dev.h"
|
|
#include "proc/proc.h"
|
|
#include "storedev/storedev.h"
|
|
#include "util/util.h"
|
|
#include "std/string.h"
|
|
#include "hshtb.h"
|
|
#include "errors.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 (strcmp(fstypestr, "LittleFS") == 0) {
|
|
fstype = VFS_LITTLEFS;
|
|
} else {
|
|
ret = E_INVALIDARGUMENT;
|
|
goto done;
|
|
}
|
|
|
|
spinlock_acquire(&PROCS.spinlock);
|
|
Proc *proc = NULL;
|
|
LL_FINDPROP(PROCS.procs, proc, pid, _caller_pid);
|
|
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;
|
|
}
|
|
|
|
int32_t SYSCALL1(sys_vfsavailmounts, availmounts1) {
|
|
VfsAvailMounts *availmounts = (VfsAvailMounts *)availmounts1;
|
|
if (availmounts == NULL) {
|
|
return E_INVALIDARGUMENT;
|
|
}
|
|
|
|
spinlock_acquire(&VFS_TABLE.spinlock);
|
|
for (size_t i = 0; i < VFS_MOUNTPOINTS_MAX; i++) {
|
|
VfsMountPoint *vmp = &VFS_TABLE.mountpoints[i];
|
|
if (vmp->_hshtbstate == HSHTB_TAKEN) {
|
|
memcpy(availmounts->labels[i], vmp->label, VFS_MOUNTPOINT_LABEL_MAX);
|
|
availmounts->fieldavail[i] = 1;
|
|
}
|
|
}
|
|
spinlock_release(&VFS_TABLE.spinlock);
|
|
|
|
return E_OK;
|
|
}
|
|
|
|
int32_t SYSCALL2(sys_vfsmountstat, statbuf1, label1) {
|
|
VfsMountStat *statbuf = (VfsMountStat *)statbuf1;
|
|
if (statbuf == NULL) {
|
|
return E_INVALIDARGUMENT;
|
|
}
|
|
|
|
char *label = (char *)label1;
|
|
if (label == NULL) {
|
|
return E_INVALIDARGUMENT;
|
|
}
|
|
|
|
VfsMountPoint *vmp = NULL;
|
|
spinlock_acquire(&VFS_TABLE.spinlock);
|
|
HSHTB_GET(VFS_TABLE.mountpoints, label, label, vmp);
|
|
spinlock_release(&VFS_TABLE.spinlock);
|
|
|
|
if (vmp == NULL) {
|
|
return E_NOENTRY;
|
|
}
|
|
|
|
memcpy(statbuf->label, vmp->label, sizeof(statbuf->label));
|
|
statbuf->fstype = vmp->fstype;
|
|
|
|
StoreDev *vmpsd = vmp->backingsd;
|
|
spinlock_acquire(&DEVTABLE.spinlock);
|
|
for (size_t i = 0; i < LEN(DEVTABLE.devs); i++) {
|
|
Dev *dev = &DEVTABLE.devs[i];
|
|
if (dev->extra != NULL && ((StoreDev *)dev->extra)->_magic == STOREDEV_MAGIC && vmpsd == dev->extra) {
|
|
memcpy(statbuf->devname, dev->ident, sizeof(statbuf->devname));
|
|
break;
|
|
}
|
|
}
|
|
spinlock_release(&DEVTABLE.spinlock);
|
|
|
|
return E_OK;
|
|
}
|