Temporary mountpoint (temp)

This commit is contained in:
2025-09-09 19:38:39 +02:00
parent 71be9c5fb3
commit 3b42abc027
3 changed files with 24 additions and 11 deletions

View File

@ -15,7 +15,7 @@
VfsTable VFS_TABLE;
void vfs_init_littlefs(VfsMountPoint *mp) {
void vfs_init_littlefs(VfsMountPoint *mp, bool format) {
struct lfs_config *cfg = dlmalloc(sizeof(*cfg));
hal_memset(cfg, 0, sizeof(*cfg));
cfg->context = mp;
@ -36,16 +36,19 @@ void vfs_init_littlefs(VfsMountPoint *mp) {
cfg->name_max = 0;
cfg->file_max = 0;
cfg->attr_max = 0;
if (format) {
lfs_format(&mp->fs.littlefs.instance, cfg);
}
int err = lfs_mount(&mp->fs.littlefs.instance, cfg);
if (err < 0) {
ERR("vfs", "Little FS mount failed\n");
ERR("vfs", "Little FS mount failed %d\n", err);
}
mp->cleanup = &littlefs_cleanup;
mp->open = &littlefs_open;
}
int32_t vfs_mount(char *mountpoint, int32_t fstype, StoreDev *backingsd) {
int32_t vfs_mount(char *mountpoint, int32_t fstype, StoreDev *backingsd, bool format) {
VfsMountPoint *mp = NULL;
spinlock_acquire(&VFS_TABLE.spinlock);
@ -61,7 +64,7 @@ int32_t vfs_mount(char *mountpoint, int32_t fstype, StoreDev *backingsd) {
mp->fstype = fstype;
switch (fstype) {
case VFS_LITTLEFS:
vfs_init_littlefs(mp);
vfs_init_littlefs(mp, format);
break;
default:
return E_UNKNOWN_FSTYPE;
@ -114,13 +117,23 @@ void vfs_init(void) {
hal_memset(&VFS_TABLE, 0, sizeof(VFS_TABLE));
spinlock_init(&VFS_TABLE.spinlock);
{
RamSdInitExtra extra = { .capacity = baseimg_getsize(), .preallocbuffer = (uint8_t *)baseimg_getaddr() };
StoreDev *backingsd = storedev_create(STOREDEV_RAMSD, &extra);
if (backingsd == NULL) {
return;
}
vfs_mount("base", VFS_LITTLEFS, backingsd, false);
}
vfs_mount("base", VFS_LITTLEFS, backingsd);
{
RamSdInitExtra extra = { .capacity = (1024*1024*10) };
StoreDev *backingsd = storedev_create(STOREDEV_RAMSD, &extra);
if (backingsd == NULL) {
return;
}
vfs_mount("temp", VFS_LITTLEFS, backingsd, true);
}
LOG("vfs", "init\n");

View File

@ -74,7 +74,7 @@ extern VfsTable VFS_TABLE;
void vfs_init(void);
int32_t vfs_unmount(char *mountpoint);
int32_t vfs_mount(char *mountpoint, int32_t fstype, StoreDev *backingsd);
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);

View File

@ -12,7 +12,7 @@ void main(void) {
int32_t ioh = ioctl(IOCTL_NOHANDLE,
IOCTL_OPENF,
(uint64_t)"base:/hello.txt",
(uint64_t)"temp:/hello.txt",
IOCTL_F_WRITE | IOCTL_F_READ | IOCTL_F_MAKE,
0
);