Implement storedevs, prepare to port littlefs

This commit is contained in:
2025-08-16 12:34:36 +02:00
parent c936910199
commit 2b0566c56f
91 changed files with 54963 additions and 37 deletions

View File

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