BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / blob / acd091571545e40dc85fc691d9d0b12cf4d363ee / vfs / fstype.c

// Related

Nucleus

Barry FS Object wrapper functions 77a8df8 (3 years, 3 months ago)
/*
 * 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 {
	Object obj;
	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 = {
	.name = "FILE SYSTEM TYPE",
	.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;
}