New syscalls vfsavailmounts() and vfsmountstat() to get info about current VFS mountpoints

This commit is contained in:
2025-11-04 00:24:58 +01:00
parent 9612e7961e
commit 88ac5cf877
5 changed files with 79 additions and 0 deletions

View File

@ -32,6 +32,8 @@ SyscallFn SYSCALL_TABLE[SYSCALLS_MAX] = {
[SYS_VFSMOUNT] = &sys_vfsmount,
[SYS_VFSUNMOUNT] = &sys_vfsunmount,
[SYS_VFSAVAILMOUNTS] = &sys_vfsavailmounts,
[SYS_VFSMOUNTSTAT] = &sys_vfsmountstat,
[SYS_IPC_PIPEREAD] = &sys_ipc_piperead,
[SYS_IPC_PIPEWRITE] = &sys_ipc_pipewrite,

View File

@ -6,12 +6,14 @@
#include "vfs.h"
#include "errors.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 "hshtb.h"
int32_t SYSCALL4(sys_vfsmount, mountpoint1, fstypestr1, devid1, format1) {
int32_t ret = E_OK;
@ -63,3 +65,59 @@ int32_t SYSCALL1(sys_vfsunmount, mountpoint1) {
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) {
hal_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;
}
hal_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) {
hal_memcpy(statbuf->devname, dev->ident, sizeof(statbuf->devname));
break;
}
}
spinlock_release(&DEVTABLE.spinlock);
return E_OK;
}

View File

@ -7,5 +7,7 @@
int32_t SYSCALL4(sys_vfsmount, mountpoint1, fstypestr1, devid1, format1);
int32_t SYSCALL1(sys_vfsunmount, mountpoint1);
int32_t SYSCALL1(sys_vfsavailmounts, availmounts1);
int32_t SYSCALL2(sys_vfsmountstat, statbuf1, label1);
#endif // SYSCALL_VFS_H_