// vfs.cpp // Virtual file system subsystem for HOS // Author: Josh Holtrop // Date: 05/10/05 // Modified: 05/10/05 #define _HOS_CPP_ _HOS_CPP_ extern "C" { #include "hos_defines.h" #include "display/kout.h" } #include "vfs.h" #include "fs/FileSystem.h" #include "fs/VFSMount.h" #include "fs/ext2/ext2.h" #include "lang/vector.h" #include "lang/string.h" #include "devices.h" inode_num_t rootInode; vector *mountPoints; int vfs_init() { mountPoints = new vector; return 0; } int vfs_mount(device_t device, int fsType, char *mountPoint) { string mountPt(mountPoint); if (mountPt == "/") { if (mountPoints->size()) { kprintf("/ must be the first filesystem mounted!\n"); return -1; } FileSystem *fs = vfs_attempt_mount(device, fsType); if (fs == NULL) return -2; rootInode = fs->getRootInodeNumber(); mountPoints->add(VFSMount(device, fs, mountPt, 0)); return 0; } else { } return 500; } FileSystem *vfs_attempt_mount(device_t device, int fsType) { FileSystem *fs; switch (fsType) { case FS_EXT2: fs = new Ext2fs(device); break; default: return NULL; } if (fs->check()) { delete fs; return NULL; } return fs; }