Nucleus
Barry Super block object f9d8430 (3 years, 3 months ago)
diff --git a/include/nucleus/vfs.h b/include/nucleus/vfs.h
index 8ac8613..df3be93 100644
--- a/include/nucleus/vfs.h
+++ b/include/nucleus/vfs.h
@@ -8,11 +8,28 @@
typedef struct FSType FSType;
typedef struct FileSystem FileSystem;
+typedef struct SuperBlock SuperBlock;
+typedef struct SuperOps SuperOps;
typedef struct Inode Inode;
typedef struct InodeOps InodeOps;
typedef Inode *(*mount_callback_t)(FSType *, int, const char *, void *);
+/* Structure for a Super Block */
+struct SuperBlock {
+ Object obj;
+ FSType *type;
+ SuperOps *ops;
+ Inode *root;
+ ObjectList *inodes; /* List of cached inodes */
+ void *data;
+};
+struct SuperOps {
+ Inode *(*alloc_inode)(SuperBlock *);
+ int (*write_inode)(Inode *);
+ void (*delete_inode)(Inode *);
+};
+
/* Structure for an Inode */
struct Inode {
Object obj;
@@ -24,6 +41,7 @@ struct Inode {
size_t size;
dev_t dev;
InodeOps *ops;
+ SuperBlock *super;
union {
ObjectList *pages;
};
diff --git a/vfs/superblock.c b/vfs/superblock.c
new file mode 100644
index 0000000..237f723
--- /dev/null
+++ b/vfs/superblock.c
@@ -0,0 +1,55 @@
+/*
+ * This file implements the Super Block object and associated functions. Most
+ * of the functions here are just wrappers for the Super Block Operations that
+ * get specified by the individual file systems, since most of them need to know
+ * driver-specific values. There usually isn't a generic way to handle these
+ * operations.
+ */
+
+#include <sys/types.h>
+#include <nucleus/vfs.h>
+
+/* Data for find callback */
+struct FindData {
+ ino_t ino;
+ Inode *result;
+};
+
+ObjectType superBlockType = {
+ .size = sizeof(SuperBlock),
+};
+
+/* Find an Inode by ino value */
+int
+compare_inode_ino(void *addr, void *data)
+{
+ Inode *inode = addr;
+ struct FindData *find = data;
+ if (find->ino == inode->ino){
+ find->result = get(inode);
+ return 1;
+ }
+ return 0;
+}
+
+/* Allocate an Inode */
+Inode *
+super_alloc_inode(SuperBlock *sb)
+{
+ if (!sb->ops || !sb->ops->alloc_inode)
+ return NULL;
+ return sb->ops->alloc_inode(sb);
+}
+
+/* Search for an Inode in a Super Block's Inode list */
+Inode *
+super_find_inode(SuperBlock *sb, ino_t ino)
+{
+ Inode *inode;
+ struct FindData find = {
+ .ino = ino,
+ .result = NULL,
+ };
+ iterate(sb->inodes, compare_inode_ino, &find);
+ return find.result;
+}