Virtual filesystem and ramdiskfs
All checks were successful
Build documentation / build-and-deploy (push) Successful in 27s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 27s
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <aux/compiler.h>
|
||||
#include <aux/elf.h>
|
||||
#include <fs/vfs.h>
|
||||
#include <irq/irq.h>
|
||||
#include <libk/align.h>
|
||||
#include <libk/list.h>
|
||||
@@ -7,12 +8,12 @@
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <limine/requests.h>
|
||||
#include <m/fs_desc_buffer.h>
|
||||
#include <mm/liballoc.h>
|
||||
#include <mm/pmm.h>
|
||||
#include <proc/proc.h>
|
||||
#include <proc/procgroup.h>
|
||||
#include <proc/resource.h>
|
||||
#include <rd/rd.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/debug.h>
|
||||
#include <sys/mm.h>
|
||||
@@ -100,17 +101,38 @@ struct elf_aux proc_load_segments (struct proc* proc, uint8_t* elf) {
|
||||
return aux;
|
||||
}
|
||||
|
||||
struct proc* proc_spawn_rd (char* name) {
|
||||
struct rd_file* rd_file = rd_get_file (name);
|
||||
struct proc* proc_from_file (const char* mountpoint, const char* path) {
|
||||
struct fs_desc_buffer desc;
|
||||
|
||||
bool ok = proc_check_elf (rd_file->content);
|
||||
|
||||
DEBUG ("Spawning %s, elf header %s\n", name, ok ? "ok" : "bad");
|
||||
|
||||
if (!ok)
|
||||
if (vfs_describe (mountpoint, path, &desc) != VFS_OK)
|
||||
return NULL;
|
||||
|
||||
return proc_from_elf (rd_file->content);
|
||||
if (desc.type != FS_FILE)
|
||||
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) != VFS_OK) {
|
||||
free (temp_buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool ok = proc_check_elf (temp_buffer);
|
||||
|
||||
DEBUG ("Spawning %s:%s, elf header %s\n", mountpoint, path, ok ? "ok" : "bad");
|
||||
|
||||
if (!ok) {
|
||||
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) {
|
||||
@@ -275,11 +297,11 @@ void proc_init (void) {
|
||||
irq_attach (&proc_irq_sched, NULL, CPU_REQUEST_SCHED);
|
||||
#endif
|
||||
|
||||
struct proc* spin_proc = proc_spawn_rd ("spin.exe");
|
||||
struct proc* spin_proc = proc_from_file ("ramdisk", "/spin.exe");
|
||||
struct cpu* spin_cpu = thiscpu;
|
||||
proc_register (spin_proc, &spin_cpu);
|
||||
|
||||
struct proc* init = proc_spawn_rd ("init.exe");
|
||||
struct proc* init = proc_from_file ("ramdisk", "/init.exe");
|
||||
struct cpu* init_cpu = thiscpu;
|
||||
proc_register (init, &init_cpu);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user