Redesign the VFS
This commit is contained in:
@ -5,7 +5,6 @@
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include "spinlock/spinlock.h"
|
||||
#include "fs/kvfs/kvfs.h"
|
||||
#include "fs/portlfs/portlfs.h"
|
||||
#include "storedev/storedev.h"
|
||||
|
||||
@ -13,12 +12,10 @@
|
||||
#define VFS_MOUNTPOINTS_MAX 30
|
||||
|
||||
enum {
|
||||
VFS_KVFS,
|
||||
VFS_LITTLEFS,
|
||||
};
|
||||
|
||||
static const char *vfs_strings[] = {
|
||||
"KVFS",
|
||||
"Little FS",
|
||||
};
|
||||
|
||||
@ -27,27 +24,41 @@ enum {
|
||||
VFS_TYPE_FILE,
|
||||
};
|
||||
|
||||
enum {
|
||||
VFS_FLAG_READ = 1<<0,
|
||||
VFS_FLAG_WRITE = 1<<1,
|
||||
VFS_FLAG_MAKE = 1<<2,
|
||||
};
|
||||
|
||||
#define VFS_PATH_MAX 1024
|
||||
|
||||
typedef struct VfsStat {
|
||||
size_t size;
|
||||
int32_t type;
|
||||
} VfsStat;
|
||||
|
||||
typedef struct VfsObj {
|
||||
SpinLock spinlock;
|
||||
int32_t refs;
|
||||
void *extra;
|
||||
size_t extrasize;
|
||||
struct VfsMountPoint *vmp;
|
||||
char path[VFS_PATH_MAX];
|
||||
int32_t (*read)(struct VfsObj *vobj, uint8_t *const buffer, size_t n, size_t off);
|
||||
int32_t (*stat)(struct VfsObj *vobj, struct VfsStat *stat);
|
||||
void (*cleanup)(struct VfsObj *vobj);
|
||||
} VfsObj;
|
||||
|
||||
typedef struct VfsMountPoint {
|
||||
bool taken;
|
||||
uint8_t label[VFS_MOUNTPOINT_LABEL_MAX];
|
||||
int32_t fstype;
|
||||
StoreDev *backingsd;
|
||||
|
||||
int32_t (*read)(struct VfsMountPoint *vmp, const char *path, uint8_t *const buffer, size_t n, size_t off);
|
||||
int32_t (*stat)(struct VfsMountPoint *vmp, const char *path, struct VfsStat *stat);
|
||||
int32_t (*write)(struct VfsMountPoint *vmp, const char *path, const uint8_t *const buffer, size_t n, size_t off);
|
||||
int32_t (*remove)(struct VfsMountPoint *vmp, const char *path);
|
||||
int32_t (*create)(struct VfsMountPoint *vmp, const char *path, int32_t type);
|
||||
VfsObj *(*open)(struct VfsMountPoint *vmp, const char *path, uint32_t flags);
|
||||
int32_t (*cleanup)(struct VfsMountPoint *vmp);
|
||||
bool (*check)(void);
|
||||
|
||||
union {
|
||||
Kvfs kvfs;
|
||||
LittleFs littlefs;
|
||||
} fs;
|
||||
SpinLock spinlock;
|
||||
@ -61,12 +72,9 @@ typedef struct {
|
||||
extern VfsTable VFS_TABLE;
|
||||
|
||||
void vfs_init(void);
|
||||
int32_t vfs_read(char *mountpoint, const char *path, uint8_t *const buffer, size_t n, size_t off);
|
||||
int32_t vfs_stat(char *mountpoint, const char *path, VfsStat *stat);
|
||||
int32_t vfs_write(char *mountpoint, const char *path, const uint8_t *const buffer, size_t n, size_t off);
|
||||
int32_t vfs_remove(char *mountpoint, const char *path);
|
||||
int32_t vfs_create(char *mountpoint, const char *path, int32_t type);
|
||||
int32_t vfs_unmount(char *mountpoint);
|
||||
|
||||
int32_t vfs_mount(char *mountpoint, int32_t fstype, StoreDev *backingsd);
|
||||
void vfs_close(VfsObj *vobj);
|
||||
VfsObj *vfs_open(char *mountpoint, const char *path, uint32_t flags);
|
||||
|
||||
#endif // VFS_VFS_H_
|
||||
|
Reference in New Issue
Block a user