Nucleus
Barry File system namespace b085b26 (3 years, 3 months ago)
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