From 4359b745017b663fa0e1e28be2212ccbd90f2c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sun, 9 Jan 2011 18:51:00 +0000 Subject: [PATCH] * finding marked or unmarked bit in the last double word didn't work, we need to take start pos into account. Should fix #7079. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40182 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/file_systems/ext2/BitmapBlock.cpp | 125 +++++++++--------- .../kernel/file_systems/ext2/BitmapBlock.h | 1 + 2 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/add-ons/kernel/file_systems/ext2/BitmapBlock.cpp b/src/add-ons/kernel/file_systems/ext2/BitmapBlock.cpp index d8ec0b4d37..78cf17ef79 100644 --- a/src/add-ons/kernel/file_systems/ext2/BitmapBlock.cpp +++ b/src/add-ons/kernel/file_systems/ext2/BitmapBlock.cpp @@ -25,7 +25,8 @@ BitmapBlock::BitmapBlock(Volume* volume, uint32 numBits) CachedBlock(volume), fData(NULL), fReadOnlyData(NULL), - fNumBits(numBits) + fNumBits(numBits), + fMaxIndex(fNumBits >> 5) { TRACE("BitmapBlock::BitmapBlock(): num bits: %lu\n", fNumBits); } @@ -403,47 +404,46 @@ BitmapBlock::FindNextMarked(uint32& pos) uint32 index = pos >> 5; uint32 bit = pos & 0x1F; + uint32 maxBit = 32; - uint32 mask = (1 << bit) - 1; + uint32 mask = ~((1 << bit) - 1); uint32 bits = B_LENDIAN_TO_HOST_INT32(data[index]); TRACE("BitmapBlock::FindNextMarked(): index: %lu, bit: %lu, mask: %lX, " "bits: %lX\n", index, bit, mask, bits); - bits &= ~mask; - uint32 maxBit = 32; - - if (bits == 0) { - // Find a block of 32 bits that has a marked bit - uint32 maxIndex = fNumBits >> 5; - TRACE("BitmapBlock::FindNextMarked(): max index: %lu\n", maxIndex); - + bits &= mask; + if (bits == 0 && index < fMaxIndex) { + // Find a 32 bits block that has a marked bit do { index++; - } while (index < maxIndex && data[index] == 0); - - if (index >= maxIndex) { - maxBit = fNumBits & 0x1F; - - if (maxBit == 0) { - // Not found - TRACE("BitmapBlock::FindNextMarked(): reached end of block, " - "num bits: %lu\n", fNumBits); - pos = fNumBits; - return; - } - bits = B_LENDIAN_TO_HOST_INT32(data[maxIndex]); - mask = (1 << maxBit) - 1; - if ((bits & mask) == 0) { - pos = fNumBits; - return; - } - maxBit++; - } else - bits = B_LENDIAN_TO_HOST_INT32(data[index]); + } while (index < fMaxIndex && data[index] == 0); bit = 0; + mask = 0xffffffff; } + if (index >= fMaxIndex) { + maxBit = fNumBits & 0x1F; + + if (maxBit == 0) { + // Not found + TRACE("BitmapBlock::FindNextMarked(): reached end of block, " + "num bits: %lu\n", fNumBits); + pos = fNumBits; + return; + } + bits = B_LENDIAN_TO_HOST_INT32(data[fMaxIndex]); + mask &= (1 << maxBit) - 1; + if ((bits & mask) == 0) { + TRACE("BitmapBlock::FindNextMarked(): reached end of block, " + "num bits: %lu\n", fNumBits); + pos = fNumBits; + return; + } + maxBit++; + } else + bits = B_LENDIAN_TO_HOST_INT32(data[index]); + for (; bit < maxBit; ++bit) { // Find the marked bit if ((bits >> bit & 1) != 0) { @@ -474,47 +474,47 @@ BitmapBlock::FindNextUnmarked(uint32& pos) uint32 index = pos >> 5; uint32 bit = pos & 0x1F; + uint32 maxBit = 32; - uint32 mask = (1 << bit) - 1; + uint32 mask = ~((1 << bit) - 1); uint32 bits = B_LENDIAN_TO_HOST_INT32(data[index]); TRACE("BitmapBlock::FindNextUnmarked(): index: %lu, bit: %lu, mask: %lX, " "bits: %lX\n", index, bit, mask, bits); - bits &= ~mask; - uint32 maxBit = 32; - - if (bits == ~mask) { - // Find an block of 32 bits that has a unmarked bit - uint32 maxIndex = fNumBits >> 5; - TRACE("BitmapBlock::FindNextUnmarked(): max index: %lu\n", maxIndex); + bits &= mask; + if (bits == mask && index < fMaxIndex) { + // Find a 32 bits block that has an unmarked bit do { index++; - } while (index < maxIndex && data[index] == 0xFFFFFFFF); - - if (index >= maxIndex) { - maxBit = fNumBits & 0x1F; - - if (maxBit == 0) { - // Not found - TRACE("BitmapBlock::FindNextUnmarked(): reached end of block, " - "num bits: %lu\n", fNumBits); - pos = fNumBits; - return; - } - bits = B_LENDIAN_TO_HOST_INT32(data[maxIndex]); - mask = (1 << maxBit) - 1; - if ((bits & mask) == mask) { - pos = fNumBits; - return; - } - maxBit++; - } else - bits = B_LENDIAN_TO_HOST_INT32(data[index]); + } while (index < fMaxIndex && data[index] == 0xFFFFFFFF); bit = 0; + mask = 0xffffffff; } + if (index >= fMaxIndex) { + maxBit = fNumBits & 0x1F; + + if (maxBit == 0) { + // Not found + TRACE("BitmapBlock::FindNextUnmarked(): reached end of block, " + "num bits: %lu\n", fNumBits); + pos = fNumBits; + return; + } + bits = B_LENDIAN_TO_HOST_INT32(data[fMaxIndex]); + mask &= (1 << maxBit) - 1; + if ((bits & mask) == mask) { + TRACE("BitmapBlock::FindNextUnmarked(): reached end of block, " + "num bits: %lu\n", fNumBits); + pos = fNumBits; + return; + } + maxBit++; + } else + bits = B_LENDIAN_TO_HOST_INT32(data[index]); + TRACE("BitmapBlock::FindNextUnmarked(): searching bit at pos %lu\n", bit); for (; bit < maxBit; ++bit) { // Find the unmarked bit @@ -594,14 +594,13 @@ BitmapBlock::FindLargestUnmarkedRange(uint32& start, uint32& length) return; uint32 wordSpan = length >> 5; - uint32 lastIndex = fNumBits >> 5; uint32 startIndex = 0; uint32 index = 0; uint32 bits = B_LENDIAN_TO_HOST_INT32(data[0]); TRACE("BitmapBlock::FindLargestUnmarkedRange(): word span: %lu, last " "index: %lu, start index: %lu, index: %lu, bits: %lX, start: %lu, " - "length: %lu\n", wordSpan, lastIndex, startIndex, index, bits, start, + "length: %lu\n", wordSpan, fMaxIndex, startIndex, index, bits, start, length); if (wordSpan == 0) { @@ -640,7 +639,7 @@ BitmapBlock::FindLargestUnmarkedRange(uint32& start, uint32& length) bits = B_LENDIAN_TO_HOST_INT32(data[index]); } - for (; index < lastIndex; ++index) { + for (; index < fMaxIndex; ++index) { bits = B_LENDIAN_TO_HOST_INT32(data[index]); if (bits != 0) { diff --git a/src/add-ons/kernel/file_systems/ext2/BitmapBlock.h b/src/add-ons/kernel/file_systems/ext2/BitmapBlock.h index 3086244eed..fd5624dafb 100644 --- a/src/add-ons/kernel/file_systems/ext2/BitmapBlock.h +++ b/src/add-ons/kernel/file_systems/ext2/BitmapBlock.h @@ -43,6 +43,7 @@ protected: const uint32* fReadOnlyData; uint32 fNumBits; + uint32 fMaxIndex; }; #endif // BITMAPBLOCK_H