Volume-centric VFS implementation
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m41s

This commit is contained in:
2026-02-25 08:53:54 +01:00
parent 62a6543dab
commit 704db2dfa4
26 changed files with 441 additions and 406 deletions

View File

@@ -115,77 +115,57 @@ struct elf_aux proc_load_segments (struct proc* proc, uint8_t* elf) {
return aux;
}
struct proc* proc_from_file (struct procgroup* procgroup, const char* mountpoint,
const char* path) {
struct proc* proc_from_file (struct proc* proc1, const char* volume, const char* path,
struct reschedule_ctx* rctx) {
struct desc desc;
int ret;
if (procgroup == NULL) {
if (vfs_kernel_describe (mountpoint, path, &desc) < 0)
return NULL;
for (;;) {
ret = vfs_volume_open (proc1, volume, rctx);
if (desc.type != FS_FILE)
return NULL;
uint8_t* temp_buffer = malloc (desc.size);
if (temp_buffer == NULL)
return NULL;
if (vfs_kernel_read (mountpoint, path, temp_buffer, 0, desc.size) < 0) {
free (temp_buffer);
return NULL;
}
if (!proc_check_elf (temp_buffer)) {
free (temp_buffer);
return NULL;
}
struct proc* proc = proc_from_elf (temp_buffer);
free (temp_buffer);
return proc;
} else {
int handle = vfs_open (procgroup, mountpoint, path);
if (handle < 0)
return NULL;
if (vfs_describe (procgroup, handle, &desc) != ST_OK) {
vfs_close (procgroup, handle);
return NULL;
}
if (desc.type != FS_FILE) {
vfs_close (procgroup, handle);
return NULL;
}
uint8_t* temp_buffer = malloc (desc.size);
if (temp_buffer == NULL) {
vfs_close (procgroup, handle);
return NULL;
}
if (vfs_read (procgroup, handle, temp_buffer, 0, desc.size) != ST_OK) {
free (temp_buffer);
vfs_close (procgroup, handle);
return NULL;
}
vfs_close (procgroup, handle);
if (!proc_check_elf (temp_buffer)) {
free (temp_buffer);
return NULL;
}
struct proc* proc = proc_from_elf (temp_buffer);
free (temp_buffer);
return proc;
if (ret < 0) {
if (ret == -ST_TRY_AGAIN)
continue;
else
return NULL;
} else
break;
}
if ((ret = vfs_describe (proc1, volume, path, &desc, rctx)) < 0) {
vfs_volume_close (proc1, volume, rctx);
return NULL;
}
if (desc.type != FS_FILE) {
vfs_volume_close (proc1, volume, rctx);
return NULL;
}
uint8_t* temp_buffer = malloc (desc.size);
if (temp_buffer == NULL) {
vfs_volume_close (proc1, volume, rctx);
return NULL;
}
if ((ret = vfs_read (proc1, volume, path, temp_buffer, 0, desc.size, rctx)) < 0) {
free (temp_buffer);
vfs_volume_close (proc1, volume, rctx);
return NULL;
}
vfs_volume_close (proc1, volume, rctx);
if (!proc_check_elf (temp_buffer)) {
free (temp_buffer);
return NULL;
}
struct proc* proc = proc_from_elf (temp_buffer);
free (temp_buffer);
return proc;
}
struct proc* proc_find_pid (int pid) {
@@ -358,10 +338,12 @@ void proc_init (void) {
irq_attach (&proc_irq_sched, NULL, CPU_REQUEST_SCHED);
#endif
struct proc* spin_proc = proc_from_file (NULL, "ramdisk", "/spin");
struct reschedule_ctx rctx = {.cpu = NULL, .reschedule = false};
struct proc* spin_proc = proc_from_file (VFS_KERNEL, "ramdisk", "/spin", &rctx);
proc_register (spin_proc, thiscpu, NULL);
struct proc* init = proc_from_file (NULL, "ramdisk", "/init");
struct proc* init = proc_from_file (VFS_KERNEL, "ramdisk", "/init", &rctx);
init->procgroup->capabilities |= (PROC_CAP_TERMINAL | PROC_CAP_KB);
proc_register (init, thiscpu, NULL);