[haiku-commits] BRANCH ahenriksson-github.fixes - src/add-ons/kernel/file_systems/bfs

  • From: ahenriksson-github.fixes <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 18 Jul 2012 15:49:17 +0200 (CEST)

added 2 changesets to branch 'refs/remotes/ahenriksson-github/fixes'
old head: 86ca32ad0dca509e4ba4d22e9c0bf84810ce7891
new head: 38ccbefd64f652b8993f83c901156d515f44356d

----------------------------------------------------------------------------

cda6263: A duplicate array with a single value is not allowed
  
  Such arrays could be created by the BFS code between hrev43837 and
  hrev43924, and cause the array to not be free'd when the entry is
  removed.
  
  The check in _InsertDuplicate() is not changed, as doing an insertion
  will actually repair this problem.
  
  Potentially, the code could be modified to handle this state instead,
  but since checkfs can fix it, it doesn't seem necessary.

38ccbef: CheckBlocks() calculated the group block incorrectly

                                      [ ahenriksson <sausageboy@xxxxxxxxx> ]

----------------------------------------------------------------------------

2 files changed, 6 insertions(+), 4 deletions(-)
src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp  |    4 ++--
.../kernel/file_systems/bfs/BlockAllocator.cpp     |    6 ++++--

############################################################################

Commit:      cda62633805e6a77ec30a0f11436b54f897375e7

Author:      ahenriksson <sausageboy@xxxxxxxxx>
Date:        Tue Jul 17 19:11:18 2012 UTC

A duplicate array with a single value is not allowed

Such arrays could be created by the BFS code between hrev43837 and
hrev43924, and cause the array to not be free'd when the entry is
removed.

The check in _InsertDuplicate() is not changed, as doing an insertion
will actually repair this problem.

Potentially, the code could be modified to handle this state instead,
but since checkfs can fix it, it doesn't seem necessary.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp 
b/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp
index 90972f3..51b896a 100644
--- a/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp
+++ b/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp
@@ -1782,7 +1782,7 @@ BPlusTree::_RemoveDuplicate(Transaction& transaction,
                        bplustree_node::FragmentIndex(oldValue));
                int32 arrayCount = array->Count();
 
-               if (arrayCount > NUM_FRAGMENT_VALUES || arrayCount < 1) {
+               if (arrayCount > NUM_FRAGMENT_VALUES || arrayCount <= 1) {
                        FATAL(("_RemoveDuplicate: Invalid array[%d] size in 
fragment %"
                                B_PRIdOFF " == %" B_PRId32 ", inode %" 
B_PRIdOFF "!\n",
                                (int)bplustree_node::FragmentIndex(oldValue), 
duplicateOffset,
@@ -2361,7 +2361,7 @@ BPlusTree::_ValidateChildren(TreeCheck& check, uint32 
level, off_t offset,
                                }
                                int32 arrayCount = array->Count();
 
-                               if (arrayCount < 1 || arrayCount > maxSize) {
+                               if (arrayCount <= 1 || arrayCount > maxSize) {
                                        dprintf("inode %" B_PRIdOFF ": 
duplicate at %" B_PRIdOFF
                                                " has invalid array size %" 
B_PRId32 "!\n",
                                                fStream->ID(), duplicateOffset, 
arrayCount);

############################################################################

Commit:      38ccbefd64f652b8993f83c901156d515f44356d

Author:      ahenriksson <sausageboy@xxxxxxxxx>
Date:        Tue Jul 17 19:23:22 2012 UTC

CheckBlocks() calculated the group block incorrectly

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp 
b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp
index 4d23373..bc0f217 100644
--- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp
+++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp
@@ -1699,10 +1699,12 @@ BlockAllocator::CheckBlocks(off_t start, off_t length, 
bool allocated)
        if (start < 0 || start + length > fVolume->NumBlocks())
                return B_BAD_VALUE;
 
-       uint32 group = start >> fVolume->AllocationGroupShift();
-       uint32 groupBlock = start / (fVolume->BlockSize() << 3);
+       int32 group = start >> fVolume->AllocationGroupShift();
+       uint32 bitmapBlock = start / (fVolume->BlockSize() << 3);
        uint32 blockOffset = start % (fVolume->BlockSize() << 3);
 
+       uint32 groupBlock = bitmapBlock % fBlocksPerGroup;
+
        AllocationBlock cached(fVolume);
 
        while (group < fNumGroups && groupBlock < fGroups[group].NumBlocks()


Other related posts: