X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FFilesystems%2FExt2%2Fext2.c;h=971ef28ed538e185dc73c63c83289dce872727b4;hb=891868f0b4d64eb274b5810ac0c4f0a53d104114;hp=7c4bf973ae16656cce01b9d14c0f3ee3dd21ad72;hpb=51ab5f489bc356940c95cc936fd0508e8f07ea97;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/Filesystems/Ext2/ext2.c b/KernelLand/Modules/Filesystems/Ext2/ext2.c index 7c4bf973..971ef28e 100644 --- a/KernelLand/Modules/Filesystems/Ext2/ext2.c +++ b/KernelLand/Modules/Filesystems/Ext2/ext2.c @@ -1,14 +1,12 @@ /* - * Acess OS - * Ext2 Driver Version 1 + * Acess2 Ext2 Driver + * - By John Hodge (thePowersGang) + * + * ext2.c + * - Driver core */ -/** - * \file fs/ext2.c - * \brief Second Extended Filesystem Driver - * \todo Implement file full write support - */ -#define DEBUG 1 -#define VERBOSE 0 +#define DEBUG 0 +#define VERSION VER2(0,90) #include "ext2_common.h" #include @@ -17,22 +15,28 @@ extern tVFS_NodeType gExt2_DirType; // === PROTOTYPES === int Ext2_Install(char **Arguments); -// Interface Functions + int Ext2_Cleanup(void); +// - Interface Functions + int Ext2_Detect(int FD); tVFS_Node *Ext2_InitDevice(const char *Device, const char **Options); void Ext2_Unmount(tVFS_Node *Node); void Ext2_CloseFile(tVFS_Node *Node); -// Internal Helpers +// - Internal Helpers int Ext2_int_GetInode(tVFS_Node *Node, tExt2_Inode *Inode); Uint64 Ext2_int_GetBlockAddr(tExt2_Disk *Disk, Uint32 *Blocks, int BlockNum); Uint32 Ext2_int_AllocateInode(tExt2_Disk *Disk, Uint32 Parent); void Ext2_int_UpdateSuperblock(tExt2_Disk *Disk); // === SEMI-GLOBALS === -MODULE_DEFINE(0, 0x5B /*v0.90*/, FS_Ext2, Ext2_Install, NULL); +MODULE_DEFINE(0, VERSION, FS_Ext2, Ext2_Install, Ext2_Cleanup); tExt2_Disk gExt2_disks[6]; int giExt2_count = 0; tVFS_Driver gExt2_FSInfo = { - "ext2", 0, Ext2_InitDevice, Ext2_Unmount, NULL + .Name = "ext2", + .Detect = Ext2_Detect, + .InitDevice = Ext2_InitDevice, + .Unmount = Ext2_Unmount, + .GetNodeFromINode = NULL }; // === CODE === @@ -46,6 +50,39 @@ int Ext2_Install(char **Arguments) return MODULE_ERR_OK; } +/** + * \brief Clean up driver state before unload + */ +int Ext2_Cleanup(void) +{ + return 0; +} + +/** + * Detect if a volume is Ext2 formatted + */ +int Ext2_Detect(int FD) +{ + tExt2_SuperBlock sb; + size_t len; + + len = VFS_ReadAt(FD, 1024, 1024, &sb); + + if( len != 1024 ) { + Log_Debug("Ext2", "_Detect: Read failed? (0x%x != 1024)", len); + return 0; + } + + switch(sb.s_magic) + { + case 0xEF53: + return 2; + default: + Log_Debug("Ext2", "_Detect: s_magic = 0x%x", sb.s_magic); + return 0; + } +} + /** \brief Initializes a device to be read by by the driver \param Device String - Device to read from @@ -102,10 +139,11 @@ tVFS_Node *Ext2_InitDevice(const char *Device, const char **Options) disk->CacheID = Inode_GetHandle(); // Get Block Size - LOG("s_log_block_size = 0x%x", sb.s_log_block_size); disk->BlockSize = 1024 << sb.s_log_block_size; + LOG("Disk->BlockSie = 0x%x (1024 << %i)", disk->BlockSize, sb.s_log_block_size); // Read Group Information + LOG("sb,s_first_data_block = %x", sb.s_first_data_block); VFS_ReadAt( disk->FD, sb.s_first_data_block * disk->BlockSize + 1024, @@ -113,7 +151,6 @@ tVFS_Node *Ext2_InitDevice(const char *Device, const char **Options) disk->Groups ); - #if VERBOSE LOG("Block Group 0"); LOG(".bg_block_bitmap = 0x%x", disk->Groups[0].bg_block_bitmap); LOG(".bg_inode_bitmap = 0x%x", disk->Groups[0].bg_inode_bitmap); @@ -122,7 +159,6 @@ tVFS_Node *Ext2_InitDevice(const char *Device, const char **Options) LOG(".bg_block_bitmap = 0x%x", disk->Groups[1].bg_block_bitmap); LOG(".bg_inode_bitmap = 0x%x", disk->Groups[1].bg_inode_bitmap); LOG(".bg_inode_table = 0x%x", disk->Groups[1].bg_inode_table); - #endif // Get root Inode Ext2_int_ReadInode(disk, 2, &inode);