Orion
Barry Importing existing Orion kernel d41a53c (2 years, 4 months ago)/* * This file controls the superblock for ProcFS. It supports mounting new ProcFS * filesystems. The VFS will use the calls here when dealing directly with the * filesystem structure. */ #include <stdint.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include "fs.h" #include "../vfs.h" #include "../super.h" #include "../inode.h" #include "../../mem/heap.h" Inode *procfs_mount(FileSystemType *type, int flags, const char *dev, void *data); Inode *procfs_alloc_inode(SuperBlock *sb); FileSystemType procfsType = { .name = "ProcFS", .mount = procfs_mount, // .kill_sb = procfs_kill_sb, }; SuperOps procfsSuperOps = { .alloc_inode = procfs_alloc_inode, // .free_inode = procfs_free_inode, // .write_inode = procfs_write_inode, // .delete_inode = procfs_delete_inode, }; Inode procfsRoot = { .mode = S_IFDIR | 0755, .ops = &procfsInodeOps, .fileOps = &procfsFileOps, .size = 4096, }; /* Mount a ProcFS instance */ Inode * procfs_mount(FileSystemType *type, int flags, const char *dev, void *data) { if (type != &procfsType) return NULL; SuperBlock *super = kmalloc(sizeof(SuperBlock)); super->type = type; super->ops = &procfsSuperOps; init_lock(&super->lock); Inode *inode = &procfsRoot; inode->nlink++; inode->super = super; /* FIXME: need an inode per super, or only one super */ super->root = inode; /* Never free */ if (!inode->usage) inode_get(inode); return inode; } /* Allocate an inode */ Inode * procfs_alloc_inode(SuperBlock *sb) { Inode *inode = kmalloc(sizeof(Inode)); init_lock(&inode->lock); inode->ops = &procfsInodeOps; inode->fileOps = &procfsFileOps; inode->super = sb; inode->nlink = 1; return inode_get(inode); /* This ensures that the inode is never free */ }