Volume-centric VFS implementation
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m41s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m41s
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <libk/list.h>
|
||||
#include <libk/rbtree.h>
|
||||
#include <libk/std.h>
|
||||
#include <path_defs.h>
|
||||
#include <proc/procgroup.h>
|
||||
#include <proc/resource.h>
|
||||
#include <proc/suspension_q.h>
|
||||
@@ -45,6 +46,7 @@ struct proc {
|
||||
uintptr_t uvaddr_argument;
|
||||
void* mail_recv_buffer;
|
||||
size_t mail_recv_size;
|
||||
char cwv[VOLUME_MAX];
|
||||
};
|
||||
|
||||
void proc_sched (void);
|
||||
@@ -57,7 +59,8 @@ void proc_register (struct proc* proc, struct cpu* register_cpu, struct reschedu
|
||||
|
||||
struct proc* proc_find_pid (int pid);
|
||||
|
||||
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);
|
||||
|
||||
void proc_free_pid (int pid);
|
||||
|
||||
|
||||
@@ -151,13 +151,7 @@ struct procgroup* procgroup_create (void) {
|
||||
|
||||
memset (procgroup, 0, sizeof (*procgroup));
|
||||
|
||||
if (!id_alloc_init (&procgroup->vfs_handle_id_alloc, PROCGROUP_VFS_HANDLES_MAX)) {
|
||||
free (procgroup);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!id_alloc_init (&procgroup->rid_alloc, PROCGROUP_RESOURCES_MAX)) {
|
||||
id_alloc_fini (&procgroup->vfs_handle_id_alloc);
|
||||
free (procgroup);
|
||||
return NULL;
|
||||
}
|
||||
@@ -166,7 +160,6 @@ struct procgroup* procgroup_create (void) {
|
||||
|
||||
if (procgroup->pgid < 0) {
|
||||
id_alloc_fini (&procgroup->rid_alloc);
|
||||
id_alloc_fini (&procgroup->vfs_handle_id_alloc);
|
||||
free (procgroup);
|
||||
return NULL;
|
||||
}
|
||||
@@ -178,7 +171,6 @@ struct procgroup* procgroup_create (void) {
|
||||
|
||||
if (proc_create_resource_mail (procgroup) == NULL) {
|
||||
id_alloc_fini (&procgroup->rid_alloc);
|
||||
id_alloc_fini (&procgroup->vfs_handle_id_alloc);
|
||||
free (procgroup);
|
||||
return NULL;
|
||||
}
|
||||
@@ -237,9 +229,6 @@ static void procgroup_delete (struct procgroup* procgroup, struct reschedule_ctx
|
||||
proc_delete_resource (procgroup, resource, rctx);
|
||||
}
|
||||
|
||||
/* unlock VFS owned mountpoints */
|
||||
vfs_procgroup_cleanup (procgroup);
|
||||
|
||||
/* delete mappings */
|
||||
struct list_node_link *mapping_link, *mapping_link_tmp;
|
||||
list_foreach (procgroup->mappings, mapping_link, mapping_link_tmp) {
|
||||
@@ -254,7 +243,6 @@ static void procgroup_delete (struct procgroup* procgroup, struct reschedule_ctx
|
||||
|
||||
free (procgroup->tls.tls_tmpl);
|
||||
|
||||
id_alloc_fini (&procgroup->vfs_handle_id_alloc);
|
||||
id_alloc_fini (&procgroup->rid_alloc);
|
||||
id_free (&pgid_alloc, procgroup->pgid);
|
||||
|
||||
|
||||
@@ -36,8 +36,6 @@ struct procgroup {
|
||||
uintptr_t map_base;
|
||||
struct procgroup_tls tls;
|
||||
uint64_t capabilities;
|
||||
struct rb_node_link* vfs_handle_tree;
|
||||
struct id_alloc vfs_handle_id_alloc;
|
||||
};
|
||||
|
||||
struct procgroup* procgroup_create (void);
|
||||
|
||||
Reference in New Issue
Block a user