hos/kernel/fs/vfs.cpp

102 lines
1.9 KiB
C++

// 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 "ext2.h"
#include "lang/vector.h"
#include "lang/string.h"
#include "devices.h"
inode_num_t rootInode;
vector<VFSMount> *mountPoints;
int vfs_init()
{
mountPoints = new vector<VFSMount>;
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;
}
VFSMount::VFSMount(device_t dev, FileSystem *fs, string mountPoint, inode_num_t mountInode)
{
myDev = dev;
myFS = fs;
myRefs = 0;
myMountPoint = mountPoint;
myMountInode = mountInode;
}
VFSMount::~VFSMount()
{
if (myFS)
{
delete myFS;
if (myRefs)
kprintf("Filesystem uncleanly mounted from %s\n", myMountPoint.data());
}
}
FileSystem::FileSystem() {myError = -10278;}
FileSystem::~FileSystem() {}
u32_t FileSystem::totalBlocks(){return 0;}
u32_t FileSystem::usedBlocks(){return 0;};
u32_t FileSystem::freeBlocks(){return 0;};
u32_t FileSystem::totalInodes(){return 0;};
u32_t FileSystem::usedInodes(){return 0;};
u32_t FileSystem::freeInodes(){return 0;};
u32_t FileSystem::getRootInodeNumber(){return 0;};
int FileSystem::check(){return myError;};