Wrap filesystem op in macros
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m32s

This commit is contained in:
2026-03-15 14:50:13 +01:00
parent cd5604da43
commit d7bfc5c8fd
5 changed files with 85 additions and 93 deletions

45
kernel/fs/def_vfs_op.h Normal file
View File

@@ -0,0 +1,45 @@
#ifndef _KERNEL_FS_DEF_VFS_OP_H
#define _KERNEL_FS_DEF_VFS_OP_H
#include <aux/compiler.h>
#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

View File

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

View File

@@ -4,38 +4,31 @@
#include <desc.h>
#include <device/device.h>
#include <dir_entry.h>
#include <fs/def_vfs_op.h>
#include <libk/std.h>
#include <proc/proc.h>
#include <proc/reschedule.h>
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

View File

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

View File

@@ -4,6 +4,7 @@
#include <desc.h>
#include <device/device.h>
#include <dir_entry.h>
#include <fs/def_vfs_op.h>
#include <libk/std.h>
#include <proc/proc.h>
#include <proc/reschedule.h>
@@ -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