Redesign VFS around handles
This commit is contained in:
@@ -108,47 +108,73 @@ struct proc* proc_from_file (struct procgroup* procgroup, const char* mountpoint
|
||||
const char* path) {
|
||||
struct desc desc;
|
||||
|
||||
if (vfs_open (procgroup, mountpoint, path) != ST_OK)
|
||||
return NULL;
|
||||
if (procgroup == NULL) {
|
||||
if (vfs_kernel_describe (mountpoint, path, &desc) < 0)
|
||||
return NULL;
|
||||
|
||||
if (vfs_describe (procgroup, mountpoint, path, &desc) != ST_OK) {
|
||||
vfs_close (procgroup, mountpoint, path);
|
||||
return NULL;
|
||||
}
|
||||
if (desc.type != FS_FILE)
|
||||
return NULL;
|
||||
|
||||
if (desc.type != FS_FILE) {
|
||||
vfs_close (procgroup, mountpoint, path);
|
||||
return NULL;
|
||||
}
|
||||
uint8_t* temp_buffer = malloc (desc.size);
|
||||
|
||||
uint8_t* temp_buffer = malloc (desc.size);
|
||||
if (temp_buffer == NULL)
|
||||
return NULL;
|
||||
|
||||
if (temp_buffer == NULL) {
|
||||
vfs_close (procgroup, mountpoint, path);
|
||||
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);
|
||||
|
||||
if (vfs_read (procgroup, mountpoint, path, temp_buffer, 0, desc.size) != ST_OK) {
|
||||
free (temp_buffer);
|
||||
vfs_close (procgroup, mountpoint, path);
|
||||
return NULL;
|
||||
}
|
||||
return proc;
|
||||
} else {
|
||||
int handle = vfs_open (procgroup, mountpoint, path);
|
||||
|
||||
vfs_close (procgroup, mountpoint, path);
|
||||
if (handle < 0)
|
||||
return NULL;
|
||||
|
||||
bool ok = proc_check_elf (temp_buffer);
|
||||
if (vfs_describe (procgroup, handle, &desc) != ST_OK) {
|
||||
vfs_close (procgroup, handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DEBUG ("Spawning %s:%s, elf header %s\n", mountpoint, path, ok ? "ok" : "bad");
|
||||
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);
|
||||
|
||||
if (!ok) {
|
||||
free (temp_buffer);
|
||||
return NULL;
|
||||
return proc;
|
||||
}
|
||||
|
||||
struct proc* proc = proc_from_elf (temp_buffer);
|
||||
|
||||
free (temp_buffer);
|
||||
return proc;
|
||||
}
|
||||
|
||||
struct proc* proc_find_pid (int pid) {
|
||||
|
||||
Reference in New Issue
Block a user