VFS can now reschedule the calling process
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m48s

This commit is contained in:
2026-03-11 19:07:22 +01:00
parent e765855309
commit 04b7355a3d
10 changed files with 196 additions and 120 deletions

View File

@@ -15,6 +15,7 @@
#include <fs_types.h>
#include <irq/irq.h>
#include <libk/std.h>
#include <libk/string.h>
#include <limine/limine.h>
#include <limine/requests.h>
#include <mm/liballoc.h>
@@ -65,11 +66,14 @@ void bootmain (void) {
devices_init ();
vfs_init ();
struct reschedule_ctx rctx;
memset (&rctx, 0, sizeof (rctx));
struct device* rd0 = device_find ("RD0");
vfs_create_volume ("RD", FS_TARFS, rd0, false);
vfs_create_volume (thiscpu->kproc, &rctx, "RD", FS_TARFS, rd0, false);
struct device* temp0 = device_find ("TEMP0");
vfs_create_volume ("TEMP", FS_FAT16, temp0, true);
vfs_create_volume (thiscpu->kproc, &rctx, "TEMP", FS_FAT16, temp0, true);
smp_init ();

View File

@@ -12,6 +12,8 @@
#include <libk/string.h>
#include <mm/liballoc.h>
#include <path_defs.h>
#include <proc/proc.h>
#include <proc/reschedule.h>
#include <status.h>
#include <sys/debug.h>
#include <write_file.h>
@@ -30,7 +32,7 @@ static int fat1_diskio_read (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* bu
spin_lock (&back_device->lock);
ret = device_op (back_device, XDRV_GET_SECTOR_SIZE, NULL, NULL, &sector_size);
ret = device_op (back_device, XDRV_GET_SECTOR_SIZE, ctx->proc, ctx->rctx, &sector_size);
if (ret < 0) {
spin_unlock (&back_device->lock);
return 0;
@@ -39,7 +41,8 @@ static int fat1_diskio_read (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* bu
vfs_translate (sector, sector_count, FAT_SECTOR_SIZE, sector_size, &phys_sector,
&phys_sector_count);
ret = device_op (back_device, XDRV_READ, NULL, NULL, &phys_sector, &phys_sector_count, buffer);
ret = device_op (back_device, XDRV_READ, ctx->proc, ctx->rctx, &phys_sector, &phys_sector_count,
buffer);
if (ret < 0) {
spin_unlock (&back_device->lock);
return 0;
@@ -66,7 +69,7 @@ static int fat1_diskio_write (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* b
spin_lock (&back_device->lock);
ret = device_op (back_device, XDRV_GET_SECTOR_SIZE, NULL, NULL, &sector_size);
ret = device_op (back_device, XDRV_GET_SECTOR_SIZE, ctx->proc, ctx->rctx, &sector_size);
if (ret < 0) {
spin_unlock (&back_device->lock);
return 0;
@@ -75,7 +78,8 @@ static int fat1_diskio_write (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* b
vfs_translate (sector, sector_count, FAT_SECTOR_SIZE, sector_size, &phys_sector,
&phys_sector_count);
ret = device_op (back_device, XDRV_WRITE, NULL, NULL, &phys_sector, &phys_sector_count, buffer);
ret = device_op (back_device, XDRV_WRITE, ctx->proc, ctx->rctx, &phys_sector, &phys_sector_count,
buffer);
if (ret < 0) {
spin_unlock (&back_device->lock);
return 0;
@@ -88,7 +92,8 @@ static int fat1_diskio_write (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* b
return 1;
}
int fatfs_mount (struct vfs_volume* volume, bool format) {
int fatfs_mount (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
bool format) {
struct fatfs_ctx* fatfs_ctx = malloc (sizeof (*fatfs_ctx));
int r;
@@ -102,9 +107,11 @@ int fatfs_mount (struct vfs_volume* volume, bool format) {
fl_init (fatfs_ctx);
fatfs_ctx->_fs.disk_io.read_media = &fat1_diskio_read;
fatfs_ctx->_fs.disk_io.write_media = &fat1_diskio_write;
fatfs_ctx->proc = proc;
fatfs_ctx->rctx = rctx;
if (format) {
r = volume->driver_ops.format (volume);
r = volume->driver_ops.format (volume, proc, rctx);
if (r < 0)
return -ST_FORMAT_ERROR;
}
@@ -116,13 +123,15 @@ int fatfs_mount (struct vfs_volume* volume, bool format) {
return ST_OK;
}
int fatfs16_format (struct vfs_volume* volume) {
int fatfs16_format (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx) {
struct fatfs_ctx* fatfs_ctx = volume->udata;
struct device* back_device = volume->back_device;
size_t total_size;
fatfs_ctx->proc = proc;
fatfs_ctx->rctx = rctx;
spin_lock (&back_device->lock);
device_op (back_device, XDRV_GET_SIZE, NULL, NULL, &total_size);
device_op (back_device, XDRV_GET_SIZE, proc, rctx, &total_size);
spin_unlock (&back_device->lock);
size_t sectors = div_align_up (total_size, FAT_SECTOR_SIZE);
@@ -130,13 +139,15 @@ int fatfs16_format (struct vfs_volume* volume) {
return r < 0 ? -ST_FORMAT_ERROR : ST_OK;
}
int fatfs32_format (struct vfs_volume* volume) {
int fatfs32_format (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx) {
struct fatfs_ctx* fatfs_ctx = volume->udata;
struct device* back_device = volume->back_device;
size_t total_size;
fatfs_ctx->proc = proc;
fatfs_ctx->rctx = rctx;
spin_lock (&back_device->lock);
device_op (back_device, XDRV_GET_SIZE, NULL, NULL, &total_size);
device_op (back_device, XDRV_GET_SIZE, proc, rctx, &total_size);
spin_unlock (&back_device->lock);
size_t sectors = div_align_up (total_size, FAT_SECTOR_SIZE);
@@ -144,8 +155,11 @@ int fatfs32_format (struct vfs_volume* volume) {
return r < 0 ? -ST_FORMAT_ERROR : ST_OK;
}
int fatfs_describe (struct vfs_volume* volume, const char* path, struct desc* desc) {
int fatfs_describe (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, struct desc* desc) {
struct fatfs_ctx* fatfs_ctx = volume->udata;
fatfs_ctx->proc = proc;
fatfs_ctx->rctx = rctx;
if (fl_is_dir (fatfs_ctx, path)) {
FL_DIR dir;
@@ -176,9 +190,11 @@ int fatfs_describe (struct vfs_volume* volume, const char* path, struct desc* de
return ST_OK;
}
int fatfs_read_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
size_t size) {
int fatfs_read_file (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, uint8_t* buffer, size_t off, size_t size) {
struct fatfs_ctx* fatfs_ctx = volume->udata;
fatfs_ctx->proc = proc;
fatfs_ctx->rctx = rctx;
if (fl_is_dir (fatfs_ctx, path))
return -ST_NOT_FOUND;
@@ -196,9 +212,11 @@ int fatfs_read_file (struct vfs_volume* volume, const char* path, uint8_t* buffe
return ST_OK;
}
int fatfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
size_t size, uint32_t flags) {
int fatfs_write_file (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, uint8_t* buffer, size_t off, size_t size, uint32_t flags) {
struct fatfs_ctx* fatfs_ctx = volume->udata;
fatfs_ctx->proc = proc;
fatfs_ctx->rctx = rctx;
if (fl_is_dir (fatfs_ctx, path))
return -ST_NOT_FOUND;
@@ -221,10 +239,12 @@ int fatfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buff
return ST_OK;
}
int fatfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct dir_entry* entry,
size_t entry_num) {
int fatfs_read_dir_entry (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, struct dir_entry* entry, size_t entry_num) {
struct fatfs_ctx* fatfs_ctx = volume->udata;
FL_DIR dir;
fatfs_ctx->proc = proc;
fatfs_ctx->rctx = rctx;
if (!fl_is_dir (fatfs_ctx, path))
return -ST_NOT_FOUND;
@@ -248,8 +268,11 @@ int fatfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct di
return ST_OK;
}
int fatfs_create_file (struct vfs_volume* volume, const char* path) {
int fatfs_create_file (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path) {
struct fatfs_ctx* fatfs_ctx = volume->udata;
fatfs_ctx->proc = proc;
fatfs_ctx->rctx = rctx;
FL_FILE* file = fl_fopen (fatfs_ctx, path, "wb+");
@@ -260,15 +283,21 @@ int fatfs_create_file (struct vfs_volume* volume, const char* path) {
return ST_OK;
}
int fatfs_create_dir (struct vfs_volume* volume, const char* path) {
int fatfs_create_dir (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path) {
struct fatfs_ctx* fatfs_ctx = volume->udata;
fatfs_ctx->proc = proc;
fatfs_ctx->rctx = rctx;
int r = fl_createdirectory (fatfs_ctx, path);
return r == 0 ? ST_OK : -ST_CREATE_DIR_ERROR;
}
int fatfs_remove (struct vfs_volume* volume, const char* path) {
int fatfs_remove (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path) {
struct fatfs_ctx* fatfs_ctx = volume->udata;
fatfs_ctx->proc = proc;
fatfs_ctx->rctx = rctx;
int r = fl_remove (fatfs_ctx, path);
return r == 0 ? ST_OK : -ST_REMOVE_ERROR;

View File

@@ -10,27 +10,32 @@
struct vfs_volume;
int fatfs_mount (struct vfs_volume* volume, bool format);
int fatfs_mount (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
bool format);
int fatfs16_format (struct vfs_volume* volume);
int fatfs16_format (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx);
int fatfs32_format (struct vfs_volume* volume);
int fatfs32_format (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx);
int fatfs_describe (struct vfs_volume* volume, const char* path, struct desc* desc);
int fatfs_describe (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, struct desc* desc);
int fatfs_read_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
size_t size);
int fatfs_read_file (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, uint8_t* buffer, size_t off, size_t size);
int fatfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
size_t size, uint32_t flags);
int fatfs_write_file (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, uint8_t* buffer, size_t off, size_t size, uint32_t flags);
int fatfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct dir_entry* entry,
size_t entry_num);
int fatfs_read_dir_entry (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, struct dir_entry* entry, size_t entry_num);
int fatfs_create_file (struct vfs_volume* volume, const char* path);
int fatfs_create_file (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path);
int fatfs_create_dir (struct vfs_volume* volume, const char* path);
int fatfs_create_dir (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path);
int fatfs_remove (struct vfs_volume* volume, const char* path);
int fatfs_remove (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path);
#endif // _KERNEL_FS_FATFS_H

View File

@@ -1,6 +1,9 @@
#ifndef _KERNEL_FS_FATFS_CTX_H
#define _KERNEL_FS_FATFS_CTX_H
struct proc;
struct reschedule_ctx;
struct fatfs_ctx {
FL_FILE _files[FATFS_MAX_OPEN_FILES];
int _filelib_init;
@@ -9,6 +12,8 @@ struct fatfs_ctx {
struct fat_list _open_file_list;
struct fat_list _free_file_list;
void* udata;
struct proc* proc;
struct reschedule_ctx* rctx;
};
#endif // _KERNEL_FS_FATFS_CTX_H

View File

@@ -11,6 +11,8 @@
#include <limine/requests.h>
#include <mm/liballoc.h>
#include <path_defs.h>
#include <proc/proc.h>
#include <proc/reschedule.h>
#include <status.h>
#include <sys/debug.h>
@@ -63,7 +65,8 @@ static size_t tar_parse (struct tarfs* tarfs, uint8_t* addr, size_t max_size) {
return i;
}
int tarfs_mount (struct vfs_volume* volume, bool format) {
int tarfs_mount (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
bool format) {
(void)format;
struct tarfs* tarfs = malloc (sizeof (*tarfs));
@@ -107,7 +110,7 @@ int tarfs_mount (struct vfs_volume* volume, bool format) {
size_t sector_count = 1;
for (size_t sector = 0; sector < total_size / sector_size; sector++) {
uint8_t* dest = (uint8_t*)((uintptr_t)buffer + (sector * sector_size));
ret = device_op (back_device, XDRV_READ, NULL, NULL, &sector, &sector_count, dest);
ret = device_op (back_device, XDRV_READ, proc, rctx, &sector, &sector_count, dest);
}
spin_unlock (&back_device->lock);
@@ -126,12 +129,15 @@ int tarfs_mount (struct vfs_volume* volume, bool format) {
return ret;
}
int tarfs_format (struct vfs_volume* volume) {
(void)volume;
int tarfs_format (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx) {
(void)volume, (void)proc, (void)rctx;
return ST_OK;
}
int tarfs_describe (struct vfs_volume* volume, const char* path, struct desc* desc) {
int tarfs_describe (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, struct desc* desc) {
(void)proc, (void)rctx;
struct tarfs* tarfs = volume->udata;
if ((path[0] == '/') && (path[1] == '\0')) {
@@ -163,9 +169,9 @@ int tarfs_describe (struct vfs_volume* volume, const char* path, struct desc* de
}
}
int tarfs_read_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
size_t size) {
(void)volume;
int tarfs_read_file (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, uint8_t* buffer, size_t off, size_t size) {
(void)volume, (void)proc, (void)rctx;
const char* filename = path_basename (path);
@@ -185,8 +191,10 @@ int tarfs_read_file (struct vfs_volume* volume, const char* path, uint8_t* buffe
return ST_OK;
}
int tarfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct dir_entry* entry,
size_t entry_num) {
int tarfs_read_dir_entry (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, struct dir_entry* entry, size_t entry_num) {
(void)proc, (void)rctx;
struct tarfs* tarfs = volume->udata;
if (strncmp (path, "/", PATH_MAX) != 0) {
@@ -214,23 +222,27 @@ int tarfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct di
return -ST_DIR_NO_ENTRIES;
}
int tarfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
size_t size, uint32_t flags) {
(void)volume, (void)path, (void)buffer, (void)off, (void)size, (void)flags;
int tarfs_write_file (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, uint8_t* buffer, size_t off, size_t size, uint32_t flags) {
(void)volume, (void)path, (void)buffer, (void)off;
(void)size, (void)flags, (void)proc, (void)rctx;
return ST_OK;
}
int tarfs_create_file (struct vfs_volume* volume, const char* path) {
(void)volume, (void)path;
int tarfs_create_file (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path) {
(void)volume, (void)path, (void)proc, (void)rctx;
return ST_OK;
}
int tarfs_create_dir (struct vfs_volume* volume, const char* path) {
(void)volume, (void)path;
int tarfs_create_dir (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path) {
(void)volume, (void)path, (void)proc, (void)rctx;
return ST_OK;
}
int tarfs_remove (struct vfs_volume* volume, const char* path) {
(void)volume, (void)path;
int tarfs_remove (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path) {
(void)volume, (void)path, (void)proc, (void)rctx;
return ST_OK;
}

View File

@@ -34,25 +34,30 @@ struct tarfs {
struct vfs_volume;
int tarfs_mount (struct vfs_volume* volume, bool format);
int tarfs_mount (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
bool format);
int tarfs_format (struct vfs_volume* volume);
int tarfs_format (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx);
int tarfs_describe (struct vfs_volume* volume, const char* path, struct desc* desc);
int tarfs_describe (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, struct desc* desc);
int tarfs_read_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
size_t size);
int tarfs_read_file (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, uint8_t* buffer, size_t off, size_t size);
int tarfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
size_t size, uint32_t flags);
int tarfs_write_file (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, uint8_t* buffer, size_t off, size_t size, uint32_t flags);
int tarfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct dir_entry* entry,
size_t entry_num);
int tarfs_read_dir_entry (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, struct dir_entry* entry, size_t entry_num);
int tarfs_create_file (struct vfs_volume* volume, const char* path);
int tarfs_create_file (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path);
int tarfs_create_dir (struct vfs_volume* volume, const char* path);
int tarfs_create_dir (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path);
int tarfs_remove (struct vfs_volume* volume, const char* path);
int tarfs_remove (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path);
#endif // _KERNEL_FS_TARFS_H

View File

@@ -37,7 +37,8 @@ static struct vfs_volume* vfs_find_volume (const char* volume) {
return hash_entry (found_link, struct vfs_volume, volume_table_link);
}
int vfs_create_volume (const char* key, int fs_type, struct device* back_device, bool format) {
int vfs_create_volume (struct proc* proc, struct reschedule_ctx* rctx, const char* key, int fs_type,
struct device* back_device, bool format) {
if (strlen_null (key) > VOLUME_MAX)
return -ST_OOB_ERROR;
@@ -92,7 +93,7 @@ int vfs_create_volume (const char* key, int fs_type, struct device* back_device,
return -ST_MOUNT_ERROR;
}
int ret = volume->driver_ops.mount (volume, format);
int ret = volume->driver_ops.mount (volume, proc, rctx, format);
if (ret < 0) {
free (volume);
@@ -170,7 +171,7 @@ int vfs_volume_close (struct proc* proc, const char* volume_name, struct resched
return ST_OK;
}
int vfs_format (struct proc* proc, const char* volume_name) {
int vfs_format (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name) {
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
@@ -185,11 +186,11 @@ int vfs_format (struct proc* proc, const char* volume_name) {
spin_unlock (&volume->lock);
return volume->driver_ops.format (volume);
return volume->driver_ops.format (volume, proc, rctx);
}
int vfs_read_file (struct proc* proc, const char* volume_name, const char* path, uint8_t* buffer,
size_t off, size_t size) {
int vfs_read_file (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path, uint8_t* buffer, size_t off, size_t size) {
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
@@ -204,11 +205,11 @@ int vfs_read_file (struct proc* proc, const char* volume_name, const char* path,
spin_unlock (&volume->lock);
return volume->driver_ops.read_file (volume, path, buffer, off, size);
return volume->driver_ops.read_file (volume, proc, rctx, path, buffer, off, size);
}
int vfs_write_file (struct proc* proc, const char* volume_name, const char* path, uint8_t* buffer,
size_t off, size_t size, uint32_t flags) {
int vfs_write_file (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path, uint8_t* buffer, size_t off, size_t size, uint32_t flags) {
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
@@ -223,10 +224,11 @@ int vfs_write_file (struct proc* proc, const char* volume_name, const char* path
spin_unlock (&volume->lock);
return volume->driver_ops.write_file (volume, path, buffer, off, size, flags);
return volume->driver_ops.write_file (volume, proc, rctx, path, buffer, off, size, flags);
}
int vfs_create_file (struct proc* proc, const char* volume_name, const char* path) {
int vfs_create_file (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path) {
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
@@ -241,10 +243,11 @@ int vfs_create_file (struct proc* proc, const char* volume_name, const char* pat
spin_unlock (&volume->lock);
return volume->driver_ops.create_file (volume, path);
return volume->driver_ops.create_file (volume, proc, rctx, path);
}
int vfs_describe (struct proc* proc, const char* volume_name, const char* path, struct desc* desc) {
int vfs_describe (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path, struct desc* desc) {
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
@@ -259,11 +262,11 @@ int vfs_describe (struct proc* proc, const char* volume_name, const char* path,
spin_unlock (&volume->lock);
return volume->driver_ops.describe (volume, path, desc);
return volume->driver_ops.describe (volume, proc, rctx, path, desc);
}
int vfs_read_dir_entry (struct proc* proc, const char* volume_name, const char* path,
struct dir_entry* entry, size_t entry_num) {
int vfs_read_dir_entry (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path, struct dir_entry* entry, size_t entry_num) {
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
@@ -278,10 +281,11 @@ int vfs_read_dir_entry (struct proc* proc, const char* volume_name, const char*
spin_unlock (&volume->lock);
return volume->driver_ops.read_dir_entry (volume, path, entry, entry_num);
return volume->driver_ops.read_dir_entry (volume, proc, rctx, path, entry, entry_num);
}
int vfs_create_dir (struct proc* proc, const char* volume_name, const char* path) {
int vfs_create_dir (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path) {
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
@@ -296,10 +300,11 @@ int vfs_create_dir (struct proc* proc, const char* volume_name, const char* path
spin_unlock (&volume->lock);
return volume->driver_ops.create_dir (volume, path);
return volume->driver_ops.create_dir (volume, proc, rctx, path);
}
int vfs_remove (struct proc* proc, const char* volume_name, const char* path) {
int vfs_remove (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path) {
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
@@ -314,7 +319,7 @@ int vfs_remove (struct proc* proc, const char* volume_name, const char* path) {
spin_unlock (&volume->lock);
return volume->driver_ops.remove (volume, path);
return volume->driver_ops.remove (volume, proc, rctx, path);
}
void vfs_init (void) {

View File

@@ -27,26 +27,32 @@ struct vfs_volume {
bool locked;
struct proc_suspension_q sq;
struct {
int (*mount) (struct vfs_volume* volume, bool format);
int (*mount) (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
bool format);
int (*format) (struct vfs_volume* volume);
int (*format) (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx);
int (*describe) (struct vfs_volume* volume, const char* path, struct desc* desc);
int (*describe) (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, struct desc* desc);
int (*read_file) (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
size_t size);
int (*read_file) (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, uint8_t* buffer, size_t off, size_t size);
int (*write_file) (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
size_t size, uint32_t flags);
int (*write_file) (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path, uint8_t* buffer, size_t off, size_t size, uint32_t flags);
int (*read_dir_entry) (struct vfs_volume* volume, const char* path, struct dir_entry* entry,
int (*read_dir_entry) (struct vfs_volume* volume, struct proc* proc,
struct reschedule_ctx* rctx, const char* path, struct dir_entry* entry,
size_t entry_num);
int (*create_file) (struct vfs_volume* volume, const char* path);
int (*create_file) (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path);
int (*create_dir) (struct vfs_volume* volume, const char* path);
int (*create_dir) (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path);
int (*remove) (struct vfs_volume* volume, const char* path);
int (*remove) (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
const char* path);
} driver_ops;
struct device* back_device;
void* udata
@@ -57,30 +63,35 @@ struct vfs_volume_table {
spin_lock_t lock;
};
int vfs_create_volume (const char* key, int fs_type, struct device* back_device, bool format);
int vfs_create_volume (struct proc* proc, struct reschedule_ctx* rctx, const char* key, int fs_type,
struct device* back_device, bool format);
int vfs_volume_open (struct proc* proc, const char* volume, struct reschedule_ctx* rctx);
int vfs_volume_close (struct proc* proc, const char* volume, struct reschedule_ctx* rctx);
int vfs_format (struct proc* proc, const char* volume_name);
int vfs_format (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name);
int vfs_read_file (struct proc* proc, const char* volume, const char* path, uint8_t* buffer,
size_t off, size_t size);
int vfs_read_file (struct proc* proc, struct reschedule_ctx* rctx, const char* volume,
const char* path, uint8_t* buffer, size_t off, size_t size);
int vfs_write_file (struct proc* proc, const char* volume, const char* path, uint8_t* buffer,
size_t off, size_t size, uint32_t flags);
int vfs_write_file (struct proc* proc, struct reschedule_ctx* rctx, const char* volume,
const char* path, uint8_t* buffer, size_t off, size_t size, uint32_t flags);
int vfs_describe (struct proc* proc, const char* volume, const char* path, struct desc* desc);
int vfs_describe (struct proc* proc, struct reschedule_ctx* rctx, const char* volume,
const char* path, struct desc* desc);
int vfs_read_dir_entry (struct proc* proc, const char* volume, const char* path,
struct dir_entry* entry, size_t entry_num);
int vfs_read_dir_entry (struct proc* proc, struct reschedule_ctx* rctx, const char* volume,
const char* path, struct dir_entry* entry, size_t entry_num);
int vfs_create_file (struct proc* proc, const char* volume_name, const char* path);
int vfs_create_file (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path);
int vfs_create_dir (struct proc* proc, const char* volume_name, const char* path);
int vfs_create_dir (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path);
int vfs_remove (struct proc* proc, const char* volume_name, const char* path);
int vfs_remove (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path);
void vfs_init (void);

View File

@@ -168,7 +168,7 @@ struct proc* proc_from_file (struct proc* proc1, const char* volume, const char*
}
}
if ((ret = vfs_describe (proc1, volume, path, &desc)) < 0) {
if ((ret = vfs_describe (proc1, rctx, volume, path, &desc)) < 0) {
vfs_volume_close (proc1, volume, rctx);
return NULL;
}
@@ -185,7 +185,7 @@ struct proc* proc_from_file (struct proc* proc1, const char* volume, const char*
return NULL;
}
if ((ret = vfs_read_file (proc1, volume, path, temp_buffer, 0, desc.size)) < 0) {
if ((ret = vfs_read_file (proc1, rctx, volume, path, temp_buffer, 0, desc.size)) < 0) {
free (temp_buffer);
vfs_volume_close (proc1, volume, rctx);
return NULL;

View File

@@ -395,7 +395,7 @@ DEFINE_SYSCALL (sys_read_file) {
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
spin_lock (&proc->lock);
int ret = vfs_read_file (proc, proc->cwv, path, buffer, off, size);
int ret = vfs_read_file (proc, rctx, proc->cwv, path, buffer, off, size);
spin_unlock (&proc->lock);
return SYSRESULT (ret);
@@ -425,7 +425,7 @@ DEFINE_SYSCALL (sys_describe) {
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
spin_lock (&proc->lock);
int ret = vfs_describe (proc, proc->cwv, path, desc);
int ret = vfs_describe (proc, rctx, proc->cwv, path, desc);
spin_unlock (&proc->lock);
return SYSRESULT (ret);
@@ -479,7 +479,7 @@ DEFINE_SYSCALL (sys_read_dir_entry) {
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
spin_lock (&proc->lock);
int ret = vfs_read_dir_entry (proc, proc->cwv, path, entry, entry_num);
int ret = vfs_read_dir_entry (proc, rctx, proc->cwv, path, entry, entry_num);
spin_unlock (&proc->lock);
return SYSRESULT (ret);
@@ -503,7 +503,7 @@ DEFINE_SYSCALL (sys_create_file) {
const char* path = (const char*)((uintptr_t)hhdm->offset + out_paddr);
spin_lock (&proc->lock);
int ret = vfs_create_file (proc, proc->cwv, path);
int ret = vfs_create_file (proc, rctx, proc->cwv, path);
spin_unlock (&proc->lock);
return SYSRESULT (ret);
@@ -536,7 +536,7 @@ DEFINE_SYSCALL (sys_write_file) {
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
spin_lock (&proc->lock);
int ret = vfs_write_file (proc, proc->cwv, path, buffer, off, size, flags);
int ret = vfs_write_file (proc, rctx, proc->cwv, path, buffer, off, size, flags);
spin_unlock (&proc->lock);
return SYSRESULT (ret);
@@ -616,7 +616,7 @@ DEFINE_SYSCALL (sys_create_dir) {
const char* path = (const char*)((uintptr_t)hhdm->offset + out_paddr);
spin_lock (&proc->lock);
int ret = vfs_create_dir (proc, proc->cwv, path);
int ret = vfs_create_dir (proc, rctx, proc->cwv, path);
spin_unlock (&proc->lock);
return SYSRESULT (ret);
@@ -640,7 +640,7 @@ DEFINE_SYSCALL (sys_remove) {
const char* path = (const char*)((uintptr_t)hhdm->offset + out_paddr);
spin_lock (&proc->lock);
int ret = vfs_remove (proc, proc->cwv, path);
int ret = vfs_remove (proc, rctx, proc->cwv, path);
spin_unlock (&proc->lock);
return SYSRESULT (ret);
@@ -683,7 +683,7 @@ DEFINE_SYSCALL (sys_create_volume) {
if (device == NULL)
return SYSRESULT (-ST_NOT_FOUND);
return SYSRESULT (vfs_create_volume (key, type, device, false));
return SYSRESULT (vfs_create_volume (proc, rctx, key, type, device, false));
}
static syscall_handler_func_t handler_table[] = {