[haiku-commits] r35490 - haiku/trunk/src/add-ons/kernel/file_systems/bfs

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 16 Feb 2010 09:34:55 +0100 (CET)

Author: axeld
Date: 2010-02-16 09:34:55 +0100 (Tue, 16 Feb 2010)
New Revision: 35490
Changeset: http://dev.haiku-os.org/changeset/35490/haiku
Ticket: http://dev.haiku-os.org/ticket/5410

Modified:
   haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp
Log:
* CachedNode::SetToWritable() already needs the updated header, so we need to
  Unset() the header in Allocate() before calling it. This fixes bug #5410.
* CachedNode::Allocate() does not need to revert its changes; the transaction
  will take care of that. However, BPlusTree::fHeader is currently not correctly
  maintained if a transaction fails (working on that now).


Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp
===================================================================
--- haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp       
2010-02-16 08:16:17 UTC (rev 35489)
+++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp       
2010-02-16 08:34:55 UTC (rev 35490)
@@ -227,7 +227,7 @@
                        fWritable = false;
                }
 
-               if (block) {
+               if (block != NULL) {
                        // The node is somewhere in that block...
                        // (confusing offset calculation)
                        fNode = (bplustree_node*)(block + offset
@@ -324,18 +324,17 @@
        header->maximum_size = HOST_ENDIAN_TO_BFS_INT64(header->MaximumSize()
                + fTree->fNodeSize);
 
-       if (SetToWritable(transaction, offset, false) != NULL) {
-               fNode->Initialize();
+       cached.Unset();
+               // SetToWritable() below needs the new values in the tree's 
header
 
-               *_offset = offset;
-               *_node = fNode;
-               return B_OK;
-       }
+       if (SetToWritable(transaction, offset, false) == NULL)
+               RETURN_ERROR(B_ERROR);
 
-       // revert header size to old value
-       header->maximum_size = HOST_ENDIAN_TO_BFS_INT64(header->MaximumSize()
-               - fTree->fNodeSize);
-       RETURN_ERROR(B_ERROR);
+       fNode->Initialize();
+
+       *_offset = offset;
+       *_node = fNode;
+       return B_OK;
 }
 
 
@@ -423,7 +422,7 @@
                = HOST_ENDIAN_TO_BFS_INT64((uint64)BPLUSTREE_NULL);
        header->maximum_size = HOST_ENDIAN_TO_BFS_INT64(nodeSize * 2);
 
-       memcpy(&fHeader, header, sizeof(bplustree_header));
+       cached.Unset();
 
        // initialize b+tree root node
        cached.SetToWritable(transaction, fHeader.RootNode(), false);


Other related posts:

  • » [haiku-commits] r35490 - haiku/trunk/src/add-ons/kernel/file_systems/bfs - axeld