bool ext2_write_block(PEXT2_FILESYS fs, ULONG block, void *inbuf) { bool retval = false; retval = NT_SUCCESS(Ext2WriteDisk( fs, ((ULONGLONG)block * fs->blocksize), fs->blocksize, (unsigned char *)inbuf)); return retval; }
/* * This function zeros out the allocated block, and updates all of the * appropriate filesystem records. */ bool ext2_alloc_block(PEXT2_FILESYS fs, ULONG goal, ULONG *ret) { bool retval; ULONG block; char *buf = NULL; buf = (char *)RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, fs->blocksize); if (!buf) return false; if (!fs->block_map) { retval = ext2_read_block_bitmap(fs); if (!retval) goto fail; } retval = ext2_new_block(fs, goal, 0, &block); if (!retval) goto fail; retval = NT_SUCCESS(Ext2WriteDisk( fs, ((LONGLONG)block * fs->blocksize), fs->blocksize, (unsigned char *)buf)); if (!retval) { goto fail; } ext2_block_alloc_stats(fs, block, +1); *ret = block; if (buf) { RtlFreeHeap(RtlGetProcessHeap(), 0, buf); } return true; fail: if (buf) { RtlFreeHeap(RtlGetProcessHeap(), 0, buf); } return false; }
bool ext2_save_inode(PEXT2_FILESYS Ext2Sys, ULONG no, PEXT2_INODE pInode) { LONGLONG offset; bool bRet = false; if (ext2_get_inode_lba(Ext2Sys, no, &offset)) { bRet = NT_SUCCESS(Ext2WriteDisk( Ext2Sys, offset, sizeof(EXT2_INODE), (unsigned char *)pInode)); } return bRet; }
bool ext2_write_inode (PEXT2_FILESYS Ext2Sys, ULONG ino, ULONG offset, PVOID Buffer, ULONG size, PULONG dwReturn ) { PEXT2_BDL ext2_bdl = NULL; ULONG blocks, i; bool bRet = true; EXT2_INODE inode; ULONG dwTotal = 0; ULONG dwBlk = 0; ULONG TotalBlks; blocks = (size + offset + Ext2Sys->blocksize - 1) / Ext2Sys->blocksize; if (!ext2_load_inode(Ext2Sys, ino, &inode)) { return false; } TotalBlks = inode.i_blocks / (Ext2Sys->blocksize / SECTOR_SIZE); TotalBlks = Ext2DataBlocks(Ext2Sys, TotalBlks); if (blocks > TotalBlks) { for (i=0; i < (blocks - TotalBlks); i++) { if (ext2_alloc_block(Ext2Sys, 0, &dwBlk) ) { ext2_expand_inode(Ext2Sys, &inode, dwBlk); inode.i_blocks += (Ext2Sys->blocksize/SECTOR_SIZE); } } } blocks = ext2_build_bdl(Ext2Sys, &inode, offset, size, &ext2_bdl); if (blocks <= 0) return false; for(i = 0; i < blocks; i++) { bRet = NT_SUCCESS(Ext2WriteDisk( Ext2Sys, ext2_bdl[i].Lba, ext2_bdl[i].Length, (PUCHAR)Buffer + ext2_bdl[i].Offset )); if (!bRet) { goto errorout; } dwTotal += ext2_bdl[i].Length; } *dwReturn = dwTotal; if (size + offset > inode.i_size) { inode.i_size = size + offset; } ext2_save_inode(Ext2Sys, ino, &inode); errorout: if (ext2_bdl) RtlFreeHeap(RtlGetProcessHeap(), 0, ext2_bdl); return bRet; }