/* * 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 #include #include #include /* 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; }