Orion
Barry Importing existing Orion kernel d41a53c (3 years, 3 months ago)
diff --git a/vfs/tmpfs/super.c b/vfs/tmpfs/super.c
new file mode 100644
index 0000000..ede1961
--- /dev/null
+++ b/vfs/tmpfs/super.c
@@ -0,0 +1,65 @@
+/*
+ * This file controls the superblock for TmpFS. It supports mounting new TmpFS
+ * filesystems. The VFS will use the calls here when dealing directly with the
+ * filesystem structure.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include "fs.h"
+#include "../vfs.h"
+#include "../super.h"
+#include "../inode.h"
+#include "../../mem/heap.h"
+
+Inode *tmpfs_mount(FileSystemType *type, int flags,
+ const char *dev, void *data);
+Inode *tmpfs_alloc_inode(SuperBlock *sb);
+
+FileSystemType tmpfsType = {
+ .name = "TmpFS",
+ .mount = tmpfs_mount,
+// .kill_sb = tmpfs_kill_sb,
+};
+
+SuperOps tmpfsSuperOps = {
+ .alloc_inode = tmpfs_alloc_inode,
+// .free_inode = tmpfs_free_inode,
+// .write_inode = tmpfs_write_inode,
+// .delete_inode = tmpfs_delete_inode,
+};
+
+/* Mount a TmpFS instance */
+Inode *
+tmpfs_mount(FileSystemType *type, int flags, const char *dev, void *data)
+{
+ if (type != &tmpfsType)
+ return NULL;
+
+ SuperBlock *super = kmalloc(sizeof(SuperBlock));
+
+ super->type = type;
+ super->ops = &tmpfsSuperOps;
+ init_lock(&super->lock);
+
+ Inode *inode = super_alloc_inode(super);
+ inode->mode = S_IFDIR | 0755;
+ super->root = inode;
+
+ return inode;
+}
+
+/* Allocate an inode */
+Inode *
+tmpfs_alloc_inode(SuperBlock *sb)
+{
+ Inode *inode = kmalloc(sizeof(Inode));
+ init_lock(&inode->lock);
+ inode->ops = &tmpfsInodeOps;
+ inode->fileOps = &tmpfsFileOps;
+ inode->super = sb;
+ inode->nlink = 1;
+ return inode_get(inode); /* This ensures that the inode is never free */
+}