X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FFilesystems%2FExt2%2Fext2.c;h=f8f942d58153c79243f8d5705d60ea290c9c41d3;hb=e93b9c1fe4068dd5b07049c0926dbb910d20a99b;hp=6379a9d0f69017873b0facdede6da4b76d8208c3;hpb=214f5285816adefadbeff98d04d04d39207c86ef;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/Filesystems/Ext2/ext2.c b/KernelLand/Modules/Filesystems/Ext2/ext2.c index 6379a9d0..f8f942d5 100644 --- a/KernelLand/Modules/Filesystems/Ext2/ext2.c +++ b/KernelLand/Modules/Filesystems/Ext2/ext2.c @@ -15,23 +15,29 @@ extern tVFS_NodeType gExt2_DirType; // === PROTOTYPES === int Ext2_Install(char **Arguments); -void Ext2_Cleanup(void); + 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); +void Ext2_Unmount(tVFS_Node *Node); +void Ext2_CloseFile(tVFS_Node *Node); // - 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); + 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_DereferenceInode(tExt2_Disk *Disk, Uint32 Inode); +void Ext2_int_UpdateSuperblock(tExt2_Disk *Disk); // === SEMI-GLOBALS === 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 === @@ -48,9 +54,34 @@ int Ext2_Install(char **Arguments) /** * \brief Clean up driver state before unload */ -void Ext2_Cleanup(void) +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; + } } /** @@ -178,7 +209,22 @@ void Ext2_Unmount(tVFS_Node *Node) void Ext2_CloseFile(tVFS_Node *Node) { tExt2_Disk *disk = Node->ImplPtr; - Inode_UncacheNode(disk->CacheID, Node->Inode); + + if( Mutex_Acquire(&Node->Lock) != 0 ) + { + return ; + } + + if( Node->Flags & VFS_FFLAG_DIRTY ) + { + // Commit changes + } + + int was_not_referenced = (Node->ImplInt == 0); + if( Inode_UncacheNode(disk->CacheID, Node->Inode) && was_not_referenced ) + { + // Remove inode + } return ; } @@ -307,6 +353,14 @@ Uint32 Ext2_int_AllocateInode(tExt2_Disk *Disk, Uint32 Parent) return 0; } +/** + * \brief Reduce the reference count on an inode + */ +void Ext2_int_DereferenceInode(tExt2_Disk *Disk, Uint32 Inode) +{ + +} + /** * \fn void Ext2_int_UpdateSuperblock(tExt2_Disk *Disk) * \brief Updates the superblock