/* * This file controls the superblock for TmpFS. It supports mounting new TmpFS * filesystems. The VFS will use the calls here when dealing directly with the * filesystem structure. */ #include #include #include #include #include "fs.h" #include "../vfs.h" #include "../super.h" #include "../inode.h" #include "../../mem/heap.h" Inode *tmpfs_mount(FileSystemType *type, int flags, const char *dev, void *data); Inode *tmpfs_alloc_inode(SuperBlock *sb); FileSystemType tmpfsType = { .name = "TmpFS", .mount = tmpfs_mount, // .kill_sb = tmpfs_kill_sb, }; SuperOps tmpfsSuperOps = { .alloc_inode = tmpfs_alloc_inode, // .free_inode = tmpfs_free_inode, // .write_inode = tmpfs_write_inode, // .delete_inode = tmpfs_delete_inode, }; /* Mount a TmpFS instance */ Inode * tmpfs_mount(FileSystemType *type, int flags, const char *dev, void *data) { if (type != &tmpfsType) return NULL; SuperBlock *super = kmalloc(sizeof(SuperBlock)); super->type = type; super->ops = &tmpfsSuperOps; init_lock(&super->lock); Inode *inode = super_alloc_inode(super); inode->mode = S_IFDIR | 0755; super->root = inode; return inode; } /* Allocate an inode */ Inode * tmpfs_alloc_inode(SuperBlock *sb) { Inode *inode = kmalloc(sizeof(Inode)); init_lock(&inode->lock); inode->ops = &tmpfsInodeOps; inode->fileOps = &tmpfsFileOps; inode->super = sb; inode->nlink = 1; return inode_get(inode); /* This ensures that the inode is never free */ }