Implement VFS syscalls
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m29s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m29s
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <libk/string.h>
|
||||
#include <m/status.h>
|
||||
#include <mm/liballoc.h>
|
||||
#include <proc/procgroup.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/debug.h>
|
||||
|
||||
@@ -75,7 +76,9 @@ struct vfs_mountpoint* vfs_create_mountpoint (const char* key, int fs_type) {
|
||||
return mountpoint;
|
||||
}
|
||||
|
||||
int vfs_describe (const char* mountpoint, const char* path, struct fs_desc_buffer* desc) {
|
||||
int vfs_open (struct procgroup* procgroup, const char* mountpoint, const char* path) {
|
||||
(void)path;
|
||||
|
||||
struct vfs_mountpoint* vmp = vfs_find_mountpoint (mountpoint);
|
||||
|
||||
if (vmp == NULL)
|
||||
@@ -83,6 +86,51 @@ int vfs_describe (const char* mountpoint, const char* path, struct fs_desc_buffe
|
||||
|
||||
spin_lock (&vmp->lock);
|
||||
|
||||
vmp->ownerpg = procgroup;
|
||||
vmp->locked = true;
|
||||
|
||||
spin_unlock (&vmp->lock);
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
int vfs_close (struct procgroup* procgroup, const char* mountpoint, const char* path) {
|
||||
(void)path;
|
||||
|
||||
struct vfs_mountpoint* vmp = vfs_find_mountpoint (mountpoint);
|
||||
|
||||
if (vmp == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
spin_lock (&vmp->lock);
|
||||
|
||||
if (procgroup != NULL && vmp->ownerpg != procgroup) {
|
||||
spin_unlock (&vmp->lock);
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
vmp->locked = false;
|
||||
vmp->ownerpg = NULL;
|
||||
|
||||
spin_unlock (&vmp->lock);
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
int vfs_describe (struct procgroup* procgroup, const char* mountpoint, const char* path,
|
||||
struct fs_desc_buffer* desc) {
|
||||
struct vfs_mountpoint* vmp = vfs_find_mountpoint (mountpoint);
|
||||
|
||||
if (vmp == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
spin_lock (&vmp->lock);
|
||||
|
||||
if ((procgroup != NULL && vmp->ownerpg != procgroup) && vmp->locked) {
|
||||
spin_unlock (&vmp->lock);
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
int ret = vmp->driver_ops.describe (vmp, path, desc);
|
||||
|
||||
spin_unlock (&vmp->lock);
|
||||
@@ -90,7 +138,8 @@ int vfs_describe (const char* mountpoint, const char* path, struct fs_desc_buffe
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vfs_read (const char* mountpoint, const char* path, uint8_t* buffer, size_t off, size_t size) {
|
||||
int vfs_read (struct procgroup* procgroup, const char* mountpoint, const char* path,
|
||||
uint8_t* buffer, size_t off, size_t size) {
|
||||
struct vfs_mountpoint* vmp = vfs_find_mountpoint (mountpoint);
|
||||
|
||||
if (vmp == NULL)
|
||||
@@ -98,6 +147,11 @@ int vfs_read (const char* mountpoint, const char* path, uint8_t* buffer, size_t
|
||||
|
||||
spin_lock (&vmp->lock);
|
||||
|
||||
if ((procgroup != NULL && vmp->ownerpg != procgroup) && vmp->locked) {
|
||||
spin_unlock (&vmp->lock);
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
int ret = vmp->driver_ops.read (vmp, path, buffer, off, size);
|
||||
|
||||
spin_unlock (&vmp->lock);
|
||||
@@ -105,6 +159,26 @@ int vfs_read (const char* mountpoint, const char* path, uint8_t* buffer, size_t
|
||||
return ret;
|
||||
}
|
||||
|
||||
void vfs_procgroup_cleanup (struct procgroup* procgroup) {
|
||||
spin_lock (&mount_table.lock);
|
||||
|
||||
for (size_t i = 0; i < lengthof (mount_table.mountpoint_buckets); i++) {
|
||||
struct hash_node_link* link = mount_table.mountpoint_buckets[i];
|
||||
struct vfs_mountpoint* vmp = hash_entry (link, struct vfs_mountpoint, mount_table_link);
|
||||
|
||||
spin_lock (&vmp->lock);
|
||||
|
||||
if (vmp->ownerpg == procgroup) {
|
||||
vmp->locked = false;
|
||||
vmp->ownerpg = NULL;
|
||||
}
|
||||
|
||||
spin_unlock (&vmp->lock);
|
||||
}
|
||||
|
||||
spin_unlock (&mount_table.lock);
|
||||
}
|
||||
|
||||
void vfs_init (void) {
|
||||
memset (&mount_table, 0, sizeof (mount_table));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user