Implement VFS syscalls
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m29s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m29s
This commit is contained in:
@@ -103,25 +103,38 @@ struct elf_aux proc_load_segments (struct proc* proc, uint8_t* elf) {
|
||||
return aux;
|
||||
}
|
||||
|
||||
struct proc* proc_from_file (const char* mountpoint, const char* path) {
|
||||
struct proc* proc_from_file (struct procgroup* procgroup, const char* mountpoint,
|
||||
const char* path) {
|
||||
struct fs_desc_buffer desc;
|
||||
|
||||
if (vfs_describe (mountpoint, path, &desc) != ST_OK)
|
||||
if (vfs_open (procgroup, mountpoint, path) != ST_OK)
|
||||
return NULL;
|
||||
|
||||
if (desc.type != FS_FILE)
|
||||
if (vfs_describe (procgroup, mountpoint, path, &desc) != ST_OK) {
|
||||
vfs_close (procgroup, mountpoint, path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (desc.type != FS_FILE) {
|
||||
vfs_close (procgroup, mountpoint, path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t* temp_buffer = malloc (desc.size);
|
||||
|
||||
if (temp_buffer == NULL)
|
||||
return NULL;
|
||||
|
||||
if (vfs_read (mountpoint, path, temp_buffer, 0, desc.size) != ST_OK) {
|
||||
free (temp_buffer);
|
||||
if (temp_buffer == NULL) {
|
||||
vfs_close (procgroup, mountpoint, path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (vfs_read (procgroup, mountpoint, path, temp_buffer, 0, desc.size) != ST_OK) {
|
||||
free (temp_buffer);
|
||||
vfs_close (procgroup, mountpoint, path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vfs_close (procgroup, mountpoint, path);
|
||||
|
||||
bool ok = proc_check_elf (temp_buffer);
|
||||
|
||||
DEBUG ("Spawning %s:%s, elf header %s\n", mountpoint, path, ok ? "ok" : "bad");
|
||||
@@ -300,11 +313,11 @@ void proc_init (void) {
|
||||
irq_attach (&proc_irq_sched, NULL, CPU_REQUEST_SCHED);
|
||||
#endif
|
||||
|
||||
struct proc* spin_proc = proc_from_file ("ramdisk", "/spin");
|
||||
struct proc* spin_proc = proc_from_file (NULL, "ramdisk", "/spin");
|
||||
struct cpu* spin_cpu = thiscpu;
|
||||
proc_register (spin_proc, &spin_cpu);
|
||||
|
||||
struct proc* init = proc_from_file ("ramdisk", "/init");
|
||||
struct proc* init = proc_from_file (NULL, "ramdisk", "/init");
|
||||
init->procgroup->capabilities |= (PROC_CAP_TERMINAL | PROC_CAP_KB);
|
||||
struct cpu* init_cpu = thiscpu;
|
||||
proc_register (init, &init_cpu);
|
||||
|
||||
@@ -51,7 +51,7 @@ bool proc_kill (struct proc* proc, struct cpu** reschedule_cpu);
|
||||
struct elf_aux proc_load_segments (struct proc* proc, uint8_t* elf);
|
||||
bool proc_register (struct proc* proc, struct cpu** reschedule_cpu);
|
||||
struct proc* proc_find_pid (int pid);
|
||||
struct proc* proc_from_file (const char* mountpoint, const char* path);
|
||||
struct proc* proc_from_file (struct procgroup* procgroup, const char* mountpoint, const char* path);
|
||||
void proc_init (void);
|
||||
|
||||
#endif // _KERNEL_PROC_PROC_H
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <fs/vfs.h>
|
||||
#include <libk/rbtree.h>
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
@@ -195,6 +196,10 @@ void procgroup_detach (struct procgroup* procgroup, struct proc* proc) {
|
||||
proc_delete_resource (resource, &reschedule_cpu);
|
||||
}
|
||||
|
||||
/* 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) {
|
||||
struct proc_mapping* mapping =
|
||||
|
||||
Reference in New Issue
Block a user