Skip to content

Commit 72f9068

Browse files
author
Diego Ferrari
committed
[PROC] reuse open files
1 parent 1661720 commit 72f9068

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

kernel/process/scheduler.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,22 @@ size_t list_processes(const char *path, void *buf, size_t size, file_offset *off
307307
}
308308

309309
FS_RESULT open_proc(const char *path, file *descriptor){
310-
const char *fullpath = path;
310+
uint64_t fid = reserve_fd_gid(path);
311+
module_file *mfile = (module_file*)chashmap_get(proc_opened_files, &fid, sizeof(uint64_t));
312+
if (mfile){
313+
descriptor->id = mfile->fid;
314+
descriptor->size = mfile->file_size;
315+
mfile->references++;
316+
return FS_RESULT_SUCCESS;
317+
}
311318
const char *pid_s = seek_to(path, '/');
312319
path = seek_to(pid_s, '/');
313320
uint64_t pid = parse_int_u64(pid_s, path - pid_s);
314321
process_t *proc = get_proc_by_pid(pid);
315-
descriptor->id = reserve_fd_gid(fullpath);
322+
descriptor->id = fid;
316323
descriptor->cursor = 0;
317324
module_file *file = kalloc(proc_page, sizeof(module_file), ALIGN_64B, MEM_PRIV_KERNEL);
318-
file->fid = descriptor->id;
325+
file->fid = fid;
319326
if (strcmp_case(path, "out",true) == 0){
320327
descriptor->size = proc->output_size;
321328
file->buffer = proc->output;

0 commit comments

Comments
 (0)