BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / f9d84303bd9a7535d1313e1dd7d79258841ec3e4 / vfs

// Related

Nucleus

Barry Super block object f9d8430 (3 years, 3 months ago)
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;
+}