Nucleus
Barry File system namespace b085b26 (3 years, 3 months ago)
diff --git a/include/nucleus/task.h b/include/nucleus/task.h
index 3548782..397fae7 100644
--- a/include/nucleus/task.h
+++ b/include/nucleus/task.h
@@ -6,6 +6,7 @@
#include <nucleus/cpu.h>
#include <nucleus/object.h>
#include <nucleus/memory.h>
+#include <nucleus/vfs.h>
typedef struct Task Task;
@@ -35,6 +36,9 @@ struct Task {
uintptr_t esp, ebp, eip;
page_dir_t pageDir;
+
+ /* Namespaces */
+ FileSystem *fs;
};
extern ObjectType taskType;
diff --git a/include/nucleus/vfs.h b/include/nucleus/vfs.h
index 2439151..19793bb 100644
--- a/include/nucleus/vfs.h
+++ b/include/nucleus/vfs.h
@@ -7,6 +7,7 @@
#include <nucleus/memory.h>
typedef struct FSType FSType;
+typedef struct FileSystem FileSystem;
typedef struct Inode Inode;
typedef struct InodeOps InodeOps;
@@ -31,6 +32,7 @@ struct InodeOps {
};
extern ObjectType fstypeType;
+extern ObjectType fsType;
extern ObjectType inodeType;
void init_vfs(void);
diff --git a/task/clone.c b/task/clone.c
index 41cbc48..86cf440 100644
--- a/task/clone.c
+++ b/task/clone.c
@@ -4,7 +4,9 @@
*/
#include <sys/types.h>
+#include <sys/sched.h>
#include <nucleus/task.h>
+#include <nucleus/vfs.h>
extern ObjectList *readyQueue[];
@@ -17,6 +19,12 @@ clone(int flags)
Task *parent = current, *child = new(&taskType), *tmp;
pid_t tid = 0;
+ /* Clone parent's file system namespace */
+ if (flags & CLONE_FS)
+ child->fs = get(parent->fs);
+ else
+ child->fs = copy(parent->fs);
+
/* After this, anything on the stack is desynchronised */
child->pageDir = clone_dir();
diff --git a/task/task.c b/task/task.c
index 7026698..87c0c79 100644
--- a/task/task.c
+++ b/task/task.c
@@ -77,6 +77,10 @@ init_tasking(void)
asm volatile("mov %%cr3, %0" : "=r" (current->pageDir));
current->state = RUNNING;
+ /* File System namespace */
+ current->fs = new(&fsType);
+
init_scheduler();
register_interrupt(0, timer_handler);
+
}
diff --git a/vfs/namespace.c b/vfs/namespace.c
new file mode 100644
index 0000000..1cf7515
--- /dev/null
+++ b/vfs/namespace.c
@@ -0,0 +1,38 @@
+/*
+ * This file implements the File System object, which is the namespace for a
+ * task's files. It tracks a task's root and current working directory.
+ */
+
+#include <nucleus/object.h>
+#include <nucleus/vfs.h>
+#include "namespace.h"
+
+static void file_system_new(Object *);
+static void file_system_copy(Object *, Object *);
+
+/* File System object type */
+ObjectType fsType = {
+ .size = sizeof(FileSystem),
+ .new = file_system_new,
+ .copy = file_system_copy,
+};
+
+/* Create a new File System object */
+static void
+file_system_new(Object *obj)
+{
+ FileSystem *fs = (void *) obj;
+ fs->cwdPath = create_list(&dirEntryType);
+}
+
+/* Copy a File System object */
+static void
+file_system_copy(Object *a, Object *b)
+{
+ FileSystem *parent = (void *) a, *child = (void *) b;
+ child->cwd = get(parent->cwd);
+ /* init cwd custody chain */
+ child->cwdPath = copy_list(parent->cwdPath);
+ /* copy cwd custody chain */
+ child->root = get(parent->root);
+}
diff --git a/vfs/namespace.h b/vfs/namespace.h
new file mode 100644
index 0000000..e4c8a63
--- /dev/null
+++ b/vfs/namespace.h
@@ -0,0 +1,15 @@
+#ifndef VFS_NAMESPACE_H
+#define VFS_NAMESPACE_H
+
+#include <nucleus/object.h>
+#include <nucleus/vfs.h>
+
+/* Structure for a File System namespace */
+struct FileSystem {
+ Object obj;
+ Inode *cwd;
+ ObjectList *cwdPath;
+ Inode *root;
+};
+
+#endif