From d7bfc5c8fdcf888f234e1220351c30e94a2fe579 Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Sun, 15 Mar 2026 14:50:13 +0100 Subject: [PATCH] Wrap filesystem op in macros --- kernel/fs/def_vfs_op.h | 45 ++++++++++++++++++++++++++++++++++++++ kernel/fs/fatfs.c | 28 +++++++++--------------- kernel/fs/fatfs.h | 29 ++++++++++--------------- kernel/fs/tarfs.c | 49 ++++++++---------------------------------- kernel/fs/tarfs.h | 27 +++++++++-------------- 5 files changed, 85 insertions(+), 93 deletions(-) create mode 100644 kernel/fs/def_vfs_op.h diff --git a/kernel/fs/def_vfs_op.h b/kernel/fs/def_vfs_op.h new file mode 100644 index 0000000..35007a9 --- /dev/null +++ b/kernel/fs/def_vfs_op.h @@ -0,0 +1,45 @@ +#ifndef _KERNEL_FS_DEF_VFS_OP_H +#define _KERNEL_FS_DEF_VFS_OP_H + +#include + +#define DEFINE_VFS_MOUNT(name) \ + int name (struct vfs_volume* UNUSED volume, struct proc* UNUSED proc, \ + struct reschedule_ctx* UNUSED rctx, bool UNUSED format) + +#define DEFINE_VFS_FORMAT(name) \ + int name (struct vfs_volume* UNUSED volume, struct proc* UNUSED proc, \ + struct reschedule_ctx* UNUSED rctx) + +#define DEFINE_VFS_DESCRIBE(name) \ + int name (struct vfs_volume* UNUSED volume, struct proc* UNUSED proc, \ + struct reschedule_ctx* UNUSED rctx, const char* UNUSED path, struct desc* UNUSED desc) + +#define DEFINE_VFS_READ_FILE(name) \ + int name (struct vfs_volume* UNUSED volume, struct proc* UNUSED proc, \ + struct reschedule_ctx* UNUSED rctx, const char* UNUSED path, uint8_t* UNUSED buffer, \ + size_t UNUSED off, size_t UNUSED size) + +#define DEFINE_VFS_WRITE_FILE(name) \ + int name (struct vfs_volume* UNUSED volume, struct proc* UNUSED proc, \ + struct reschedule_ctx* UNUSED rctx, const char* UNUSED path, uint8_t* UNUSED buffer, \ + size_t UNUSED off, size_t UNUSED size, uint32_t UNUSED flags) + +#define DEFINE_VFS_READ_DIR_ENTRY(name) \ + int name (struct vfs_volume* UNUSED volume, struct proc* UNUSED proc, \ + struct reschedule_ctx* UNUSED rctx, const char* UNUSED path, \ + struct dir_entry* UNUSED entry, size_t UNUSED entry_num) + +#define DEFINE_VFS_CREATE_FILE(name) \ + int name (struct vfs_volume* UNUSED volume, struct proc* UNUSED proc, \ + struct reschedule_ctx* UNUSED rctx, const char* UNUSED path) + +#define DEFINE_VFS_CREATE_DIR(name) \ + int name (struct vfs_volume* UNUSED volume, struct proc* UNUSED proc, \ + struct reschedule_ctx* UNUSED rctx, const char* UNUSED path) + +#define DEFINE_VFS_REMOVE(name) \ + int name (struct vfs_volume* UNUSED volume, struct proc* UNUSED proc, \ + struct reschedule_ctx* UNUSED rctx, const char* UNUSED path) + +#endif // _KERNEL_FS_DEF_VFS_OP_H diff --git a/kernel/fs/fatfs.c b/kernel/fs/fatfs.c index 85e8783..d40eb79 100644 --- a/kernel/fs/fatfs.c +++ b/kernel/fs/fatfs.c @@ -96,8 +96,7 @@ static int fat1_diskio_write (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* b return 1; } -int fatfs_mount (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - bool format) { +DEFINE_VFS_MOUNT (fatfs_mount) { struct fatfs_ctx* fatfs_ctx = malloc (sizeof (*fatfs_ctx)); int r; @@ -127,7 +126,7 @@ int fatfs_mount (struct vfs_volume* volume, struct proc* proc, struct reschedule return ST_OK; } -int fatfs16_format (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx) { +DEFINE_VFS_FORMAT (fatfs16_format) { uint64_t fd; struct fatfs_ctx* fatfs_ctx = volume->udata; @@ -145,7 +144,7 @@ int fatfs16_format (struct vfs_volume* volume, struct proc* proc, struct resched return r < 0 ? -ST_FORMAT_ERROR : ST_OK; } -int fatfs32_format (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx) { +DEFINE_VFS_FORMAT (fatfs32_format) { uint64_t fd; struct fatfs_ctx* fatfs_ctx = volume->udata; @@ -163,8 +162,7 @@ int fatfs32_format (struct vfs_volume* volume, struct proc* proc, struct resched return r < 0 ? -ST_FORMAT_ERROR : ST_OK; } -int fatfs_describe (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - const char* path, struct desc* desc) { +DEFINE_VFS_DESCRIBE (fatfs_describe) { struct fatfs_ctx* fatfs_ctx = volume->udata; fatfs_ctx->proc = proc; fatfs_ctx->rctx = rctx; @@ -198,8 +196,7 @@ int fatfs_describe (struct vfs_volume* volume, struct proc* proc, struct resched return ST_OK; } -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) { +DEFINE_VFS_READ_FILE (fatfs_read_file) { struct fatfs_ctx* fatfs_ctx = volume->udata; fatfs_ctx->proc = proc; fatfs_ctx->rctx = rctx; @@ -220,8 +217,7 @@ int fatfs_read_file (struct vfs_volume* volume, struct proc* proc, struct resche return ST_OK; } -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) { +DEFINE_VFS_WRITE_FILE (fatfs_write_file) { struct fatfs_ctx* fatfs_ctx = volume->udata; fatfs_ctx->proc = proc; fatfs_ctx->rctx = rctx; @@ -247,8 +243,7 @@ int fatfs_write_file (struct vfs_volume* volume, struct proc* proc, struct resch return ST_OK; } -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) { +DEFINE_VFS_READ_DIR_ENTRY (fatfs_read_dir_entry) { struct fatfs_ctx* fatfs_ctx = volume->udata; FL_DIR dir; fatfs_ctx->proc = proc; @@ -276,8 +271,7 @@ int fatfs_read_dir_entry (struct vfs_volume* volume, struct proc* proc, struct r return ST_OK; } -int fatfs_create_file (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - const char* path) { +DEFINE_VFS_CREATE_FILE (fatfs_create_file) { struct fatfs_ctx* fatfs_ctx = volume->udata; fatfs_ctx->proc = proc; fatfs_ctx->rctx = rctx; @@ -291,8 +285,7 @@ int fatfs_create_file (struct vfs_volume* volume, struct proc* proc, struct resc return ST_OK; } -int fatfs_create_dir (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - const char* path) { +DEFINE_VFS_CREATE_DIR (fatfs_create_dir) { struct fatfs_ctx* fatfs_ctx = volume->udata; fatfs_ctx->proc = proc; fatfs_ctx->rctx = rctx; @@ -301,8 +294,7 @@ int fatfs_create_dir (struct vfs_volume* volume, struct proc* proc, struct resch return r == 0 ? ST_OK : -ST_CREATE_DIR_ERROR; } -int fatfs_remove (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - const char* path) { +DEFINE_VFS_REMOVE (fatfs_remove) { struct fatfs_ctx* fatfs_ctx = volume->udata; fatfs_ctx->proc = proc; fatfs_ctx->rctx = rctx; diff --git a/kernel/fs/fatfs.h b/kernel/fs/fatfs.h index 6ea16ec..582b924 100644 --- a/kernel/fs/fatfs.h +++ b/kernel/fs/fatfs.h @@ -4,38 +4,31 @@ #include #include #include +#include #include #include #include struct vfs_volume; -int fatfs_mount (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - bool format); +DEFINE_VFS_MOUNT (fatfs_mount); -int fatfs16_format (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx); +DEFINE_VFS_FORMAT (fatfs16_format); -int fatfs32_format (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx); +DEFINE_VFS_FORMAT (fatfs32_format); -int fatfs_describe (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - const char* path, struct desc* desc); +DEFINE_VFS_DESCRIBE (fatfs_describe); -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); +DEFINE_VFS_READ_FILE (fatfs_read_file); -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); +DEFINE_VFS_WRITE_FILE (fatfs_write_file); -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); +DEFINE_VFS_READ_DIR_ENTRY (fatfs_read_dir_entry); -int fatfs_create_file (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - const char* path); +DEFINE_VFS_CREATE_FILE (fatfs_create_file); -int fatfs_create_dir (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - const char* path); +DEFINE_VFS_CREATE_DIR (fatfs_create_dir); -int fatfs_remove (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - const char* path); +DEFINE_VFS_REMOVE (fatfs_remove); #endif // _KERNEL_FS_FATFS_H diff --git a/kernel/fs/tarfs.c b/kernel/fs/tarfs.c index 3edd72d..56a0dac 100644 --- a/kernel/fs/tarfs.c +++ b/kernel/fs/tarfs.c @@ -65,9 +65,7 @@ static size_t tar_parse (struct tarfs* tarfs, uint8_t* addr, size_t max_size) { return i; } -int tarfs_mount (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - bool format) { - (void)format; +DEFINE_VFS_MOUNT (tarfs_mount) { uint64_t fd; struct tarfs* tarfs = malloc (sizeof (*tarfs)); @@ -130,15 +128,9 @@ int tarfs_mount (struct vfs_volume* volume, struct proc* proc, struct reschedule return ret; } -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, struct proc* proc, struct reschedule_ctx* rctx, - const char* path, struct desc* desc) { - (void)proc, (void)rctx; +DEFINE_VFS_FORMAT (tarfs_format) { return ST_OK; } +DEFINE_VFS_DESCRIBE (tarfs_describe) { struct tarfs* tarfs = volume->udata; if ((path[0] == '/') && (path[1] == '\0')) { @@ -170,10 +162,7 @@ int tarfs_describe (struct vfs_volume* volume, struct proc* proc, struct resched } } -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; - +DEFINE_VFS_READ_FILE (tarfs_read_file) { const char* filename = path_basename (path); if (filename == NULL) @@ -192,10 +181,7 @@ int tarfs_read_file (struct vfs_volume* volume, struct proc* proc, struct resche return ST_OK; } -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; - +DEFINE_VFS_READ_DIR_ENTRY (tarfs_read_dir_entry) { struct tarfs* tarfs = volume->udata; if (strncmp (path, "/", PATH_MAX) != 0) { @@ -223,27 +209,10 @@ int tarfs_read_dir_entry (struct vfs_volume* volume, struct proc* proc, struct r return -ST_DIR_NO_ENTRIES; } -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; -} +DEFINE_VFS_WRITE_FILE (tarfs_write_file) { return ST_OK; } -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; -} +DEFINE_VFS_CREATE_FILE (tarfs_create_file) { return ST_OK; } -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; -} +DEFINE_VFS_CREATE_DIR (tarfs_create_dir) { return ST_OK; } -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; -} +DEFINE_VFS_REMOVE (tarfs_remove) { return ST_OK; } diff --git a/kernel/fs/tarfs.h b/kernel/fs/tarfs.h index 19c9b78..9f2dc8d 100644 --- a/kernel/fs/tarfs.h +++ b/kernel/fs/tarfs.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -34,30 +35,22 @@ struct tarfs { struct vfs_volume; -int tarfs_mount (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - bool format); +DEFINE_VFS_MOUNT (tarfs_mount); -int tarfs_format (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx); +DEFINE_VFS_FORMAT (tarfs_format); -int tarfs_describe (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - const char* path, struct desc* desc); +DEFINE_VFS_DESCRIBE (tarfs_describe); -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); +DEFINE_VFS_READ_FILE (tarfs_read_file); -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); +DEFINE_VFS_WRITE_FILE (tarfs_write_file); -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); +DEFINE_VFS_READ_DIR_ENTRY (tarfs_read_dir_entry); -int tarfs_create_file (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - const char* path); +DEFINE_VFS_CREATE_FILE (tarfs_create_file); -int tarfs_create_dir (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - const char* path); +DEFINE_VFS_CREATE_DIR (tarfs_create_dir); -int tarfs_remove (struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx, - const char* path); +DEFINE_VFS_REMOVE (tarfs_remove); #endif // _KERNEL_FS_TARFS_H