From 36c9094d0e26188c3dbf1b974e813797b76e7687 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Mon, 20 Aug 2012 12:27:04 +0800 Subject: [PATCH] Modules/Ext2 - Experimental write support coming along --- KernelLand/Modules/Filesystems/Ext2/dir.c | 124 ++++++++++--- KernelLand/Modules/Filesystems/Ext2/ext2.c | 86 ++++++++- .../Modules/Filesystems/Ext2/ext2_common.h | 7 +- KernelLand/Modules/Filesystems/Ext2/ext2fs.h | 2 +- KernelLand/Modules/Filesystems/Ext2/write.c | 163 ++++++++++-------- 5 files changed, 282 insertions(+), 100 deletions(-) diff --git a/KernelLand/Modules/Filesystems/Ext2/dir.c b/KernelLand/Modules/Filesystems/Ext2/dir.c index 40cdddd5..ef347ad0 100644 --- a/KernelLand/Modules/Filesystems/Ext2/dir.c +++ b/KernelLand/Modules/Filesystems/Ext2/dir.c @@ -10,7 +10,7 @@ #include "ext2_common.h" // === MACROS === -#define BLOCK_DIR_OFS(_data, _block) ((Uint16*)(_data)[(_block)]) +#define BLOCK_DIR_OFS(_data, _block) (((Uint16*)(_data))[(_block)]) // === PROTOTYPES === char *Ext2_ReadDir(tVFS_Node *Node, int Pos); @@ -183,11 +183,15 @@ int Ext2_MkNod(tVFS_Node *Parent, const char *Name, Uint Flags) Uint64 inodeNum = Ext2_int_AllocateInode(Parent->ImplPtr, Parent->Inode); if( inodeNum == 0 ) { + LOG("Inode allocation failed"); + LEAVE('i', -1); return -1; } tVFS_Node *child = Ext2_int_CreateNode(Parent->ImplPtr, inodeNum); if( !child ) { Ext2_int_DereferenceInode(Parent->ImplPtr, inodeNum); + Log_Warning("Ext2", "Ext2_MkNod - Node creation failed"); + LEAVE('i', -1); return -1; } @@ -216,6 +220,7 @@ int Ext2_MkNod(tVFS_Node *Parent, const char *Name, Uint Flags) */ int Ext2_Unlink(tVFS_Node *Node, const char *OldName) { + Log_Warning("Ext2", "TODO: Impliment Ext2_Unlink"); return 1; } @@ -228,17 +233,20 @@ int Ext2_Unlink(tVFS_Node *Node, const char *OldName) */ int Ext2_Link(tVFS_Node *Node, const char *Name, tVFS_Node *Child) { - #if 0 + #if 1 tExt2_Disk *disk = Node->ImplPtr; tExt2_Inode inode; - tExt2_DirEnt dirent; + tExt2_DirEnt *dirent; tExt2_DirEnt newEntry; - Uint64 Base; // Block's Base Address + Uint64 base; // Block's Base Address int block = 0, ofs = 0; Uint size; void *blockData; - int bestMatch = -1, bestSize, bestBlock, bestOfs; + int bestMatch = -1, bestSize, bestBlock, bestOfs, bestNeedsSplit; int nEntries; + + ENTER("pNode sName pChild", + Node, Name, Child); blockData = malloc(disk->BlockSize); @@ -248,7 +256,7 @@ int Ext2_Link(tVFS_Node *Node, const char *Name, tVFS_Node *Child) // Create a stub entry newEntry.inode = Child->Inode; newEntry.name_len = strlen(Name); - newEntry.rec_len = (newEntry.name_len+3+8)&~3; + newEntry.rec_len = ((newEntry.name_len+3)&~3) + EXT2_DIRENT_SIZE; newEntry.type = inode.i_mode >> 12; memcpy(newEntry.name, Name, newEntry.name_len); @@ -257,8 +265,12 @@ int Ext2_Link(tVFS_Node *Node, const char *Name, tVFS_Node *Child) size = inode.i_size; // Get a lock on the inode - Ext2_int_LockInode(disk, Node->Inode); - + //Ext2_int_LockInode(disk, Node->Inode); + Mutex_Acquire(&Node->Lock); + +// if( !Node->Data ) { +// } + // Get First Block // - Do this ourselves as it is a simple operation base = inode.i_block[0] * disk->BlockSize; @@ -274,10 +286,12 @@ int Ext2_Link(tVFS_Node *Node, const char *Name, tVFS_Node *Child) "Directory entry %i of inode 0x%x extends over a block boundary", nEntries, (Uint)Node->Inode); } - else { - + else + { + LOG("Entry %i: %x %i bytes", nEntries, dirent->type, dirent->rec_len); // Free entry - if(dirent->type == 0) { + if(dirent->type == 0) + { if( dirent->rec_len >= newEntry.rec_len && (bestMatch == -1 || bestSize > dirent->rec_len) ) { @@ -285,23 +299,40 @@ int Ext2_Link(tVFS_Node *Node, const char *Name, tVFS_Node *Child) bestSize = dirent->rec_len; bestBlock = block; bestOfs = ofs; + bestNeedsSplit = 0; } } // Non free - check name to avoid duplicates - else { + else + { + LOG(" name='%.*s'", dirent->name_len, dirent->name); if(strncmp(Name, dirent->name, dirent->name_len) == 0) { - Ext2_int_UnlockInode(disk, Node->Inode); + //Ext2_int_UnlockInode(disk, Node->Inode); + Mutex_Release(&Node->Lock); + LEAVE('i', 1); return 1; // ERR_??? } + + int spare_space = dirent->rec_len - (dirent->name_len + EXT2_DIRENT_SIZE); + if( spare_space > newEntry.rec_len + && (bestMatch == -1 || bestSize > spare_space) ) + { + bestMatch = nEntries; + bestSize = spare_space; + bestBlock = block; + bestOfs = ofs; + bestNeedsSplit = 1; + } } } // Increment the pointer nEntries ++; ofs += dirent->rec_len; - if( ofs >= disk->BlockSize ) { + size -= dirent->rec_len; + if( size > 0 && ofs >= disk->BlockSize ) { // Read the next block if needed - BLOCK_DIR_OFS(Node->Data, block) = nEntries; + // BLOCK_DIR_OFS(Node->Data, block) = nEntries; block ++; ofs = 0; base = Ext2_int_GetBlockAddr(disk, inode.i_block, block); @@ -309,26 +340,66 @@ int Ext2_Link(tVFS_Node *Node, const char *Name, tVFS_Node *Child) } } + LOG("bestMatch = %i", bestMatch); + // If EOF was reached with no space, check if we can fit one on the end + if( bestMatch < 0 && ofs + newEntry.rec_len < disk->BlockSize ) { + Node->Size += newEntry.rec_len; + Node->Flags |= VFS_FFLAG_DIRTY; + bestBlock = block; + bestOfs = ofs; + bestSize = newEntry.rec_len; + bestNeedsSplit = 0; + } // Check if a free slot was found - if( bestMatch >= 0 ) { + if( bestMatch >= 0 ) + { // Read-Modify-Write - bestBlock = Ext2_int_GetBlockAddr(disk, inode.i_block, bestBlock); - if( block > 0 ) - bestMatch = BLOCK_DIR_OFS(Node->Data, bestBlock); + base = Ext2_int_GetBlockAddr(disk, inode.i_block, bestBlock); VFS_ReadAt( disk->FD, base, disk->BlockSize, blockData ); dirent = blockData + bestOfs; - memcpy(dirent, newEntry, newEntry.rec_len); + // Shorten a pre-existing entry + if(bestNeedsSplit) + { + dirent->rec_len = EXT2_DIRENT_SIZE + dirent->name_len; + bestOfs += dirent->rec_len; + //bestSize -= dirent->rec_len; // (not needed, bestSize is the spare space after) + dirent = blockData + bestOfs; + } + // Insert new file entry + memcpy(dirent, &newEntry, newEntry.rec_len); + // Create a new blank entry + if( bestSize != newEntry.rec_len ) + { + bestOfs += newEntry.rec_len; + dirent = blockData + bestOfs; + + dirent->rec_len = bestSize - newEntry.rec_len; + dirent->type = 0; + } + // Save changes VFS_WriteAt( disk->FD, base, disk->BlockSize, blockData ); } else { // Allocate block, Write - block = Ext2_int_AllocateBlock(Disk, block); - Log_Warning("EXT2", ""); + Uint32 newblock = Ext2_int_AllocateBlock(disk, base / disk->BlockSize); + Ext2_int_AppendBlock(disk, &inode, newblock); + base = newblock * disk->BlockSize; + Node->Size += newEntry.rec_len; + Node->Flags |= VFS_FFLAG_DIRTY; + memcpy(blockData, &newEntry, newEntry.rec_len); + memset(blockData + newEntry.rec_len, 0, disk->BlockSize - newEntry.rec_len); + VFS_WriteAt( disk->FD, base, disk->BlockSize, blockData ); } - Ext2_int_UnlockInode(disk, Node->Inode); + Child->ImplInt ++; + Child->Flags |= VFS_FFLAG_DIRTY; + + //Ext2_int_UnlockInode(disk, Node->Inode); + Mutex_Release(&Node->Lock); + LEAVE('i', 0); return 0; #else + Log_Warning("Ext2", "TODO: Impliment Ext2_Link"); return 1; #endif } @@ -400,3 +471,10 @@ tVFS_Node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeID) // Save in node cache and return saved node return Inode_CacheNode(Disk->CacheID, &retNode); } + +int Ext2_int_WritebackNode(tExt2_Disk *Disk, tVFS_Node *Node) +{ + Log_Warning("Ext2","TODO: Impliment Ext2_int_WritebackNode"); + return 0; +} + diff --git a/KernelLand/Modules/Filesystems/Ext2/ext2.c b/KernelLand/Modules/Filesystems/Ext2/ext2.c index 38041a47..5015e14b 100644 --- a/KernelLand/Modules/Filesystems/Ext2/ext2.c +++ b/KernelLand/Modules/Filesystems/Ext2/ext2.c @@ -10,6 +10,9 @@ #include "ext2_common.h" #include +#define MIN_BLOCKS_PER_GROUP 2 +#define MAX_BLOCK_LOG_SIZE 10 // 1024 << 10 = 1MiB + // === IMPORTS === extern tVFS_NodeType gExt2_DirType; @@ -119,7 +122,13 @@ tVFS_Node *Ext2_InitDevice(const char *Device, const char **Options) LEAVE('n'); return NULL; } - + + if( sb.s_blocks_per_group < MIN_BLOCKS_PER_GROUP ) { + Log_Warning("Ext2", "Blocks per group is too small (%i < %i)", + sb.s_blocks_per_group, MIN_BLOCKS_PER_GROUP); + goto _error; + } + // Get Group count groupCount = DivUp(sb.s_blocks_count, sb.s_blocks_per_group); LOG("groupCount = %i", groupCount); @@ -140,6 +149,11 @@ tVFS_Node *Ext2_InitDevice(const char *Device, const char **Options) disk->CacheID = Inode_GetHandle(); // Get Block Size + if( sb.s_log_block_size > MAX_BLOCK_LOG_SIZE ) { + Log_Warning("Ext2", "Block size (log2) too large (%i > %i)", + sb.s_log_block_size, MAX_BLOCK_LOG_SIZE); + goto _error; + } disk->BlockSize = 1024 << sb.s_log_block_size; LOG("Disk->BlockSie = 0x%x (1024 << %i)", disk->BlockSize, sb.s_log_block_size); @@ -186,6 +200,11 @@ tVFS_Node *Ext2_InitDevice(const char *Device, const char **Options) LEAVE('p', &disk->RootNode); return &disk->RootNode; +_error: + free(disk); + VFS_Close(fd); + LEAVE('n'); + return NULL; } /** @@ -366,8 +385,67 @@ 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"); + Uint start_group = (Parent - 1) / Disk->SuperBlock.s_inodes_per_group; + Uint group = start_group; + + if( Disk->SuperBlock.s_free_inodes_count == 0 ) + { + Log_Notice("Ext2", "Ext2_int_AllocateInode - Out of inodes on %p", Disk); + return 0; + } + + while( group < Disk->GroupCount && Disk->Groups[group].bg_free_inodes_count == 0 ) + group ++; + if( group == Disk->GroupCount ) + { + group = 0; + while( group < start_group && Disk->Groups[group].bg_free_inodes_count == 0 ) + group ++; + } + + if( Disk->Groups[group].bg_free_inodes_count == 0 ) + { + Log_Notice("Ext2", "Ext2_int_AllocateInode - Out of inodes on %p, but superblock says some free", Disk); + return 0; + } + + // Load bitmap for group + // (s_inodes_per_group / 8) bytes worth + // - Allocate a buffer the size of a sector/block + // - Read in part of the bitmap + // - Search for a free inode + tExt2_Group *bg = &Disk->Groups[group]; + int ofs = 0; + do { + const int sector_size = 512; + Uint8 buf[sector_size]; + VFS_ReadAt(Disk->FD, Disk->BlockSize*bg->bg_inode_bitmap+ofs, sector_size, buf); + + int byte, bit; + for( byte = 0; byte < sector_size && buf[byte] != 0xFF; byte ++ ) + ; + if( byte < sector_size ) + { + for( bit = 0; bit < 8 && buf[byte] & (1 << bit); bit ++) + ; + ASSERT(bit != 8); + buf[byte] |= 1 << bit; + VFS_WriteAt(Disk->FD, Disk->BlockSize*bg->bg_inode_bitmap+ofs, sector_size, buf); + + bg->bg_free_inodes_count --; + Disk->SuperBlock.s_free_inodes_count --; + + Uint32 ret = group * Disk->SuperBlock.s_inodes_per_group + byte * 8 + bit + 1; + Log_Debug("Ext2", "Ext2_int_AllocateInode - Allocated 0x%x", ret); + return ret; + } + + ofs += sector_size; + } while(ofs < Disk->SuperBlock.s_inodes_per_group / 8); + + Log_Notice("Ext2", "Ext2_int_AllocateInode - Out of inodes in group %p:%i but header reported free", + Disk, group); + return 0; } @@ -376,7 +454,7 @@ Uint32 Ext2_int_AllocateInode(tExt2_Disk *Disk, Uint32 Parent) */ void Ext2_int_DereferenceInode(tExt2_Disk *Disk, Uint32 Inode) { - + Log_Warning("Ext2", "TODO: Impliment Ext2_int_DereferenceInode"); } /** diff --git a/KernelLand/Modules/Filesystems/Ext2/ext2_common.h b/KernelLand/Modules/Filesystems/Ext2/ext2_common.h index 1d994ddb..57b74932 100644 --- a/KernelLand/Modules/Filesystems/Ext2/ext2_common.h +++ b/KernelLand/Modules/Filesystems/Ext2/ext2_common.h @@ -2,10 +2,6 @@ * Acess OS * Ext2 Driver Version 1 */ -/** - * \file ext2_common.h - * \brief Second Extended Filesystem Driver - */ #ifndef _EXT2_COMMON_H #define _EXT2_COMMON_H #include @@ -45,5 +41,8 @@ extern int Ext2_Link(tVFS_Node *Parent, const char *Name, tVFS_Node *Node); extern size_t Ext2_Read(tVFS_Node *node, off_t offset, size_t length, void *buffer); // --- Write --- extern size_t Ext2_Write(tVFS_Node *node, off_t offset, size_t length, const void *buffer); +extern Uint32 Ext2_int_AllocateBlock(tExt2_Disk *Disk, Uint32 LastBlock); +extern void Ext2_int_DeallocateBlock(tExt2_Disk *Disk, Uint32 Block); +extern int Ext2_int_AppendBlock(tExt2_Disk *Disk, tExt2_Inode *Inode, Uint32 Block); #endif diff --git a/KernelLand/Modules/Filesystems/Ext2/ext2fs.h b/KernelLand/Modules/Filesystems/Ext2/ext2fs.h index a3aa301e..4f9210e9 100644 --- a/KernelLand/Modules/Filesystems/Ext2/ext2fs.h +++ b/KernelLand/Modules/Filesystems/Ext2/ext2fs.h @@ -157,6 +157,6 @@ struct ext2_dir_entry_s { Uint8 type; //!< File Type (Duplicate of ext2_inode_s.i_mode) char name[EXT2_NAME_LEN+1]; //!< File name }; -#define EXT2_DIRENT_SIZE (sizeof(struct ext2_dir_entry_s)-EXT2_NAME_LEN+1) +#define EXT2_DIRENT_SIZE (sizeof(struct ext2_dir_entry_s)-(EXT2_NAME_LEN+1)) #endif diff --git a/KernelLand/Modules/Filesystems/Ext2/write.c b/KernelLand/Modules/Filesystems/Ext2/write.c index 22e256bf..766a0e66 100644 --- a/KernelLand/Modules/Filesystems/Ext2/write.c +++ b/KernelLand/Modules/Filesystems/Ext2/write.c @@ -98,7 +98,9 @@ addBlocks: block = Ext2_int_AllocateBlock(disk, base/disk->BlockSize); if(!block) return Length - retLen; // Add it to this inode - if( !Ext2_int_AppendBlock(disk, &inode, block) ) { + if( Ext2_int_AppendBlock(disk, &inode, block) ) { + Log_Warning("Ext2", "Appending %x to inode %p:%X failed", + block, disk, Node->Inode); Ext2_int_DeallocateBlock(disk, block); goto ret; } @@ -113,7 +115,9 @@ addBlocks: // Last block :D block = Ext2_int_AllocateBlock(disk, base/disk->BlockSize); if(!block) goto ret; - if( !Ext2_int_AppendBlock(disk, &inode, block) ) { + if( Ext2_int_AppendBlock(disk, &inode, block) ) { + Log_Warning("Ext2", "Appending %x to inode %p:%X failed", + block, disk, Node->Inode); Ext2_int_DeallocateBlock(disk, block); goto ret; } @@ -141,80 +145,96 @@ ret: // Makes sure the changes to the inode are committed Uint32 Ext2_int_AllocateBlock(tExt2_Disk *Disk, Uint32 PrevBlock) { int bpg = Disk->SuperBlock.s_blocks_per_group; - Uint blockgroup = PrevBlock / bpg; - Uint bitmap[Disk->BlockSize/sizeof(Uint)]; - Uint bitsperblock = 8*Disk->BlockSize; - int i, j = 0; - Uint block; - + Uint firstgroup = PrevBlock / bpg; + Uint blockgroup = firstgroup; + tExt2_Group *bg; + + // TODO: Need to do locking on the bitmaps + // Are there any free blocks? - if(Disk->SuperBlock.s_free_blocks_count == 0) return 0; - - if(Disk->Groups[blockgroup].bg_free_blocks_count > 0) + if(Disk->SuperBlock.s_free_blocks_count == 0) + return 0; + + // First: Check the next block after \a PrevBlock + if( (PrevBlock + 1) % Disk->SuperBlock.s_blocks_per_group != 0 + && Disk->Groups[blockgroup].bg_free_blocks_count > 0 ) { - // Search block group's bitmap - for(i = 0; i < bpg; i++) + bg = &Disk->Groups[blockgroup]; + const int sector_size = 512; + Uint8 buf[sector_size]; + int iblock = (PrevBlock + 1) % Disk->SuperBlock.s_blocks_per_group; + int byte = iblock / 8; + int ofs = byte / sector_size * sector_size; + byte %= sector_size; + VFS_ReadAt(Disk->FD, Disk->BlockSize*bg->bg_block_bitmap+ofs, sector_size, buf); + + if( (buf[byte] & (1 << (iblock%8))) == 0 ) { - // Get the block in the bitmap block - j = i & (bitsperblock-1); - - // Read in if needed - if(j == 0) { - VFS_ReadAt( - Disk->FD, - (Uint64)Disk->Groups[blockgroup].bg_block_bitmap + i / bitsperblock, - Disk->BlockSize, - bitmap - ); - } - - // Fast Check - if( bitmap[j/32] == 0xFFFFFFFF ) { - j = (j + 31) & ~31; - continue; - } - - // Is the bit set? - if( bitmap[j/32] & (1 << (j%32)) ) - continue; - - // Ooh! We found one - break; - } - if( i < bpg ) { - Warning("[EXT2 ] Inconsistency detected, Group Free Block count is non-zero when no free blocks exist"); - goto checkAll; // Search the entire filesystem for a free block - // Goto needed for neatness + // Free block - nice and contig allocation + buf[byte] |= (1 << (iblock%8)); + VFS_WriteAt(Disk->FD, Disk->BlockSize*bg->bg_block_bitmap+ofs, sector_size, buf); + + bg->bg_free_blocks_count --; + Disk->SuperBlock.s_free_blocks_count --; + #if EXT2_UPDATE_WRITEBACK + Ext2_int_UpdateSuperblock(Disk); + #endif + return PrevBlock + 1; } - - // Mark as used - bitmap[j/32] |= (1 << (j%32)); - VFS_WriteAt( - Disk->FD, - (Uint64)Disk->Groups[blockgroup].bg_block_bitmap + i / bitsperblock, - Disk->BlockSize, - bitmap - ); - block = i; - Disk->Groups[blockgroup].bg_free_blocks_count --; - #if EXT2_UPDATE_WRITEBACK - //Ext2_int_UpdateBlockGroup(Disk, blockgroup); - #endif + // Used... darnit + // Fall through and search further } - else + + // Second: Search for a group with free blocks + while( blockgroup < Disk->GroupCount && Disk->Groups[blockgroup].bg_free_blocks_count == 0 ) + blockgroup ++; + if( Disk->Groups[blockgroup].bg_free_blocks_count == 0 ) { - checkAll: - Log_Warning("EXT2", "TODO - Implement using blocks outside the current block group"); + blockgroup = 0; + while( blockgroup < firstgroup && Disk->Groups[blockgroup].bg_free_blocks_count == 0 ) + blockgroup ++; + } + if( Disk->Groups[blockgroup].bg_free_blocks_count == 0 ) { + Log_Notice("Ext2", "Ext2_int_AllocateBlock - Out of blockss on %p, but superblock says some free", + Disk); return 0; } + + // Search the bitmap for a free block + bg = &Disk->Groups[blockgroup]; + int ofs = 0; + do { + const int sector_size = 512; + Uint8 buf[sector_size]; + VFS_ReadAt(Disk->FD, Disk->BlockSize*bg->bg_block_bitmap+ofs, sector_size, buf); + + int byte, bit; + for( byte = 0; byte < sector_size && buf[byte] != 0xFF; byte ++ ) + ; + if( byte < sector_size ) + { + for( bit = 0; bit < 8 && buf[byte] & (1 << bit); bit ++) + ; + ASSERT(bit != 8); + buf[byte] |= 1 << bit; + VFS_WriteAt(Disk->FD, Disk->BlockSize*bg->bg_block_bitmap+ofs, sector_size, buf); + + bg->bg_free_blocks_count --; + Disk->SuperBlock.s_free_blocks_count --; + + #if EXT2_UPDATE_WRITEBACK + Ext2_int_UpdateSuperblock(Disk); + #endif + + Uint32 ret = blockgroup * Disk->SuperBlock.s_blocks_per_group + byte * 8 + bit; + Log_Debug("Ext2", "Ext2_int_AllocateBlock - Allocated 0x%x", ret); + return ret; + } + } while(ofs < Disk->SuperBlock.s_blocks_per_group / 8); - // Reduce global count - Disk->SuperBlock.s_free_blocks_count --; - #if EXT2_UPDATE_WRITEBACK - Ext2_int_UpdateSuperblock(Disk); - #endif - - return block; + Log_Notice("Ext2", "Ext2_int_AllocateBlock - Out of block in group %p:%i but header reported free", + Disk, blockgroup); + return 0; } /** @@ -222,6 +242,7 @@ Uint32 Ext2_int_AllocateBlock(tExt2_Disk *Disk, Uint32 PrevBlock) */ void Ext2_int_DeallocateBlock(tExt2_Disk *Disk, Uint32 Block) { + Log_Warning("Ext2", "TODO: Impliment Ext2_int_DeallocateBlock"); } /** @@ -253,6 +274,7 @@ int Ext2_int_AppendBlock(tExt2_Disk *Disk, tExt2_Inode *Inode, Uint32 Block) if( nBlocks == 0 ) { Inode->i_block[12] = Ext2_int_AllocateBlock(Disk, Inode->i_block[0]); if( !Inode->i_block[12] ) { + Log_Warning("Ext2", "Allocating indirect block failed"); free(blocks); return 1; } @@ -276,6 +298,7 @@ int Ext2_int_AppendBlock(tExt2_Disk *Disk, tExt2_Inode *Inode, Uint32 Block) if( nBlocks == 0 ) { Inode->i_block[13] = Ext2_int_AllocateBlock(Disk, Inode->i_block[0]); if( !Inode->i_block[13] ) { + Log_Warning("Ext2", "Allocating double indirect block failed"); free(blocks); return 1; } @@ -289,6 +312,7 @@ int Ext2_int_AppendBlock(tExt2_Disk *Disk, tExt2_Inode *Inode, Uint32 Block) id1 = Ext2_int_AllocateBlock(Disk, Inode->i_block[0]); if( !id1 ) { free(blocks); + Log_Warning("Ext2", "Allocating double indirect block (l2) failed"); return 1; } blocks[nBlocks/dwPerBlock] = id1; @@ -316,6 +340,7 @@ int Ext2_int_AppendBlock(tExt2_Disk *Disk, tExt2_Inode *Inode, Uint32 Block) if( nBlocks == 0 ) { Inode->i_block[14] = Ext2_int_AllocateBlock(Disk, Inode->i_block[0]); if( !Inode->i_block[14] ) { + Log_Warning("Ext2", "Allocating triple indirect block failed"); free(blocks); return 1; } @@ -329,6 +354,7 @@ int Ext2_int_AppendBlock(tExt2_Disk *Disk, tExt2_Inode *Inode, Uint32 Block) { id1 = Ext2_int_AllocateBlock(Disk, Inode->i_block[0]); if( !id1 ) { + Log_Warning("Ext2", "Allocating triple indirect block (l2) failed"); free(blocks); return 1; } @@ -346,6 +372,7 @@ int Ext2_int_AppendBlock(tExt2_Disk *Disk, tExt2_Inode *Inode, Uint32 Block) if( nBlocks % dwPerBlock == 0 ) { id2 = Ext2_int_AllocateBlock(Disk, id1); if( !id2 ) { + Log_Warning("Ext2", "Allocating triple indirect block (l3) failed"); free(blocks); return 1; } @@ -366,7 +393,7 @@ int Ext2_int_AppendBlock(tExt2_Disk *Disk, tExt2_Inode *Inode, Uint32 Block) return 0; } - Warning("[EXT2 ] Inode %i cannot have a block appended to it, all indirects used"); + Log_Warning("Ext2", "Inode ?? cannot have a block appended to it, all indirects used"); free(blocks); return 1; } -- 2.20.1