summaryrefslogtreecommitdiff
path: root/src/kernel/proc/proc.cc
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-01-02 00:47:16 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-01-02 00:58:45 +0800
commitd8eaa13f2efc1eeca4e5f230d5a2d535aaf27338 (patch)
tree6ca02e2a2d1b1121620431059e322724a3c94a33 /src/kernel/proc/proc.cc
parent2dde56422dcfb94affee2baffc8d240ad16ad4b2 (diff)
downloadlume-d8eaa13f2efc1eeca4e5f230d5a2d535aaf27338.tar.gz
lume-d8eaa13f2efc1eeca4e5f230d5a2d535aaf27338.tar.xz
dev(file-system): establish VFS and Read-only FAT32 File System
Diffstat (limited to 'src/kernel/proc/proc.cc')
-rw-r--r--src/kernel/proc/proc.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/kernel/proc/proc.cc b/src/kernel/proc/proc.cc
index c8b6d1d..f1f1c1d 100644
--- a/src/kernel/proc/proc.cc
+++ b/src/kernel/proc/proc.cc
@@ -8,6 +8,8 @@
#include "kernel/trap.h"
#include "kernel/riscv.h"
#include "drivers/uart.h"
+#include "fs/fs.h"
+#include "fs/file.h"
#include "lib/string.h"
#define NPROC 64
@@ -172,6 +174,9 @@ found:
p->pid = nextpid++;
p->priority = 0;
p->cpu = mycpu();
+ p->cwd = nullptr;
+ for (int i = 0; i < NOFILE; i++)
+ p->ofile[i] = nullptr;
if ((p->tf = (struct Trapframe *)PMM::alloc_page()) == 0)
{
@@ -206,6 +211,19 @@ static void freeproc(struct Proc *p)
p->kstack = 0;
if (p->pagetable)
VM::uvmfree(p->pagetable, p->sz);
+ for (int i = 0; i < NOFILE; i++)
+ {
+ if (p->ofile[i])
+ {
+ FileTable::close(p->ofile[i]);
+ p->ofile[i] = nullptr;
+ }
+ }
+ if (p->cwd)
+ {
+ VFS::iput(p->cwd);
+ p->cwd = nullptr;
+ }
p->pagetable = 0;
p->sz = 0;
p->pid = 0;
@@ -245,6 +263,19 @@ int fork()
np->parent = p;
np->priority = p->priority;
+ for (int i = 0; i < NOFILE; i++)
+ {
+ if (p->ofile[i])
+ {
+ np->ofile[i] = FileTable::dup(p->ofile[i]);
+ }
+ }
+
+ if (p->cwd)
+ {
+ np->cwd = VFS::idup(p->cwd);
+ }
+
proc_mem_lock.release();
struct cpu *c = mycpu();
@@ -394,6 +425,8 @@ namespace ProcManager
p->sz = stack_va + PGSIZE;
strcpy(p->name, "initcode");
+ p->cwd = nullptr;
+
proc_mem_lock.release();
struct cpu *c = &cpus[0];