Author: korli Date: 2010-10-30 15:45:01 +0200 (Sat, 30 Oct 2010) New Revision: 39203 Changeset: http://dev.haiku-os.org/changeset/39203 Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Attribute.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/BitmapBlock.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/BlockAllocator.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/BlockAllocator.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/CachedBlock.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/DataStream.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/DataStream.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/InodeAllocator.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp Log: * added some support for 64bit feature: extended struct ext2_block_group, block number types changed from uint32 to off_t * added error traces, asserts * BitmapBlock::CheckUnmarked() and CheckMarked() computed a wrong remainingBits and mask Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Attribute.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Attribute.cpp 2010-10-30 11:45:04 UTC (rev 39202) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Attribute.cpp 2010-10-30 13:45:01 UTC (rev 39203) @@ -251,11 +251,11 @@ // try to find it in the small data region if (fInode->HasExtraAttributes() && recursive_lock_lock(&fInode->SmallDataLock()) == B_OK) { - uint32 block; - fVolume->GetInodeBlock(fInode->ID(), block); + off_t blockNum; + fVolume->GetInodeBlock(fInode->ID(), blockNum); - if (block != 0) { - fBlock.SetTo(block); + if (blockNum != 0) { + fBlock.SetTo(blockNum); const uint8* start = fBlock.Block() + fVolume->InodeBlockIndex(fInode->ID()) * fVolume->InodeSize(); const uint8* end = start + fVolume->InodeSize(); Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/BitmapBlock.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/BitmapBlock.cpp 2010-10-30 11:45:04 UTC (rev 39202) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/BitmapBlock.cpp 2010-10-30 13:45:01 UTC (rev 39203) @@ -63,10 +63,12 @@ if (start + length > fNumBits) return false; + if (length == 0) + return true; uint32 startIndex = start >> 5; uint32 startBit = start & 0x1F; - uint32 remainingBits = (length - startBit) & 0x1F; + uint32 remainingBits = (length + startBit) & 0x1F; uint32 iterations; @@ -86,28 +88,39 @@ uint32 index = startIndex; uint32 mask = 0; + TRACE("BitmapBlock::CheckUnmarked(): startBit: %lu iterations %lu remainingbits %lu\n", + startBit, iterations, remainingBits); + if (startBit != 0) { mask = ~((1 << startBit) - 1); uint32 bits = B_LENDIAN_TO_HOST_INT32(data[index]); - if ((bits & mask) != 0) + if ((bits & mask) != 0) { + TRACE("BitmapBlock::CheckUnmarked(): start %lx mask %lx\n", bits, mask); return false; + } index += 1; } else iterations++; for (; iterations > 0; --iterations) { - if (data[index++] != 0) + if (data[index++] != 0) { + TRACE("BitmapBlock::CheckUnmarked(): iterations %lu bits: %lX\n", iterations, + data[index - 1]); return false; + } } if (remainingBits != 0) { - mask = (1 << (remainingBits + 1)) - 1; + mask = (1 << remainingBits) - 1; uint32 bits = B_LENDIAN_TO_HOST_INT32(data[index]); - if ((bits & mask) != 0) + if ((bits & mask) != 0) { + TRACE("BitmapBlock::CheckUnmarked(): remainingBits %ld remaining %lX mask %lX\n", + remainingBits, bits, mask); return false; + } } return true; @@ -123,10 +136,12 @@ if (start + length > fNumBits) return false; + if (length == 0) + return true; uint32 startIndex = start >> 5; uint32 startBit = start & 0x1F; - uint32 remainingBits = (length - startBit) & 0x1F; + uint32 remainingBits = (length + startBit) & 0x1F; uint32 iterations; @@ -164,7 +179,7 @@ } if (remainingBits != 0) { - mask = (1 << (remainingBits + 1)) - 1; + mask = (1 << remainingBits) - 1; uint32 bits = B_HOST_TO_LENDIAN_INT32(data[index]); if ((bits & mask) != mask) @@ -183,7 +198,7 @@ uint32 startIndex = start >> 5; uint32 startBit = start & 0x1F; - uint32 remainingBits = (length - 32 + startBit) & 0x1F; + uint32 remainingBits = (length + startBit) & 0x1F; uint32 iterations; @@ -194,8 +209,11 @@ uint32 mask = (1 << (startBit + length)) - 1; mask &= ~((1 << startBit) - 1); - if ((bits & mask) != 0) + if ((bits & mask) != 0) { + TRACE("BitmapBlock::Mark() Marking failed bits %lx " + "startBit %ld\n", bits, startBit); return false; + } bits |= mask; @@ -221,8 +239,11 @@ TRACE("BitmapBlock::Mark(): index %lu mask: %lX, bits: %lX\n", index, mask, bits); - if (!force && (bits & mask) != 0) + if (!force && (bits & mask) != 0) { + TRACE("BitmapBlock::Mark() Marking failed bits %lx " + "startBit %ld\n", bits, startBit); return false; + } bits |= mask; fData[index] = B_HOST_TO_LENDIAN_INT32(bits); @@ -233,8 +254,11 @@ mask = 0xFFFFFFFF; for (; iterations > 0; --iterations) { - if (!force && fData[index] != 0) + if (!force && fData[index] != 0) { + TRACE("BitmapBlock::Mark() Marking failed " + "index %ld, iterations %ld\n", index, iterations); return false; + } fData[index++] |= mask; } @@ -244,8 +268,10 @@ TRACE("BitmapBlock::Mark(): marking index %lu remaining %lu bits: %lX," " mask: %lX\n", index, remainingBits, bits, mask); - if (!force && (bits & mask) != 0) + if (!force && (bits & mask) != 0) { + TRACE("BitmapBlock::Mark() Marking failed remaining\n"); return false; + } bits |= mask; fData[index] = B_HOST_TO_LENDIAN_INT32(bits); @@ -266,7 +292,7 @@ uint32 startIndex = start >> 5; uint32 startBit = start & 0x1F; - uint32 remainingBits = (length - 32 + startBit) & 0x1F; + uint32 remainingBits = (length + startBit) & 0x1F; TRACE("BitmapBlock::Unmark(): start index: %lu, start bit: %lu, remaining " "bits: %lu)\n", startIndex, startBit, remainingBits); @@ -282,8 +308,11 @@ TRACE("BitmapBlock::Unmark(): mask: %lx\n", mask); - if ((bits & mask) != mask) + if ((bits & mask) != mask) { + TRACE("BitmapBlock::Unmark() Marking failed bits %lx " + "startBit %ld\n", bits, startBit); return false; + } bits &= ~mask; @@ -319,8 +348,11 @@ mask = 0xFFFFFFFF; for (; iterations > 0; --iterations) { - if (!force && fData[index] != mask) + if (!force && fData[index] != mask) { + TRACE("BitmapBlock::Unmark() Marking failed " + "index %ld, iterations %ld\n", index, iterations); return false; + } fData[index++] = 0; } @@ -332,8 +364,10 @@ TRACE("BitmapBlock::Unmark(): mask: %lx, bits: %lx\n", mask, bits); - if (!force && (bits & mask) != mask) + if (!force && (bits & mask) != mask) { + TRACE("BitmapBlock::Unmark() Marking failed remaining\n"); return false; + } bits &= ~mask; fData[index] = B_HOST_TO_LENDIAN_INT32(bits); @@ -460,7 +494,7 @@ } } - panic("Couldn't find unmarked bit inside an int32 whith value zero!?\n"); + panic("Couldn't find unmarked bit inside an int32 with value zero!?\n"); } @@ -504,6 +538,9 @@ bit = 31; } + TRACE("BitmapBlock::FindPreviousMarked(): index: %lu bit: %lu bits: %lx\n", + index, bit, bits); + for (; bit >= 0; --bit) { // Find the unmarked bit if ((bits >> bit & 1) != 0) { @@ -512,7 +549,7 @@ } } - panic("Couldn't find marked bit inside an int32 whith value different than " + panic("Couldn't find marked bit inside an int32 with value different than " "zero!?\n"); } Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/BlockAllocator.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/BlockAllocator.cpp 2010-10-30 11:45:04 UTC (rev 39202) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/BlockAllocator.cpp 2010-10-30 13:45:01 UTC (rev 39203) @@ -15,12 +15,16 @@ #include "Inode.h" +#undef ASSERT //#define TRACE_EXT2 #ifdef TRACE_EXT2 # define TRACE(x...) dprintf("\33[34mext2:\33[0m " x) +# define ASSERT(x) { if (!(x)) kernel_debugger("ext2: assert failed: " #x "\n"); } #else # define TRACE(x...) ; +# define ASSERT(x) ; #endif +#define ERROR(x...) dprintf("\33[34mext2:\33[0m " x) class AllocationBlockGroup : public TransactionListener { @@ -67,7 +71,7 @@ uint32 fStart; uint32 fNumBits; - uint32 fBitmapBlock; + off_t fBitmapBlock; uint32 fFreeBits; uint32 fFirstFree; @@ -122,14 +126,15 @@ if (status != B_OK) return status; - fBitmapBlock = fGroupDescriptor->BlockBitmap(); + fBitmapBlock = fGroupDescriptor->BlockBitmap(fVolume->Has64bitFeature()); status = ScanFreeRanges(); - if (fGroupDescriptor->FreeBlocks() != fFreeBits) { + if (fGroupDescriptor->FreeBlocks(fVolume->Has64bitFeature()) != fFreeBits) { TRACE("AllocationBlockGroup::Initialize(): Mismatch between counted " "free blocks (%lu) and what is set on the group descriptor " - "(%lu)\n", fFreeBits, (uint32)fGroupDescriptor->FreeBlocks()); + "(%lu)\n", fFreeBits, + fGroupDescriptor->FreeBlocks(fVolume->Has64bitFeature())); return B_BAD_DATA; } @@ -161,6 +166,7 @@ if (start != block.NumBits()) { block.FindNextMarked(end); _AddFreeRange(start, end - start); + ASSERT(block.CheckUnmarked(fLargestStart, fLargestLength)); start = end; } } @@ -191,15 +197,19 @@ if (!block.SetToWritable(transaction, fBitmapBlock)) return B_ERROR; + + TRACE("AllocationBlockGroup::Allocate(): Largest range in %lu-%lu\n", + fLargestStart, fLargestStart + fLargestLength); + ASSERT(block.CheckUnmarked(fLargestStart, fLargestLength)); if (!block.Mark(start, length)) { - TRACE("Failed to allocate blocks from %lu to %lu. Some were " + ERROR("Failed to allocate blocks from %lu to %lu. Some were " "already allocated.\n", start, start + length); return B_ERROR; } fFreeBits -= length; - fGroupDescriptor->SetFreeBlocks((uint16)fFreeBits); + fGroupDescriptor->SetFreeBlocks(fFreeBits, fVolume->Has64bitFeature()); fVolume->WriteBlockGroup(transaction, fBlockGroup); if (start == fLargestStart) { @@ -227,6 +237,10 @@ return B_OK; } + TRACE("AllocationBlockGroup::Allocate(): Largest range in %lu-%lu\n", + fLargestStart, fLargestStart + fLargestLength); + ASSERT(block.CheckUnmarked(fLargestStart, fLargestLength)); + if (fLargestLength < fNumBits / 2) block.FindLargestUnmarkedRange(fLargestStart, fLargestLength); @@ -256,8 +270,12 @@ if (!block.SetToWritable(transaction, fBitmapBlock)) return B_ERROR; + TRACE("AllocationBlockGroup::Free(): Largest range in %lu-%lu\n", + fLargestStart, fLargestStart + fLargestLength); + ASSERT(block.CheckUnmarked(fLargestStart, fLargestLength)); + if (!block.Unmark(start, length)) { - TRACE("Failed to free blocks from %lu to %lu. Some were " + ERROR("Failed to free blocks from %lu to %lu. Some were " "already freed.\n", start, start + length); return B_ERROR; } @@ -279,6 +297,7 @@ uint32 newStart = start; block.FindPreviousMarked(newStart); + newStart++; if (newEnd - newStart > fLargestLength) { fLargestLength = newEnd - newStart; @@ -286,8 +305,12 @@ } } + TRACE("AllocationBlockGroup::Free(): Largest range in %lu-%lu\n", + fLargestStart, fLargestStart + fLargestLength); + ASSERT(block.CheckUnmarked(fLargestStart, fLargestLength)); + fFreeBits += length; - fGroupDescriptor->SetFreeBlocks((uint16)fFreeBits); + fGroupDescriptor->SetFreeBlocks(fFreeBits, fVolume->Has64bitFeature()); fVolume->WriteBlockGroup(transaction, fBlockGroup); return B_OK; @@ -459,17 +482,17 @@ status_t BlockAllocator::AllocateBlocks(Transaction& transaction, uint32 minimum, - uint32 maximum, uint32& blockGroup, uint32& start, uint32& length) + uint32 maximum, uint32& blockGroup, off_t& start, uint32& length) { TRACE("BlockAllocator::AllocateBlocks()\n"); MutexLocker lock(fLock); TRACE("BlockAllocator::AllocateBlocks(): Acquired lock\n"); TRACE("BlockAllocator::AllocateBlocks(): transaction: %ld, min: %lu, " - "max: %lu, block group: %lu, start: %lu, num groups: %lu\n", + "max: %lu, block group: %lu, start: %llu, num groups: %lu\n", transaction.ID(), minimum, maximum, blockGroup, start, fNumGroups); - uint32 bestStart = 0; + off_t bestStart = 0; uint32 bestLength = 0; uint32 bestGroup = 0; @@ -490,7 +513,7 @@ bestGroup = groupNum; TRACE("BlockAllocator::AllocateBlocks(): Found a better " - "range: block group: %lu, %lu-%lu\n", groupNum, + "range: block group: %lu, %llu-%llu\n", groupNum, bestStart, bestStart + bestLength); if (bestLength >= maximum) @@ -520,7 +543,7 @@ bestLength = maximum; TRACE("BlockAllocator::AllocateBlocks(): Selected range: block group %lu, " - "%lu-%lu\n", bestGroup, bestStart, bestStart + bestLength); + "%llu-%llu\n", bestGroup, bestStart, bestStart + bestLength); status_t status = fGroups[bestGroup].Allocate(transaction, bestStart, bestLength); @@ -540,7 +563,7 @@ status_t BlockAllocator::Allocate(Transaction& transaction, Inode* inode, - off_t numBlocks, uint32 minimum, uint32& start, uint32& allocated) + off_t numBlocks, uint32 minimum, off_t& start, uint32& allocated) { if (numBlocks <= 0) return B_ERROR; @@ -617,9 +640,9 @@ status_t -BlockAllocator::Free(Transaction& transaction, uint32 start, uint32 length) +BlockAllocator::Free(Transaction& transaction, off_t start, uint32 length) { - TRACE("BlockAllocator::Free(%lu, %lu)\n", start, length); + TRACE("BlockAllocator::Free(%llu, %lu)\n", start, length); MutexLocker lock(fLock); if (start <= fFirstBlock) { @@ -633,17 +656,19 @@ TRACE("BlockAllocator::Free(): first block: %lu, blocks per group: %lu\n", fFirstBlock, fBlocksPerGroup); - start -= fFirstBlock; - uint32 end = start + length - 1; + //start -= fFirstBlock; + off_t end = start + length - 1; uint32 group = start / fBlocksPerGroup; + if (group >= fNumGroups) + panic("BlockAllocator::Free() group %ld too big (fNumGroups %ld)\n", group, fNumGroups); uint32 lastGroup = end / fBlocksPerGroup; start = start % fBlocksPerGroup; if (group == lastGroup) return fGroups[group].Free(transaction, start, length); - TRACE("BlockAllocator::Free(): Freeing from group %lu: %lu, %lu\n", group, + TRACE("BlockAllocator::Free(): Freeing from group %lu: %llu, %llu\n", group, start, fGroups[group].NumBits() - start); status_t status = fGroups[group].Free(transaction, start, @@ -658,7 +683,7 @@ return status; } - TRACE("BlockAllocator::Free(): Freeing from group %lu: 0-%lu \n", group, + TRACE("BlockAllocator::Free(): Freeing from group %lu: 0-%llu \n", group, end % fBlocksPerGroup); return fGroups[group].Free(transaction, 0, (end + 1) % fBlocksPerGroup); } @@ -674,8 +699,8 @@ AllocationBlockGroup* groups = allocator->fGroups; uint32 numGroups = allocator->fNumGroups - 1; - uint32 freeBlocks = 0; - TRACE("BlockAllocator::_Initialize(): free blocks: %lu\n", freeBlocks); + off_t freeBlocks = 0; + TRACE("BlockAllocator::_Initialize(): free blocks: %llu\n", freeBlocks); for (uint32 i = 0; i < numGroups; ++i) { status_t status = groups[i].Initialize(volume, i, @@ -686,7 +711,7 @@ } freeBlocks += groups[i].FreeBits(); - TRACE("BlockAllocator::_Initialize(): free blocks: %lu\n", freeBlocks); + TRACE("BlockAllocator::_Initialize(): free blocks: %llu\n", freeBlocks); } // Last block group may have less blocks @@ -700,13 +725,13 @@ freeBlocks += groups[numGroups].FreeBits(); - TRACE("BlockAllocator::_Initialize(): free blocks: %lu\n", freeBlocks); + TRACE("BlockAllocator::_Initialize(): free blocks: %llu\n", freeBlocks); mutex_unlock(&allocator->fLock); if (freeBlocks != volume->NumFreeBlocks()) { - TRACE("Counted free blocks (%lu) doesn't match value in the " - "superblock (%lu).\n", freeBlocks, (uint32)volume->NumFreeBlocks()); + TRACE("Counted free blocks (%llu) doesn't match value in the " + "superblock (%llu).\n", freeBlocks, volume->NumFreeBlocks()); return B_BAD_DATA; } Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/BlockAllocator.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/BlockAllocator.h 2010-10-30 11:45:04 UTC (rev 39202) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/BlockAllocator.h 2010-10-30 13:45:01 UTC (rev 39203) @@ -27,11 +27,11 @@ status_t AllocateBlocks(Transaction& transaction, uint32 minimum, uint32 maximum, uint32& blockGroup, - uint32& start, uint32& length); + off_t& start, uint32& length); status_t Allocate(Transaction& transaction, Inode* inode, - off_t numBlocks, uint32 minimum, uint32& start, + off_t numBlocks, uint32 minimum, off_t& start, uint32& length); - status_t Free(Transaction& transaction, uint32 start, + status_t Free(Transaction& transaction, off_t start, uint32 length); uint32 FreeBlocks(); Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/CachedBlock.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/CachedBlock.h 2010-10-30 11:45:04 UTC (rev 39202) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/CachedBlock.h 2010-10-30 13:45:01 UTC (rev 39203) @@ -16,16 +16,16 @@ class CachedBlock { public: CachedBlock(Volume* volume); - CachedBlock(Volume* volume, uint32 block); + CachedBlock(Volume* volume, off_t block); ~CachedBlock(); void Keep(); void Unset(); - const uint8* SetTo(uint32 block); + const uint8* SetTo(off_t block); uint8* SetToWritable(Transaction& transaction, - uint32 block, bool empty = false); - uint8* SetToWritableWithoutTransaction(uint32 block, + off_t block, bool empty = false); + uint8* SetToWritableWithoutTransaction(off_t block, bool empty = false); const uint8* Block() const { return fBlock; } @@ -36,12 +36,12 @@ CachedBlock &operator=(const CachedBlock &); // no implementation - uint8* _SetToWritableEtc(int32 transaction, uint32 block, + uint8* _SetToWritableEtc(int32 transaction, off_t block, bool empty); protected: Volume* fVolume; - uint32 fBlockNumber; + off_t fBlockNumber; uint8* fBlock; }; @@ -60,7 +60,7 @@ inline -CachedBlock::CachedBlock(Volume* volume, uint32 block) +CachedBlock::CachedBlock(Volume* volume, off_t block) : fVolume(volume), fBlockNumber(0), @@ -95,7 +95,7 @@ inline const uint8 * -CachedBlock::SetTo(uint32 block) +CachedBlock::SetTo(off_t block) { Unset(); fBlockNumber = block; @@ -104,20 +104,20 @@ inline uint8* -CachedBlock::SetToWritable(Transaction& transaction, uint32 block, bool empty) +CachedBlock::SetToWritable(Transaction& transaction, off_t block, bool empty) { return _SetToWritableEtc(transaction.ID(), block, empty); } inline uint8* -CachedBlock::SetToWritableWithoutTransaction(uint32 block, bool empty) +CachedBlock::SetToWritableWithoutTransaction(off_t block, bool empty) { return _SetToWritableEtc((int32)-1, block, empty); } inline uint8* -CachedBlock::_SetToWritableEtc(int32 transaction, uint32 block, bool empty) +CachedBlock::_SetToWritableEtc(int32 transaction, off_t block, bool empty) { Unset(); fBlockNumber = block; Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/DataStream.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/DataStream.cpp 2010-10-30 11:45:04 UTC (rev 39202) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/DataStream.cpp 2010-10-30 13:45:01 UTC (rev 39203) @@ -19,6 +19,7 @@ #else # define TRACE(x...) ; #endif +#define ERROR(x...) dprintf("\33[34mext2:\33[0m " x) DataStream::DataStream(Volume* volume, ext2_data_stream* stream, @@ -51,12 +52,12 @@ status_t -DataStream::Enlarge(Transaction& transaction, uint32& numBlocks) +DataStream::Enlarge(Transaction& transaction, off_t& numBlocks) { - TRACE("DataStream::Enlarge(): current size: %lu, target size: %lu\n", + TRACE("DataStream::Enlarge(): current size: %llu, target size: %llu\n", fNumBlocks, numBlocks); - uint32 targetBlocks = numBlocks; + off_t targetBlocks = numBlocks; fWaiting = _BlocksNeeded(numBlocks); numBlocks = fWaiting; @@ -65,42 +66,57 @@ if (fNumBlocks <= kMaxDirect) { status = _AddForDirectBlocks(transaction, targetBlocks); - if (status != B_OK) + if (status != B_OK) { + ERROR("DataStream::Enlarge(): _AddForDirectBlocks() failed\n"); return status; + } - TRACE("DataStream::Enlarge(): current size: %lu, target size: %lu\n", + TRACE("DataStream::Enlarge(): current size: %llu, target size: %llu\n", fNumBlocks, targetBlocks); if (fNumBlocks == targetBlocks) return B_OK; } + TRACE("DataStream::Enlarge(): indirect current size: %llu, target size: %llu\n", + fNumBlocks, targetBlocks); + if (fNumBlocks <= kMaxIndirect) { status = _AddForIndirectBlock(transaction, targetBlocks); - if (status != B_OK) + if (status != B_OK) { + ERROR("DataStream::Enlarge(): _AddForIndirectBlock() failed\n"); return status; + } - TRACE("DataStream::Enlarge(): current size: %lu, target size: %lu\n", + TRACE("DataStream::Enlarge(): current size: %llu, target size: %llu\n", fNumBlocks, targetBlocks); if (fNumBlocks == targetBlocks) return B_OK; } + TRACE("DataStream::Enlarge(): indirect2 current size: %llu, target size: %llu\n", + fNumBlocks, targetBlocks); + if (fNumBlocks <= kMaxDoubleIndirect) { status = _AddForDoubleIndirectBlock(transaction, targetBlocks); - if (status != B_OK) + if (status != B_OK) { + ERROR("DataStream::Enlarge(): _AddForDoubleIndirectBlock() failed\n"); return status; + } - TRACE("DataStream::Enlarge(): current size: %lu, target size: %lu\n", + TRACE("DataStream::Enlarge(): current size: %llu, target size: %llu\n", fNumBlocks, targetBlocks); if (fNumBlocks == targetBlocks) return B_OK; } + TRACE("DataStream::Enlarge(): indirect3 current size: %llu, target size: %llu\n", + fNumBlocks, targetBlocks); + TRACE("DataStream::Enlarge(): allocated: %lu, waiting: %lu\n", fAllocated, fWaiting); @@ -109,25 +125,27 @@ status_t -DataStream::Shrink(Transaction& transaction, uint32& numBlocks) +DataStream::Shrink(Transaction& transaction, off_t& numBlocks) { - TRACE("DataStream::Shrink(): current size: %lu, target size: %lu\n", + TRACE("DataStream::Shrink(): current size: %llu, target size: %llu\n", fNumBlocks, numBlocks); fFreeStart = 0; fFreeCount = 0; fRemovedBlocks = 0; - uint32 oldNumBlocks = fNumBlocks; - uint32 blocksToRemove = fNumBlocks - numBlocks; + off_t oldNumBlocks = fNumBlocks; + off_t blocksToRemove = fNumBlocks - numBlocks; status_t status; if (numBlocks < kMaxDirect) { status = _RemoveFromDirectBlocks(transaction, numBlocks); - if (status != B_OK) + if (status != B_OK) { + ERROR("DataStream::Shrink(): _RemoveFromDirectBlocks() failed\n"); return status; + } if (fRemovedBlocks == blocksToRemove) { fNumBlocks -= fRemovedBlocks; @@ -140,8 +158,10 @@ if (numBlocks < kMaxIndirect) { status = _RemoveFromIndirectBlock(transaction, numBlocks); - if (status != B_OK) + if (status != B_OK) { + ERROR("DataStream::Shrink(): _RemoveFromIndirectBlock() failed\n"); return status; + } if (fRemovedBlocks == blocksToRemove) { fNumBlocks -= fRemovedBlocks; @@ -154,8 +174,10 @@ if (numBlocks < kMaxDoubleIndirect) { status = _RemoveFromDoubleIndirectBlock(transaction, numBlocks); - if (status != B_OK) + if (status != B_OK) { + ERROR("DataStream::Shrink(): _RemoveFromDoubleIndirectBlock() failed\n"); return status; + } if (fRemovedBlocks == blocksToRemove) { fNumBlocks -= fRemovedBlocks; @@ -167,8 +189,10 @@ status = _RemoveFromTripleIndirectBlock(transaction, numBlocks); - if (status != B_OK) + if (status != B_OK) { + ERROR("DataStream::Shrink(): _RemoveFromTripleIndirectBlock() failed\n"); return status; + } fNumBlocks -= fRemovedBlocks; numBlocks = _BlocksNeeded(oldNumBlocks); @@ -178,10 +202,10 @@ uint32 -DataStream::_BlocksNeeded(uint32 numBlocks) +DataStream::_BlocksNeeded(off_t numBlocks) { - TRACE("DataStream::BlocksNeeded(): num blocks %lu\n", numBlocks); - uint32 blocksNeeded = 0; + TRACE("DataStream::BlocksNeeded(): num blocks %llu\n", numBlocks); + off_t blocksNeeded = 0; if (numBlocks > fNumBlocks) { blocksNeeded += numBlocks - fNumBlocks; @@ -214,15 +238,15 @@ } } - TRACE("DataStream::BlocksNeeded(): %lu\n", blocksNeeded); + TRACE("DataStream::BlocksNeeded(): %llu\n", blocksNeeded); return blocksNeeded; } status_t -DataStream::_GetBlock(Transaction& transaction, uint32& block) +DataStream::_GetBlock(Transaction& transaction, uint32& blockNum) { - TRACE("DataStream::_GetBlock(): allocated: %lu, pos: %lu, waiting: %lu\n", + TRACE("DataStream::_GetBlock(): allocated: %lu, pos: %llu, waiting: %lu\n", fAllocated, fAllocatedPos, fWaiting); if (fAllocated == 0) { @@ -232,18 +256,20 @@ status_t status = fVolume->AllocateBlocks(transaction, 1, fWaiting, blockGroup, fAllocatedPos, fAllocated); - if (status != B_OK) + if (status != B_OK) { + ERROR("DataStream::_GetBlock(): AllocateBlocks() failed()\n"); return status; + } fWaiting -= fAllocated; fAllocatedPos += fVolume->BlocksPerGroup() * blockGroup + fFirstBlock; - TRACE("DataStream::_GetBlock(): newAllocated: %lu, newpos: %lu," + TRACE("DataStream::_GetBlock(): newAllocated: %lu, newpos: %llu," "newwaiting: %lu\n", fAllocated, fAllocatedPos, fWaiting); } fAllocated--; - block = fAllocatedPos++; + blockNum = (uint32)fAllocatedPos++; return B_OK; } @@ -258,8 +284,10 @@ if (blockNum == 0) { status_t status = _GetBlock(transaction, blockNum); - if (status != B_OK) + if (status != B_OK) { + ERROR("DataStream::_PrepareBlock() _GetBlock() failed blockNum %ld\n", blockNum); return status; + } *pos = B_HOST_TO_LENDIAN_INT32(blockNum); clear = true; @@ -270,10 +298,10 @@ status_t -DataStream::_AddBlocks(Transaction& transaction, uint32* block, uint32 _count) +DataStream::_AddBlocks(Transaction& transaction, uint32* block, off_t _count) { - uint32 count = _count; - TRACE("DataStream::_AddBlocks(): count: %lu\n", count); + off_t count = _count; + TRACE("DataStream::_AddBlocks(): count: %llu\n", count); while (count > 0) { uint32 blockNum; @@ -292,10 +320,10 @@ status_t -DataStream::_AddBlocks(Transaction& transaction, uint32* block, uint32 start, - uint32 end, int recursion) +DataStream::_AddBlocks(Transaction& transaction, uint32* block, off_t start, + off_t end, int recursion) { - TRACE("DataStream::_AddBlocks(): start: %lu, end %lu, recursion: %d\n", + TRACE("DataStream::_AddBlocks(): start: %llu, end %llu, recursion: %d\n", start, end, recursion); bool clear; @@ -339,8 +367,10 @@ if (start % elementWidth != 0) { status = _AddBlocks(transaction, &childBlock[elementPos], start % elementWidth, elementWidth, recursion); - if (status != B_OK) + if (status != B_OK) { + ERROR("DataStream::_AddBlocks() _AddBlocks() start failed\n"); return status; + } elementPos++; } @@ -348,8 +378,10 @@ while (elementPos < endPos) { status = _AddBlocks(transaction, &childBlock[elementPos], 0, elementWidth, recursion); - if (status != B_OK) + if (status != B_OK) { + ERROR("DataStream::_AddBlocks() _AddBlocks() mid failed\n"); return status; + } elementPos++; } @@ -357,8 +389,10 @@ if (end % elementWidth != 0) { status = _AddBlocks(transaction, &childBlock[elementPos], 0, end % elementWidth, recursion); - if (status != B_OK) + if (status != B_OK) { + ERROR("DataStream::_AddBlocks() _AddBlocks() end failed\n"); return status; + } } return B_OK; @@ -368,7 +402,7 @@ status_t DataStream::_AddForDirectBlocks(Transaction& transaction, uint32 numBlocks) { - TRACE("DataStream::_AddForDirectBlocks(): current size: %lu, target size: " + TRACE("DataStream::_AddForDirectBlocks(): current size: %llu, target size: " "%lu\n", fNumBlocks, numBlocks); uint32* direct = &fStream->direct[fNumBlocks]; uint32 end = numBlocks > kMaxDirect ? kMaxDirect : numBlocks; @@ -380,7 +414,7 @@ status_t DataStream::_AddForIndirectBlock(Transaction& transaction, uint32 numBlocks) { - TRACE("DataStream::_AddForIndirectBlocks(): current size: %lu, target " + TRACE("DataStream::_AddForIndirectBlocks(): current size: %llu, target " "size: %lu\n", fNumBlocks, numBlocks); uint32 *indirect = &fStream->indirect; uint32 start = fNumBlocks - kMaxDirect; @@ -397,7 +431,7 @@ DataStream::_AddForDoubleIndirectBlock(Transaction& transaction, uint32 numBlocks) { - TRACE("DataStream::_AddForDoubleIndirectBlock(): current size: %lu, " + TRACE("DataStream::_AddForDoubleIndirectBlock(): current size: %llu, " "target size: %lu\n", fNumBlocks, numBlocks); uint32 *doubleIndirect = &fStream->double_indirect; uint32 start = fNumBlocks - kMaxIndirect; @@ -414,7 +448,7 @@ DataStream::_AddForTripleIndirectBlock(Transaction& transaction, uint32 numBlocks) { - TRACE("DataStream::_AddForTripleIndirectBlock(): current size: %lu, " + TRACE("DataStream::_AddForTripleIndirectBlock(): current size: %llu, " "target size: %lu\n", fNumBlocks, numBlocks); uint32 *tripleIndirect = &fStream->triple_indirect; uint32 start = fNumBlocks - kMaxDoubleIndirect; @@ -446,9 +480,11 @@ status_t DataStream::_MarkBlockForRemoval(Transaction& transaction, uint32* block) { + TRACE("DataStream::_MarkBlockForRemoval(*(%p) = %lu): free start: %lu, " - "free count: %lu\n", block, *block, fFreeStart, fFreeCount); - uint32 blockNum = B_LENDIAN_TO_HOST_INT32(*block); + "free count: %lu\n", block, B_LENDIAN_TO_HOST_INT32(*block), + fFreeStart, fFreeCount); + uint32 blockNum = B_LENDIAN_TO_HOST_INT32(*block); *block = 0; if (blockNum != fFreeStart + fFreeCount) { @@ -491,11 +527,11 @@ status_t -DataStream::_FreeBlocks(Transaction& transaction, uint32* block, uint32 start, - uint32 end, bool freeParent, int recursion) +DataStream::_FreeBlocks(Transaction& transaction, uint32* block, off_t start, + off_t end, bool freeParent, int recursion) { // TODO: Designed specifically for shrinking. Perhaps make it more general? - TRACE("DataStream::_FreeBlocks(%p, %lu, %lu, %c, %d)\n", + TRACE("DataStream::_FreeBlocks(%p, %llu, %llu, %c, %d)\n", block, start, end, freeParent ? 't' : 'f', recursion); uint32 blockNum = B_LENDIAN_TO_HOST_INT32(*block); @@ -567,10 +603,10 @@ status_t DataStream::_RemoveFromDirectBlocks(Transaction& transaction, uint32 numBlocks) { - TRACE("DataStream::_RemoveFromDirectBlocks(): current size: %lu, " + TRACE("DataStream::_RemoveFromDirectBlocks(): current size: %llu, " "target size: %lu\n", fNumBlocks, numBlocks); uint32* direct = &fStream->direct[numBlocks]; - uint32 end = fNumBlocks > kMaxDirect ? kMaxDirect : fNumBlocks; + off_t end = fNumBlocks > kMaxDirect ? kMaxDirect : fNumBlocks; return _FreeBlocks(transaction, direct, end - numBlocks); } @@ -579,11 +615,11 @@ status_t DataStream::_RemoveFromIndirectBlock(Transaction& transaction, uint32 numBlocks) { - TRACE("DataStream::_RemoveFromIndirectBlock(): current size: %lu, " + TRACE("DataStream::_RemoveFromIndirectBlock(): current size: %llu, " "target size: %lu\n", fNumBlocks, numBlocks); uint32* indirect = &fStream->indirect; - uint32 start = numBlocks <= kMaxDirect ? 0 : numBlocks - kMaxDirect; - uint32 end = fNumBlocks - kMaxDirect; + off_t start = numBlocks <= kMaxDirect ? 0 : numBlocks - kMaxDirect; + off_t end = fNumBlocks - kMaxDirect; if (end > kIndirectsPerBlock) end = kIndirectsPerBlock; @@ -598,11 +634,11 @@ DataStream::_RemoveFromDoubleIndirectBlock(Transaction& transaction, uint32 numBlocks) { - TRACE("DataStream::_RemoveFromDoubleIndirectBlock(): current size: %lu, " + TRACE("DataStream::_RemoveFromDoubleIndirectBlock(): current size: %llu, " "target size: %lu\n", fNumBlocks, numBlocks); uint32* doubleIndirect = &fStream->double_indirect; - uint32 start = numBlocks <= kMaxIndirect ? 0 : numBlocks - kMaxIndirect; - uint32 end = fNumBlocks - kMaxIndirect; + off_t start = numBlocks <= kMaxIndirect ? 0 : numBlocks - kMaxIndirect; + off_t end = fNumBlocks - kMaxIndirect; [... truncated: 880 lines follow ...]