From c30d2d2ea6743d5bcb73436c4ef6b30c40edf2a6 Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Fri, 3 Oct 2025 19:55:14 +0200 Subject: [PATCH] Remove conversions between VfsStat struct and IoctlStat struct --- kernel/fs/portlfs/portlfs.c | 6 +++--- kernel/fs/portlfs/portlfs.h | 3 +-- kernel/proc/proc.c | 5 +++-- kernel/syscall/ioctl.c | 9 +-------- kernel/vfs/vfs.c | 2 +- kernel/vfs/vfs.h | 14 ++------------ 6 files changed, 11 insertions(+), 28 deletions(-) diff --git a/kernel/fs/portlfs/portlfs.c b/kernel/fs/portlfs/portlfs.c index 3fdb625..4121d1b 100644 --- a/kernel/fs/portlfs/portlfs.c +++ b/kernel/fs/portlfs/portlfs.c @@ -72,7 +72,7 @@ int32_t littlefs_vobj_write(struct VfsObj *vobj, const uint8_t *const buffer, si return E_OK; } -int32_t littlefs_stat(struct VfsMountPoint *vmp, const char *path, struct VfsStat *statbuf) { +int32_t littlefs_stat(struct VfsMountPoint *vmp, const char *path, IoctlStat *statbuf) { struct lfs_info info; spinlock_acquire(&vmp->spinlock); @@ -84,10 +84,10 @@ int32_t littlefs_stat(struct VfsMountPoint *vmp, const char *path, struct VfsSta } if (info.type == LFS_TYPE_REG) { - statbuf->type = VFS_TYPE_FILE; + statbuf->type = IOCTLSTAT_FILE; statbuf->size = info.size; } else if (info.type == LFS_TYPE_DIR) { - statbuf->type = VFS_TYPE_DIR; + statbuf->type = IOCTLSTAT_DIR; statbuf->size = 0; // TODO: find a better way than this... !!! lfs_dir_t dir; diff --git a/kernel/fs/portlfs/portlfs.h b/kernel/fs/portlfs/portlfs.h index 81dd302..888318d 100644 --- a/kernel/fs/portlfs/portlfs.h +++ b/kernel/fs/portlfs/portlfs.h @@ -9,7 +9,6 @@ #define LITTLEFS_BLOCK_SIZE 4096 struct VfsMountPoint; -struct VfsStat; struct VfsObj; typedef struct { @@ -18,7 +17,7 @@ typedef struct { int32_t littlefs_cleanup(struct VfsMountPoint *vmp); struct VfsObj *littlefs_open(struct VfsMountPoint *vmp, const char *path, uint32_t flags); -int32_t littlefs_stat(struct VfsMountPoint *vmp, const char *path, struct VfsStat *statbuf); +int32_t littlefs_stat(struct VfsMountPoint *vmp, const char *path, IoctlStat *statbuf); int32_t littlefs_fetchdirent(struct VfsMountPoint *vmp, const char *path, IoctlDirent *direntbuf, size_t idx); int portlfs_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size); diff --git a/kernel/proc/proc.c b/kernel/proc/proc.c index 8622820..af98760 100644 --- a/kernel/proc/proc.c +++ b/kernel/proc/proc.c @@ -14,6 +14,7 @@ #include "bootinfo/bootinfo.h" #include "ipc/pipe/pipe.h" #include "sysdefs/processctl.h" +#include "sysdefs/ioctl.h" #define PROC_REAPER_FREQ 30 @@ -74,12 +75,12 @@ ElfAuxval proc_load_elf_segs(Proc *proc, uint8_t *data) { } Proc *proc_spawnuser(char *mountpoint, char *path) { - VfsStat stat; + IoctlStat stat; if (vfs_stat(mountpoint, path, &stat) != E_OK) { return NULL; } - if (stat.type != VFS_TYPE_FILE) { + if (stat.type != IOCTLSTAT_FILE) { return NULL; } diff --git a/kernel/syscall/ioctl.c b/kernel/syscall/ioctl.c index 85d316d..2cd1a50 100644 --- a/kernel/syscall/ioctl.c +++ b/kernel/syscall/ioctl.c @@ -152,14 +152,7 @@ int32_t SYSCALL5(sys_ioctl, ioh1, cmd1, arg1, arg2, arg3) { path_parse(opath, mp, path); - VfsStat stat1; - ret = vfs_stat(mp, path, &stat1); - if (ret != E_OK) { - goto done; - } - - iostat->size = stat1.size; - iostat->type = stat1.type; + ret = vfs_stat(mp, path, iostat); } break; case IOCTL_FETCHDIRENT: { const char *opath = (const char *)arg1; diff --git a/kernel/vfs/vfs.c b/kernel/vfs/vfs.c index 57d7c0f..95b403a 100644 --- a/kernel/vfs/vfs.c +++ b/kernel/vfs/vfs.c @@ -50,7 +50,7 @@ void vfs_init_littlefs(VfsMountPoint *mp, bool format) { mp->fetchdirent = &littlefs_fetchdirent; } -int32_t vfs_stat(char *mountpoint, const char *path, VfsStat *stat) { +int32_t vfs_stat(char *mountpoint, const char *path, IoctlStat *stat) { VfsMountPoint *mp = NULL; spinlock_acquire(&VFS_TABLE.spinlock); diff --git a/kernel/vfs/vfs.h b/kernel/vfs/vfs.h index 241d7df..90f6f81 100644 --- a/kernel/vfs/vfs.h +++ b/kernel/vfs/vfs.h @@ -20,11 +20,6 @@ static const char *vfs_strings[] = { "Little FS", }; -enum { - VFS_TYPE_DIR = 0, - VFS_TYPE_FILE = 1, -}; - enum { VFS_FLAG_READ = 1<<0, VFS_FLAG_WRITE = 1<<1, @@ -33,11 +28,6 @@ enum { #define VFS_PATH_MAX 1024 -typedef struct VfsStat { - size_t size; - int32_t type; -} VfsStat; - typedef struct VfsObj { SpinLock spinlock; void *extra; @@ -58,7 +48,7 @@ typedef struct VfsMountPoint { VfsObj *(*open)(struct VfsMountPoint *vmp, const char *path, uint32_t flags); int32_t (*cleanup)(struct VfsMountPoint *vmp); - int32_t (*stat)(struct VfsMountPoint *vmp, const char *path, struct VfsStat *statbuf); + int32_t (*stat)(struct VfsMountPoint *vmp, const char *path, IoctlStat *statbuf); int32_t (*fetchdirent)(struct VfsMountPoint *vmp, const char *path, IoctlDirent *direntbuf, size_t idx); union { @@ -79,7 +69,7 @@ int32_t vfs_unmount(char *mountpoint); int32_t vfs_mount(char *mountpoint, int32_t fstype, StoreDev *backingsd, bool format); void vfs_close(VfsObj *vobj); VfsObj *vfs_open(char *mountpoint, const char *path, uint32_t flags); -int32_t vfs_stat(char *mountpoint, const char *path, VfsStat *stat); +int32_t vfs_stat(char *mountpoint, const char *path, IoctlStat *stat); int32_t vfs_fetchdirent(char *mountpoint, const char *path, IoctlDirent *direntbuf, size_t idx); #endif // VFS_VFS_H_