BarryServer : Git

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

// Related

Nucleus

Barry File system type object 4f75471 (3 years, 3 months ago)
diff --git a/vfs/fstype.c b/vfs/fstype.c
new file mode 100644
index 0000000..73d28c8
--- /dev/null
+++ b/vfs/fstype.c
@@ -0,0 +1,65 @@
+/*
+ * This file implements the FSType object.  Objects of this type represent
+ * different file-system types (e.g. ext2fs, tmpfs).  They exist to be iterated
+ * by the VFS to keep track of the installed file systems.
+ */
+
+#include <string.h>
+#include <errno.h>
+#include <nucleus/object.h>
+#include <nucleus/vfs.h>
+
+/* Structure for a File System Type */
+struct FSType {
+	const char *name;
+	Inode *(*mount)(FSType *, int, const char *, void *);
+};
+
+/* Find callback data */
+struct FindData {
+	const char *name;
+	FSType *result;
+};
+
+/* File System Type object type */
+ObjectType fstypeType = {
+	.size = sizeof(FSType),
+};
+
+/* Callback for finding a file system type */
+static int
+compare_fstype_name(void *object, void *data)
+{
+	FSType *type = object;
+	struct FindData *find = data;
+	if (!strcmp(type->name, find->name)) {
+		find->result = type;
+		return 1;
+	}
+	return 0;
+}
+
+/* Create a new file system type */
+void
+register_fstype(const char *name, mount_callback_t mount)
+{
+	FSType *fstype = new(&fstypeType);
+	fstype->name = name;
+	fstype->mount = mount;
+}
+
+/* Mount file system type by name */
+int
+mount_fstype(const char *name, int flags, const char *src, void *data,
+             Inode **root)
+{
+	struct FindData find = {
+		.name = name,
+		.result = NULL,
+	};
+	iterate(fstypeType.objects, compare_fstype_name, &find);
+	if (!find.result)
+		return -ENODEV;
+	*root = find.result->mount(find.result, flags, src, data);
+	return 0;
+}