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

@@ -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;