Kernel - Instruction tracing support
[tpg/acess2.git] / Modules / Filesystems / Ext2 / ext2.c
index c2c2df9..ad96cc8 100644 (file)
@@ -15,7 +15,7 @@
 // === PROTOTYPES ===\r
  int   Ext2_Install(char **Arguments);\r
 // Interface Functions\r
-tVFS_Node      *Ext2_InitDevice(char *Device, char **Options);\r
+tVFS_Node      *Ext2_InitDevice(const char *Device, const char **Options);\r
 void           Ext2_Unmount(tVFS_Node *Node);\r
 void           Ext2_CloseFile(tVFS_Node *Node);\r
 // Internal Helpers\r
@@ -33,7 +33,6 @@ tVFS_Driver   gExt2_FSInfo = {
        };\r
 \r
 // === CODE ===\r
-\r
 /**\r
  * \fn int Ext2_Install(char **Arguments)\r
  * \brief Install the Ext2 Filesystem Driver\r
@@ -45,13 +44,12 @@ int Ext2_Install(char **Arguments)
 }\r
 \r
 /**\r
- \fn tVFS_Node *Ext2_InitDevice(char *Device, char **Options)\r
  \brief Initializes a device to be read by by the driver\r
  \param Device String - Device to read from\r
  \param Options        NULL Terminated array of option strings\r
  \return Root Node\r
 */\r
-tVFS_Node *Ext2_InitDevice(char *Device, char **Options)\r
+tVFS_Node *Ext2_InitDevice(const char *Device, const char **Options)\r
 {\r
        tExt2_Disk      *disk;\r
         int    fd;\r
@@ -64,7 +62,7 @@ tVFS_Node *Ext2_InitDevice(char *Device, char **Options)
        // 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'", Device);\r
+               Log_Warning("EXT2", "Unable to open '%s'", Device);\r
                LEAVE('n');\r
                return NULL;\r
        }\r
@@ -74,7 +72,8 @@ tVFS_Node *Ext2_InitDevice(char *Device, char **Options)
        \r
        // Sanity Check Magic value\r
        if(sb.s_magic != 0xEF53) {\r
-               Warning("[EXT2 ] Volume '%s' is not an EXT2 volume", Device);\r
+               Log_Warning("EXT2", "Volume '%s' is not an EXT2 volume (0x%x != 0xEF53)",\r
+                       Device, sb.s_magic);\r
                VFS_Close(fd);\r
                LEAVE('n');\r
                return NULL;\r
@@ -87,7 +86,7 @@ tVFS_Node *Ext2_InitDevice(char *Device, char **Options)
        // Allocate Disk Information\r
        disk = malloc(sizeof(tExt2_Disk) + sizeof(tExt2_Group)*groupCount);\r
        if(!disk) {\r
-               Warning("[EXT2 ] Unable to allocate disk structure");\r
+               Log_Warning("EXT2", "Unable to allocate disk structure");\r
                VFS_Close(fd);\r
                LEAVE('n');\r
                return NULL;\r
@@ -187,7 +186,7 @@ int Ext2_int_ReadInode(tExt2_Disk *Disk, Uint32 InodeId, tExt2_Inode *Inode)
 {\r
         int    group, subId;\r
        \r
-       //ENTER("pDisk iInodeId pInode", Disk, InodeId, Inode);\r
+       ENTER("pDisk iInodeId pInode", Disk, InodeId, Inode);\r
        \r
        if(InodeId == 0)        return 0;\r
        \r
@@ -196,7 +195,7 @@ int Ext2_int_ReadInode(tExt2_Disk *Disk, Uint32 InodeId, tExt2_Inode *Inode)
        group = InodeId / Disk->SuperBlock.s_inodes_per_group;\r
        subId = InodeId % Disk->SuperBlock.s_inodes_per_group;\r
        \r
-       //LOG("group=%i, subId = %i", group, subId);\r
+       LOG("group=%i, subId = %i", group, subId);\r
        \r
        // Read Inode\r
        VFS_ReadAt(Disk->FD,\r
@@ -204,7 +203,7 @@ int Ext2_int_ReadInode(tExt2_Disk *Disk, Uint32 InodeId, tExt2_Inode *Inode)
                sizeof(tExt2_Inode),\r
                Inode);\r
        \r
-       //LEAVE('i', 1);\r
+       LEAVE('i', 1);\r
        return 1;\r
 }\r
 \r
@@ -216,7 +215,10 @@ int Ext2_int_WriteInode(tExt2_Disk *Disk, Uint32 InodeId, tExt2_Inode *Inode)
         int    group, subId;\r
        ENTER("pDisk iInodeId pInode", Disk, InodeId, Inode);\r
        \r
-       if(InodeId == 0)        return 0;\r
+       if(InodeId == 0) {\r
+               LEAVE('i', 0);\r
+               return 0;\r
+       }\r
        \r
        InodeId --;     // Inodes are numbered starting at 1\r
        \r
@@ -229,7 +231,8 @@ int Ext2_int_WriteInode(tExt2_Disk *Disk, Uint32 InodeId, tExt2_Inode *Inode)
        VFS_WriteAt(Disk->FD,\r
                Disk->Groups[group].bg_inode_table * Disk->BlockSize + sizeof(tExt2_Inode)*subId,\r
                sizeof(tExt2_Inode),\r
-               Inode);\r
+               Inode\r
+               );\r
        \r
        LEAVE('i', 1);\r
        return 1;\r
@@ -293,6 +296,7 @@ Uint64 Ext2_int_GetBlockAddr(tExt2_Disk *Disk, Uint32 *Blocks, int BlockNum)
 Uint32 Ext2_int_AllocateInode(tExt2_Disk *Disk, Uint32 Parent)\r
 {\r
 //     Uint    block = (Parent - 1) / Disk->SuperBlock.s_inodes_per_group;\r
+       Log_Warning("EXT2", "Ext2_int_AllocateInode is unimplemented");\r
        return 0;\r
 }\r
 \r
@@ -316,15 +320,17 @@ void Ext2_int_UpdateSuperblock(tExt2_Disk *Disk)
        if(ngrp <= 1)   return;\r
        VFS_WriteAt(Disk->FD, 1*bpg*Disk->BlockSize, 1024, &Disk->SuperBlock);\r
        \r
+       #define INT_MAX (((long long int)1<<(sizeof(int)*8))-1)\r
+       \r
        // Powers of 3\r
-       for( i = 3; i < ngrp; i *= 3 )\r
+       for( i = 3; i < ngrp && i < INT_MAX/3; i *= 3 )\r
                VFS_WriteAt(Disk->FD, i*bpg*Disk->BlockSize, 1024, &Disk->SuperBlock);\r
        \r
        // Powers of 5\r
-       for( i = 5; i < ngrp; i *= 5 )\r
+       for( i = 5; i < ngrp && i < INT_MAX/5; i *= 5 )\r
                VFS_WriteAt(Disk->FD, i*bpg*Disk->BlockSize, 1024, &Disk->SuperBlock);\r
        \r
        // Powers of 7\r
-       for( i = 7; i < ngrp; i *= 7 )\r
+       for( i = 7; i < ngrp && i < INT_MAX/7; i *= 7 )\r
                VFS_WriteAt(Disk->FD, i*bpg*Disk->BlockSize, 1024, &Disk->SuperBlock);\r
 }\r

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