Implement storedevs, prepare to port littlefs
This commit is contained in:
@ -9,14 +9,10 @@
|
||||
#include "assert.h"
|
||||
#include "errors.h"
|
||||
#include "fs/kvfs/kvfs.h"
|
||||
#include "storedev/storedev.h"
|
||||
|
||||
VfsTable VFS_TABLE;
|
||||
|
||||
static const char *vfs_strings[] = {
|
||||
[VFS_FATFS] = "FAT",
|
||||
[VFS_KVFS] = "KVFS",
|
||||
};
|
||||
|
||||
void vfs_init_kvfs(VfsMountPoint *mp) {
|
||||
mp->read = &kvfs_read;
|
||||
mp->write = &kvfs_write;
|
||||
@ -25,7 +21,7 @@ void vfs_init_kvfs(VfsMountPoint *mp) {
|
||||
mp->cleanup = &kvfs_cleanup;
|
||||
}
|
||||
|
||||
int32_t vfs_mount(char *mountpoint, int32_t fstype) {
|
||||
int32_t vfs_mount(char *mountpoint, int32_t fstype, StoreDev *backingsd) {
|
||||
VfsMountPoint *mp = NULL;
|
||||
|
||||
spinlock_acquire(&VFS_TABLE.spinlock);
|
||||
@ -37,6 +33,7 @@ int32_t vfs_mount(char *mountpoint, int32_t fstype) {
|
||||
}
|
||||
|
||||
hal_memcpy(mp->label, mountpoint, hal_strlen(mountpoint));
|
||||
mp->backingsd = backingsd;
|
||||
mp->fstype = fstype;
|
||||
switch (fstype) {
|
||||
case VFS_KVFS:
|
||||
@ -113,18 +110,28 @@ int32_t vfs_remove(char *mountpoint, const char *path) {
|
||||
return mp->remove(mp, path);
|
||||
}
|
||||
|
||||
int32_t tmpvars_init(void) {
|
||||
RamSdInitExtra extra = { .capacity = KVFS_NODES_MAX * KVFS_BUFFER_SIZE };
|
||||
StoreDev *backingsd = storedev_create(STOREDEV_RAMSD, &extra);
|
||||
if (backingsd == NULL) {
|
||||
return E_NOMEMORY;
|
||||
}
|
||||
return vfs_mount("tmpvars", VFS_KVFS, backingsd);
|
||||
}
|
||||
|
||||
void vfs_init(void) {
|
||||
hal_memset(&VFS_TABLE, 0, sizeof(VFS_TABLE));
|
||||
spinlock_init(&VFS_TABLE.spinlock);
|
||||
|
||||
ASSERT("vfs", vfs_mount("tmpvars", VFS_KVFS) == E_OK, "could not create tmpvars mount point\n");
|
||||
tmpvars_init();
|
||||
|
||||
LOG("vfs", "init done\n");
|
||||
|
||||
for (size_t i = 0; i < LEN(VFS_TABLE.mountpoints); i++) {
|
||||
if (!VFS_TABLE.mountpoints[i].taken) continue;
|
||||
VfsMountPoint *vmp = &VFS_TABLE.mountpoints[i];
|
||||
LOG("vfs", "mount point %s: %s\n", vmp->label, vfs_strings[vmp->fstype]);
|
||||
LOG("vfs", "mount point %s: %s, backing device: %s\n",
|
||||
vmp->label, vfs_strings[vmp->fstype], storedev_strings[vmp->backingsd->sdtype]);
|
||||
if (vmp->check != NULL) {
|
||||
LOG("vfs", "check = %s\n", vmp->check() ? "OK" : "FAIL");
|
||||
} else {
|
||||
|
@ -6,19 +6,24 @@
|
||||
#include <stdbool.h>
|
||||
#include "spinlock/spinlock.h"
|
||||
#include "fs/kvfs/kvfs.h"
|
||||
#include "storedev/storedev.h"
|
||||
|
||||
#define VFS_MOUNTPOINT_LABEL_MAX 128
|
||||
#define VFS_MOUNTPOINTS_MAX 30
|
||||
|
||||
enum {
|
||||
VFS_FATFS,
|
||||
VFS_KVFS,
|
||||
};
|
||||
|
||||
static const char *vfs_strings[] = {
|
||||
"KVFS"
|
||||
};
|
||||
|
||||
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 (*write)(struct VfsMountPoint *vmp, const char *path, const uint8_t *const buffer, size_t n, size_t off);
|
||||
|
Reference in New Issue
Block a user