100 lines
1.8 KiB
C++
100 lines
1.8 KiB
C++
// ext2.cpp
|
|
// ext2 filesystem driver for HOS
|
|
// Author: Josh Holtrop
|
|
// Date: 05/10/05
|
|
// Modified: 05/10/05
|
|
|
|
#define _HOS_CPP_ _HOS_CPP_
|
|
|
|
extern "C" {
|
|
#include "display/kout.h"
|
|
#include "mm/vmm.h"
|
|
#include "lang/lang.h"
|
|
}
|
|
|
|
#include "ext2.h"
|
|
#include "Ext2OpenDirectory.h"
|
|
#include "Ext2OpenFile.h"
|
|
|
|
int ext2_init()
|
|
{
|
|
vfs_register("ext2", ext2__mount_func);
|
|
return 0;
|
|
}
|
|
|
|
FileSystem *ext2__mount_func(device_t dev)
|
|
{
|
|
ext2_super_block_t *super =
|
|
(ext2_super_block_t *) New(ext2_super_block_t);
|
|
if ( (block_read(DEV_MAJOR(dev), DEV_MINOR(dev), 2, 2, super) < 1024)
|
|
|| (super->s_magic != EXT2_MAGIC) )
|
|
{
|
|
kfree(super);
|
|
return NULL;
|
|
}
|
|
Ext2fs *fs = new Ext2fs(super, dev);
|
|
kfree(super);
|
|
return fs;
|
|
}
|
|
|
|
Ext2fs::Ext2fs(ext2_super_block_t *super, device_t dev)
|
|
{
|
|
myDevice = dev;
|
|
memcpy(&mySuper, super, sizeof(ext2_super_block_t));
|
|
mySuperDirty = 0;
|
|
kprintf("Blocks: %d (%d free), Inodes: %d (%d free) Creator OS:\n",
|
|
mySuper.s_blocks_count,
|
|
mySuper.s_free_blocks_count,
|
|
mySuper.s_inodes_count,
|
|
mySuper.s_free_inodes_count,
|
|
mySuper.s_creator_os);
|
|
|
|
}
|
|
|
|
Ext2fs::~Ext2fs()
|
|
{
|
|
if (mySuperDirty)
|
|
block_write(DEV_MAJOR(myDevice), DEV_MINOR(myDevice), 2, 2, &mySuper);
|
|
}
|
|
|
|
u32_t Ext2fs::totalBlocks()
|
|
{
|
|
return mySuper.s_blocks_count << (mySuper.s_log_block_size + 1);
|
|
}
|
|
|
|
u32_t Ext2fs::freeBlocks()
|
|
{
|
|
return mySuper.s_free_blocks_count << (mySuper.s_log_block_size + 1);
|
|
}
|
|
|
|
u32_t Ext2fs::totalInodes()
|
|
{
|
|
return mySuper.s_inodes_count;
|
|
}
|
|
|
|
u32_t Ext2fs::freeInodes()
|
|
{
|
|
return mySuper.s_free_inodes_count;
|
|
}
|
|
|
|
/* ext2 filesystems always have a root-directory inode number of 2 */
|
|
u32_t Ext2fs::getRootInodeNumber()
|
|
{
|
|
return 2;
|
|
}
|
|
|
|
OpenDirectory *Ext2fs::openDirectory(u32_t inum)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
OpenFile *Ext2fs::openFile(u32_t inum)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
int Ext2fs::stat(u32_t inum, vfs_stat_t *buf)
|
|
{
|
|
return -1;
|
|
}
|