fat_io_lib finally works, implement virtual partition devices, manage devices via string keys
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m35s

This commit is contained in:
2026-03-01 00:00:27 +01:00
parent baa13fb695
commit 0533c2705d
37 changed files with 619 additions and 139 deletions

View File

@@ -22,8 +22,8 @@ static struct vfs_volume_table volume_table;
static struct vfs_volume* vfs_find_volume (const char* volume) {
struct hash_node_link* found_link = NULL;
size_t volume_len = strlen (volume);
uint32_t hash = hash_fnv32 (volume, strlen (volume));
size_t volume_len = strlen_null (volume);
uint32_t hash = hash_fnv32 (volume, volume_len);
spin_lock (&volume_table.lock);
hash_find (&volume_table, volume, volume_len, hash, lengthof (volume_table.volume_buckets),
@@ -36,8 +36,7 @@ static struct vfs_volume* vfs_find_volume (const char* volume) {
return hash_entry (found_link, struct vfs_volume, volume_table_link);
}
int vfs_create_volume (const char* key, int fs_type, struct device* back_device, struct proc* proc,
struct reschedule_ctx* rctx) {
int vfs_create_volume (const char* key, int fs_type, struct device* back_device) {
if (strlen_null (key) > VOLUME_MAX)
return -ST_OOB_ERROR;
@@ -56,14 +55,26 @@ int vfs_create_volume (const char* key, int fs_type, struct device* back_device,
switch (volume->fs_type) {
case VFS_TARFS:
volume->driver_ops.mount = &tarfs_mount;
volume->driver_ops.format = &tarfs_format;
volume->driver_ops.describe = &tarfs_describe;
volume->driver_ops.read = &tarfs_read;
volume->driver_ops.write = &tarfs_write;
volume->driver_ops.read_dir_entry = &tarfs_read_dir_entry;
break;
case VFS_FAT16:
volume->driver_ops.mount = &fatfs_mount;
volume->driver_ops.format = &fatfs16_format;
volume->driver_ops.describe = &fatfs_describe;
volume->driver_ops.read = &fatfs_read;
volume->driver_ops.write = &fatfs_write;
volume->driver_ops.read_dir_entry = &fatfs_read_dir_entry;
break;
case VFS_FAT32:
volume->driver_ops.mount = &fatfs_mount;
volume->driver_ops.format = &fatfs32_format;
volume->driver_ops.describe = &fatfs_describe;
volume->driver_ops.read = &fatfs_read;
volume->driver_ops.write = &fatfs_write;
volume->driver_ops.read_dir_entry = &fatfs_read_dir_entry;
break;
default:
@@ -71,14 +82,14 @@ int vfs_create_volume (const char* key, int fs_type, struct device* back_device,
return -ST_MOUNT_ERROR;
}
int ret = volume->driver_ops.mount (volume, proc, rctx);
int ret = volume->driver_ops.mount (volume);
if (ret < 0) {
free (volume);
return ret;
}
uint32_t mp_hash = hash_fnv32 (volume->key, strlen (volume->key));
uint32_t mp_hash = hash_fnv32 (volume->key, strlen_null (volume->key));
spin_lock (&volume_table.lock);
@@ -135,7 +146,7 @@ int vfs_volume_close (struct proc* proc, const char* volume_name, struct resched
struct proc_sq_entry* sq_entry = list_entry (node, struct proc_sq_entry, sq_link);
struct proc* resumed_proc = sq_entry->proc;
volume->owner = proc;
volume->owner = resumed_proc;
volume->locked = true;
spin_unlock (&volume->sq.lock);
@@ -154,6 +165,24 @@ int vfs_volume_close (struct proc* proc, const char* volume_name, struct resched
return ST_OK;
}
int vfs_format (struct proc* proc, const char* volume_name) {
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
return -ST_NOT_FOUND;
spin_lock (&volume->lock);
if (volume->locked && volume->owner != proc) {
spin_unlock (&volume->lock);
return -ST_PERMISSION_ERROR;
}
spin_unlock (&volume->lock);
return volume->driver_ops.format (volume);
}
int vfs_read (struct proc* proc, const char* volume_name, const char* path, uint8_t* buffer,
size_t off, size_t size) {
struct vfs_volume* volume = vfs_find_volume (volume_name);