BarryServer : Git

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

// Related

Nucleus

Barry System headers (remove libc dependency) 18495cf (3 years, 2 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 <sys/errno.h>
#include <nucleus/lib.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 *);
};

/* File System Type object type */
ObjectType fstypeType = {
	.name = "FILE SYSTEM TYPE",
	.size = sizeof(FSType),
};

/* 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)
{
	FSType *type;
	foreach (fstypeType.objects, type) {
		if (!strcmp(type->name, name))
			break;
	}
	if (!type)
		return -ENODEV;
	*root = type->mount(type, flags, src, data);
	return 0;
}