Fixed Triple Fault in EXT2 driver/hdd driver
authorJohn Hodge <[email protected]>
Sat, 10 Oct 2009 01:06:00 +0000 (09:06 +0800)
committerJohn Hodge <[email protected]>
Sat, 10 Oct 2009 01:06:00 +0000 (09:06 +0800)
Kernel/drv/ata_x86.c
Kernel/vfs/fs/ext2.c

index e57adde..c8814d9 100644 (file)
@@ -647,7 +647,8 @@ tVFS_Node *ATA_FindDir(tVFS_Node *Node, char *Name)
  * \fn Uint64 ATA_ReadFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
  */
 Uint64 ATA_ReadFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
-{      
+{
+       //Log("ATA_ReadFS: (Node=%p, Offset=0x%llx, Length=0x%llx, Buffer=%p)", Node, Offset, Length, Buffer);
        return DrvUtil_ReadBlock(Offset, Length, Buffer, ATA_Read, SECTOR_SIZE, Node->Inode);
 }
 
index 06189f8..1da9c0f 100644 (file)
@@ -78,10 +78,13 @@ tVFS_Node *Ext2_InitDevice(char *Device, char **Options)
        tExt2_SuperBlock        sb;\r
        tExt2_Inode     inode;\r
        \r
+       ENTER("sDevice pOptions", Device, Options);\r
+       \r
        // Open Disk\r
        fd = VFS_Open(Device, VFS_OPENFLAG_READ|VFS_OPENFLAG_WRITE);            //Open Device\r
        if(fd == -1) {\r
-               Warning("[EXT2] Unable to open '%s'\n", Device);\r
+               Warning("[EXT2 ] Unable to open '%s'\n", Device);\r
+               LEAVE('n');\r
                return NULL;\r
        }\r
        \r
@@ -92,15 +95,22 @@ tVFS_Node *Ext2_InitDevice(char *Device, char **Options)
        if(sb.s_magic != 0xEF53) {\r
                Warning("[EXT2 ] Volume '%s' is not an EXT2 volume\n", Device);\r
                VFS_Close(fd);\r
+               LEAVE('n');\r
                return NULL;\r
        }\r
        \r
        // Get Group count\r
        groupCount = DivUp(sb.s_blocks_count, sb.s_blocks_per_group);\r
-       //LogF(" Ext2_initDevice: groupCount = %i\n", groupCount);\r
+       LOG("groupCount = %i", groupCount);\r
        \r
        // Allocate Disk Information\r
        disk = malloc(sizeof(tExt2_Disk) + sizeof(tExt2_Group)*groupCount);\r
+       if(!disk) {\r
+               Warning("[EXT2 ] Unable to allocate disk structure\n");\r
+               VFS_Close(fd);\r
+               LEAVE('n');\r
+               return NULL;\r
+       }\r
        disk->FD = fd;\r
        memcpy(&disk->SuperBlock, &sb, 1024);\r
        disk->GroupCount = groupCount;\r
@@ -109,24 +119,26 @@ tVFS_Node *Ext2_InitDevice(char *Device, char **Options)
        disk->CacheID = Inode_GetHandle();\r
        \r
        // Get Block Size\r
-       //LogF(" Ext2_initDevice: s_log_block_size = 0x%x\n", sb.s_log_block_size);\r
+       LOG("s_log_block_size = 0x%x", sb.s_log_block_size);\r
        disk->BlockSize = 1024 << sb.s_log_block_size;\r
        \r
        // Read Group Information\r
-       VFS_ReadAt(disk->FD,\r
+       VFS_ReadAt(\r
+               disk->FD,\r
                sb.s_first_data_block * disk->BlockSize + 1024,\r
                sizeof(tExt2_Group)*groupCount,\r
-               disk->Groups);\r
-       \r
-       #if 0\r
-       Log(" Ext2_initDevice: Block Group 0\n");\r
-       Log(" Ext2_initDevice: .bg_block_bitmap = 0x%x\n", disk->Groups[0].bg_block_bitmap);\r
-       Log(" Ext2_initDevice: .bg_inode_bitmap = 0x%x\n", disk->Groups[0].bg_inode_bitmap);\r
-       Log(" Ext2_initDevice: .bg_inode_table = 0x%x\n", disk->Groups[0].bg_inode_table);\r
-       Log(" Ext2_initDevice: Block Group 1\n");\r
-       Log(" Ext2_initDevice: .bg_block_bitmap = 0x%x\n", disk->Groups[1].bg_block_bitmap);\r
-       Log(" Ext2_initDevice: .bg_inode_bitmap = 0x%x\n", disk->Groups[1].bg_inode_bitmap);\r
-       Log(" Ext2_initDevice: .bg_inode_table = 0x%x\n", disk->Groups[1].bg_inode_table);\r
+               disk->Groups\r
+               );\r
+       \r
+       #if DEBUG\r
+       LOG("Block Group 0");\r
+       LOG(".bg_block_bitmap = 0x%x", disk->Groups[0].bg_block_bitmap);\r
+       LOG(".bg_inode_bitmap = 0x%x", disk->Groups[0].bg_inode_bitmap);\r
+       LOG(".bg_inode_table = 0x%x", disk->Groups[0].bg_inode_table);\r
+       LOG("Block Group 1");\r
+       LOG(".bg_block_bitmap = 0x%x", disk->Groups[1].bg_block_bitmap);\r
+       LOG(".bg_inode_bitmap = 0x%x", disk->Groups[1].bg_inode_bitmap);\r
+       LOG(".bg_inode_table = 0x%x", disk->Groups[1].bg_inode_table);\r
        #endif\r
        \r
        // Get root Inode\r
@@ -149,11 +161,12 @@ tVFS_Node *Ext2_InitDevice(char *Device, char **Options)
        disk->RootNode.NumACLs = 1;\r
        disk->RootNode.ACLs = &gVFS_ACL_EveryoneRW;\r
        \r
-       #if 0\r
-       Log(" Ext2_InitDevice: inode.i_size = 0x%x\n", inode.i_size);\r
-       Log(" Ext2_InitDevice: inode.i_block[0] = 0x%x\n", inode.i_block[0]);\r
+       #if DEBUG\r
+       LOG("inode.i_size = 0x%x", inode.i_size);\r
+       LOG("inode.i_block[0] = 0x%x", inode.i_block[0]);\r
        #endif\r
        \r
+       LEAVE('p', &disk->RootNode);\r
        return &disk->RootNode;\r
 }\r
 \r
