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