#include #include #include #include #include #include #include "ext2fs.h" Inode *ext2fs_alloc_inode(SuperBlock *sb); const uint16_t EXT2_SIGNATURE = 0xEF53; SuperOps ext2fsSuperOps = { .alloc_inode = ext2fs_alloc_inode, }; /* Mount an ext2fs instance */ Inode * ext2fs_mount(FSType *type, int flags, const char *dev, void *data) { /* Open backing file */ int fd = open(dev, O_RDONLY); if (fd < 0) return (void *) fd; File *back = get(get_file_by_fd(fd)); close(fd); if (!S_ISBLK(back->inode->mode)) { put(back); return (void *) -ENOTBLK; } /* Read super block */ struct Ext2Super *rsuper = kmalloc(sizeof(struct Ext2Super)); back->pos = 1024; file_read(back, (char *) rsuper, sizeof(struct Ext2Super)); if (rsuper->signature != EXT2_SIGNATURE) goto error; if (rsuper->requiredFeatures & 0x01) /* Compression required */ goto error; if ((rsuper->writableFeatures & 0x02) && !(flags & MS_RDONLY)) /* 64-bit file system */ goto error; SuperBlock *super = new(&superBlockType); super->type = get(type); super->ops = &ext2fsSuperOps; super->back = back; super->data = rsuper; super->root = new(&inodeType); ext2fs_read_vnode(super, 2, super->root); return super->root; error: put(back); kfree(rsuper); return (void *) -EINVAL; } /* Allocate an inode */ Inode * ext2fs_alloc_inode(SuperBlock *sb) { return NULL; }