From 2a8ae7fb92985550913ac2eb04bfb8513d40f886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 16 Feb 2010 08:34:55 +0000 Subject: [PATCH] * 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). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35490 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/file_systems/bfs/BPlusTree.cpp | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp b/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp index 9b23b00f37..38c4b699ad 100644 --- a/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp +++ b/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp @@ -227,7 +227,7 @@ CachedNode::InternalSetTo(Transaction* transaction, off_t offset) 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 @@ CachedNode::Allocate(Transaction& transaction, bplustree_node** _node, 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 @@ BPlusTree::SetTo(Transaction& transaction, Inode* stream, int32 nodeSize) = 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);