Orion
Barry Importing existing Orion kernel d41a53c (2 years, 4 months ago)diff --git a/vfs/ext2fs/super.c b/vfs/ext2fs/super.c new file mode 100644 index 0000000..98ca800 --- /dev/null +++ b/vfs/ext2fs/super.c @@ -0,0 +1,89 @@ +/* + * This file controls the superblock for Ext2FS. It supports mounting new + * Ext2FS filesystems. The VFS will use the calls here when dealing directly + * with the filesystem structure. + */ + +#include <stdint.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <sys/mount.h> +#include "fs.h" +#include "../vfs.h" +#include "../inode.h" +#include "../super.h" +#include "../../mem/heap.h" +#include "../../task/task.h" +#include "../../screen.h" + +Inode *ext2fs_mount(FileSystemType *type, int flags, + const char *dev, void *data); +Inode *ext2fs_alloc_inode(SuperBlock *sb); + +FileSystemType ext2fsType = { + .name = "Ext2FS", + .mount = ext2fs_mount, +}; + +SuperOps ext2fsSuperOps = { + .alloc_inode = ext2fs_alloc_inode, +}; + +/* Mount a Ext2FS instance */ +Inode * +ext2fs_mount(FileSystemType *type, int flags, const char *dev, void *data) +{ + if (type != &ext2fsType) + return NULL; + + int fd = open(dev, O_RDONLY); + if (fd < 0) + return (void *) fd; + File *back = file_get(current->files->fd[fd]); + close(fd); + if (!S_ISBLK(back->mode)) { + file_put(back); + return (void *) -ENOTBLK; + } + + Ext2Super *rsuper = kmalloc(sizeof(Ext2Super)); + back->pos = 1024; + file_read(back, (char *) rsuper, sizeof(Ext2Super)); + if (rsuper->signature != 0xEF53) { + kprintf("Error while mounting %s: Not an Ext2FS drive", dev); + file_put(back); + kfree(rsuper); + return (void *) -EINVAL; + } + if (rsuper->requiredFeatures & 0x01) { + kprintf("Cannot mount %s: Compression required", dev); + file_put(back); + kfree(rsuper); + return (void *) -EINVAL; + } + if ((rsuper->writableFeatures & 0x02) && !(flags & MS_RDONLY)) { + kprintf("Cannot mount %s: 64-bit File System required", dev); + file_put(back); + kfree(rsuper); + return (void *) -EINVAL; + } + + SuperBlock *super = kmalloc(sizeof(SuperBlock)); + super->type = type; + super->ops = &ext2fsSuperOps; + init_lock(&super->lock); + super->back = back; + super->data = rsuper; + super->root = kmalloc(sizeof(Inode)); + ext2_read_vnode(super, 2, super->root); + + return super->root; +} + +/* Allocate an inode */ +Inode * +ext2fs_alloc_inode(SuperBlock *sb) +{ + return NULL; +}