From 25a55b41c7945b9d6e0c6b70b051fa10ec81ec03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sun, 31 Oct 2010 19:29:31 +0000 Subject: [PATCH] * more cleanup * more fixes in BitmapBlock::FindNextMarked() and BitmapBlock::FindPreviousMarked() git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39242 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/file_systems/ext2/BitmapBlock.cpp | 30 +++++++++++-------- .../kernel/file_systems/ext2/Inode.cpp | 2 +- .../kernel/file_systems/ext2/Journal.cpp | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/add-ons/kernel/file_systems/ext2/BitmapBlock.cpp b/src/add-ons/kernel/file_systems/ext2/BitmapBlock.cpp index 8336889654..8f9bb570f6 100644 --- a/src/add-ons/kernel/file_systems/ext2/BitmapBlock.cpp +++ b/src/add-ons/kernel/file_systems/ext2/BitmapBlock.cpp @@ -403,6 +403,7 @@ BitmapBlock::FindNextMarked(uint32& pos) "bits: %lX\n", index, bit, mask, bits); bits = bits & ~mask; + uint32 maxBit = 32; if (bits == 0) { // Find a block of 32 bits that has a marked bit @@ -414,18 +415,23 @@ BitmapBlock::FindNextMarked(uint32& pos) } while (index < maxIndex && data[index] == 0); if (index >= maxIndex) { - // Not found - TRACE("BitmapBlock::FindNextMarked(): reached end of block, num " - "bits: %lu\n", fNumBits); - pos = fNumBits; - return; + maxBit = fNumBits & 0x1F; + + if (maxBit == 0) { + // Not found + TRACE("BitmapBlock::FindNextMarked(): reached end of block, " + "num bits: %lu\n", fNumBits); + pos = fNumBits; + return; + } + maxBit++; } bits = B_LENDIAN_TO_HOST_INT32(data[index]); bit = 0; } - for (; bit < 32; ++bit) { + for (; bit < maxBit; ++bit) { // Find the marked bit if ((bits >> bit & 1) != 0) { pos = index << 5 | bit; @@ -520,18 +526,18 @@ BitmapBlock::FindPreviousMarked(uint32& pos) uint32 index = pos >> 5; int32 bit = pos & 0x1F; - uint32 mask = (1 << (bit + 1)) - 1; + uint32 mask = (1 << bit) - 1; uint32 bits = B_LENDIAN_TO_HOST_INT32(data[index]); bits = bits & mask; - TRACE("BitmapBlock::FindPreviousMarked(): index: %lu, bit: %lu\n", index, - bit); + TRACE("BitmapBlock::FindPreviousMarked(): index: %lu bit: %lu bits: %lx\n", + index, bit, bits); if (bits == 0) { // Find an block of 32 bits that has a marked bit do { index--; - } while (data[index] == 0 && index >= 0); + } while (data[index] == 0 && index > 0); bits = B_LENDIAN_TO_HOST_INT32(data[index]); if (bits == 0) { @@ -543,11 +549,11 @@ BitmapBlock::FindPreviousMarked(uint32& pos) bit = 31; } - TRACE("BitmapBlock::FindPreviousMarked(): index: %lu bit: %lu bits: %lx\n", + TRACE("BitmapBlock::FindPreviousMarked(): index: %lu bit: %lu bits: %lx\n", index, bit, bits); for (; bit >= 0; --bit) { - // Find the unmarked bit + // Find the marked bit if ((bits >> bit & 1) != 0) { pos = index << 5 | bit; return; diff --git a/src/add-ons/kernel/file_systems/ext2/Inode.cpp b/src/add-ons/kernel/file_systems/ext2/Inode.cpp index be9994cbe1..e9e2c65c2b 100644 --- a/src/add-ons/kernel/file_systems/ext2/Inode.cpp +++ b/src/add-ons/kernel/file_systems/ext2/Inode.cpp @@ -938,7 +938,7 @@ Inode::_ShrinkDataStream(Transaction& transaction, off_t size) if (size > minSize) { // No need to allocate more blocks TRACE("Inode::_ShrinkDataStream(): No need to allocate more blocks\n"); - TRACE("Inode::_ShrinkDataStream(): Setting size to %ld\n", (long)size); + TRACE("Inode::_ShrinkDataStream(): Setting size to %lld\n", size); fNode.SetSize(size); return B_OK; } diff --git a/src/add-ons/kernel/file_systems/ext2/Journal.cpp b/src/add-ons/kernel/file_systems/ext2/Journal.cpp index 9f7f573b31..80a10d959e 100644 --- a/src/add-ons/kernel/file_systems/ext2/Journal.cpp +++ b/src/add-ons/kernel/file_systems/ext2/Journal.cpp @@ -489,7 +489,7 @@ Journal::_WriteTransactionToLog() if (size > FreeLogBlocks()) { panic("Transaction fits, but sync didn't result in enough" "free space.\n\tGot %ld when at least %ld was expected.", - (long)FreeLogBlocks(), (long)size); + FreeLogBlocks(), size); } }