Simple VFS layer

This commit is contained in:
2025-08-15 01:41:11 +02:00
parent b470fb03da
commit d91330ba73
16 changed files with 403 additions and 2 deletions

46
kernel/vfs/vfs.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef VFS_VFS_H_
#define VFS_VFS_H_
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "spinlock/spinlock.h"
#include "fs/kvfs/kvfs.h"
#define VFS_MOUNTPOINT_LABEL_MAX 128
#define VFS_MOUNTPOINTS_MAX 30
enum {
VFS_FATFS,
VFS_KVFS,
};
typedef struct VfsMountPoint {
bool taken;
uint8_t label[VFS_MOUNTPOINT_LABEL_MAX];
int32_t fstype;
int32_t (*read)(struct VfsMountPoint *vmp, const char *path, uint8_t *const buffer, size_t n);
int32_t (*write)(struct VfsMountPoint *vmp, const char *path, const uint8_t *const buffer, size_t n);
int32_t (*remove)(struct VfsMountPoint *vmp, const char *path);
bool (*check)(void);
union {
Kvfs kvfs;
} fs;
SpinLock spinlock;
} VfsMountPoint;
typedef struct {
SpinLock spinlock;
VfsMountPoint mountpoints[VFS_MOUNTPOINTS_MAX];
} VfsTable;
extern VfsTable VFS_TABLE;
void vfs_init(void);
int32_t vfs_read(char *mountpoint, const char *path, uint8_t *const buffer, size_t n);
int32_t vfs_write(char *mountpoint, const char *path, const uint8_t *const buffer, size_t n);
int32_t vfs_remove(char *mountpoint, const char *path);
#endif // VFS_VFS_H_