@@ -183,6 +196,8 @@ Uint64 Ext2_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
        Uint    block;\r
        Uint64  remLen;\r
        \r
+       ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);\r
+       \r
        // Get Inode\r
        Ext2_int_GetInode(Node, &inode);\r
        \r
@@ -194,6 +209,7 @@ Uint64 Ext2_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
        if(Length <= disk->BlockSize - Offset)\r
        {\r
                VFS_ReadAt( disk->FD, base+Offset, Length, Buffer);\r
+               LEAVE('X', Length);\r
                return Length;\r
        }\r
        \r
@@ -218,6 +234,7 @@ Uint64 Ext2_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
        base = Ext2_int_GetBlockAddr(disk, inode.i_block, block);\r
        VFS_ReadAt( disk->FD, base, remLen, Buffer);\r
        \r
+       LEAVE('X', Length);\r
        return Length;\r
 }\r
 \r
@@ -348,9 +365,9 @@ char *Ext2_ReadDir(tVFS_Node *Node, int Pos)
        \r
        // Read Entry\r
        VFS_ReadAt( disk->FD, Base+ofs, sizeof(tExt2_DirEnt), &dirent );\r
-       //LOG(" Ext2_ReadDir: dirent.inode = %i\n", dirent.inode);\r
-       //LOG(" Ext2_ReadDir: dirent.rec_len = %i\n", dirent.rec_len);\r
-       //LOG(" Ext2_ReadDir: dirent.name_len = %i\n", dirent.name_len);\r
+       //LOG("dirent.inode = %i\n", dirent.inode);\r
+       //LOG("dirent.rec_len = %i\n", dirent.rec_len);\r
+       //LOG("dirent.name_len = %i\n", dirent.name_len);\r
        VFS_ReadAt( disk->FD, Base+ofs+sizeof(tExt2_DirEnt), dirent.name_len, namebuf );\r
        namebuf[ dirent.name_len ] = '\0';      // Cap off string\r
        \r

UCC git Repository :: git.ucc.asn.au