KVFS improvements
This commit is contained in:
@ -14,7 +14,7 @@ VfsTable VFS_TABLE;
|
||||
|
||||
static const char *vfs_strings[] = {
|
||||
[VFS_FATFS] = "FAT",
|
||||
[VFS_KVFS] = "Kvfs",
|
||||
[VFS_KVFS] = "KVFS",
|
||||
};
|
||||
|
||||
void vfs_init_kvfs(VfsMountPoint *mp) {
|
||||
@ -22,6 +22,7 @@ void vfs_init_kvfs(VfsMountPoint *mp) {
|
||||
mp->write = &kvfs_write;
|
||||
mp->remove = &kvfs_remove;
|
||||
mp->check = &kvfs_check;
|
||||
mp->cleanup = &kvfs_cleanup;
|
||||
}
|
||||
|
||||
int32_t vfs_mount(char *mountpoint, int32_t fstype) {
|
||||
@ -48,7 +49,7 @@ int32_t vfs_mount(char *mountpoint, int32_t fstype) {
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t vfs_read(char *mountpoint, const char *path, uint8_t *const buffer, size_t n) {
|
||||
int32_t vfs_unmount(char *mountpoint) {
|
||||
VfsMountPoint *mp = NULL;
|
||||
|
||||
spinlock_acquire(&VFS_TABLE.spinlock);
|
||||
@ -59,10 +60,18 @@ int32_t vfs_read(char *mountpoint, const char *path, uint8_t *const buffer, size
|
||||
return E_NOENTRY;
|
||||
}
|
||||
|
||||
return mp->read(mp, path, buffer, n);
|
||||
spinlock_acquire(&mp->spinlock);
|
||||
int32_t err = mp->cleanup(mp);
|
||||
if (err != E_OK) {
|
||||
spinlock_release(&mp->spinlock);
|
||||
return err;
|
||||
}
|
||||
hal_memset(mp, 0, sizeof(*mp));
|
||||
spinlock_release(&mp->spinlock);
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t vfs_write(char *mountpoint, const char *path, const uint8_t *const buffer, size_t n) {
|
||||
int32_t vfs_read(char *mountpoint, const char *path, uint8_t *const buffer, size_t n, size_t off) {
|
||||
VfsMountPoint *mp = NULL;
|
||||
|
||||
spinlock_acquire(&VFS_TABLE.spinlock);
|
||||
@ -73,7 +82,21 @@ int32_t vfs_write(char *mountpoint, const char *path, const uint8_t *const buffe
|
||||
return E_NOENTRY;
|
||||
}
|
||||
|
||||
return mp->write(mp, path, buffer, n);
|
||||
return mp->read(mp, path, buffer, n, off);
|
||||
}
|
||||
|
||||
int32_t vfs_write(char *mountpoint, const char *path, const uint8_t *const buffer, size_t n, size_t off) {
|
||||
VfsMountPoint *mp = NULL;
|
||||
|
||||
spinlock_acquire(&VFS_TABLE.spinlock);
|
||||
HSHTB_GET(&VFS_TABLE, mountpoints, mountpoint, label, mp);
|
||||
spinlock_release(&VFS_TABLE.spinlock);
|
||||
|
||||
if (mp == NULL) {
|
||||
return E_NOENTRY;
|
||||
}
|
||||
|
||||
return mp->write(mp, path, buffer, n, off);
|
||||
}
|
||||
|
||||
int32_t vfs_remove(char *mountpoint, const char *path) {
|
||||
@ -94,7 +117,7 @@ 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");
|
||||
ASSERT("vfs", vfs_mount("tmpvars", VFS_KVFS) == E_OK, "could not create tmpvars mount point\n");
|
||||
|
||||
LOG("vfs", "init done\n");
|
||||
|
||||
@ -102,7 +125,11 @@ void vfs_init(void) {
|
||||
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", "check = %s\n", vmp->check() ? "OK" : "FAIL");
|
||||
if (vmp->check != NULL) {
|
||||
LOG("vfs", "check = %s\n", vmp->check() ? "OK" : "FAIL");
|
||||
} else {
|
||||
LOG("vfs", "check skipped\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user