From 3489b30126531618cc12a3a7b7c552386ae61c46 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 27 Dec 2005 21:33:11 +0000 Subject: [PATCH] Fixed some boot loader PPC BFS issues: * bfs_inode must be packed, otherwise the structure is larger due to different alignment requirements. * The off_t array returned by bfs_inode::Values() is in on-disk endianess. This was ignored in some places. Hope I squashed all occurences. Those fixes should probably be back-ported to the kernel add-on, too. Will do that when I get to that point in the kernel, unless someone beats me to it. The PPC boot loader does at least find the kernel on a BFS volume now. Haven't dared to let it be loaded yet. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15686 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../boot/loader/file_systems/bfs/BPlusTree.cpp | 12 +++++++----- src/system/boot/loader/file_systems/bfs/BPlusTree.h | 2 +- .../boot/loader/file_systems/bfs/Directory.cpp | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/system/boot/loader/file_systems/bfs/BPlusTree.cpp b/src/system/boot/loader/file_systems/bfs/BPlusTree.cpp index 7e2cf779f5..8e7d2d2e68 100644 --- a/src/system/boot/loader/file_systems/bfs/BPlusTree.cpp +++ b/src/system/boot/loader/file_systems/bfs/BPlusTree.cpp @@ -386,7 +386,8 @@ BPlusTree::FindFreeDuplicateFragment(bplustree_node *node, CachedNode *cached, o if (bplustree_node::LinkType(values[i]) != BPLUSTREE_DUPLICATE_FRAGMENT) continue; - bplustree_node *fragment = cached->SetTo(bplustree_node::FragmentOffset(values[i]), false); + bplustree_node *fragment = cached->SetTo(bplustree_node::FragmentOffset( + BFS_ENDIAN_TO_HOST_INT64(values[i])), false); if (fragment == NULL) { FATAL(("Could not get duplicate fragment at %Ld\n",values[i])); continue; @@ -398,7 +399,8 @@ BPlusTree::FindFreeDuplicateFragment(bplustree_node *node, CachedNode *cached, o duplicate_array *array = fragment->FragmentAt(j); if (array->count == 0) { - *_offset = bplustree_node::FragmentOffset(values[i]); + *_offset = bplustree_node::FragmentOffset( + BFS_ENDIAN_TO_HOST_INT64(values[i])); *_fragment = fragment; *_index = j; return B_OK; @@ -444,7 +446,7 @@ BPlusTree::Find(const uint8 *key, uint16 keyLength, off_t *_value) if (node->OverflowLink() == BPLUSTREE_NULL) { if (status == B_OK && _value != NULL) - *_value = node->Values()[keyIndex]; + *_value = BFS_ENDIAN_TO_HOST_INT64(node->Values()[keyIndex]); return status; } else if (nextOffset == nodeOffset) @@ -503,7 +505,7 @@ TreeIterator::Goto(int8 to) || (uint32)node->Values() > (uint32)node + fTree->fNodeSize - 8 * node->NumKeys()) return B_ERROR; - nextOffset = node->Values()[0]; + nextOffset = BFS_ENDIAN_TO_HOST_INT64(node->Values()[0]); } if (nextOffset == nodeOffset) break; @@ -639,7 +641,7 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, uint16 maxL } *keyLength = length; - off_t offset = node->Values()[fCurrentKey]; + off_t offset = BFS_ENDIAN_TO_HOST_INT64(node->Values()[fCurrentKey]); #ifdef BPLUSTREE_SUPPORTS_DUPLICATES // duplicate fragments? diff --git a/src/system/boot/loader/file_systems/bfs/BPlusTree.h b/src/system/boot/loader/file_systems/bfs/BPlusTree.h index 98ba5cb49d..cb58b462d0 100644 --- a/src/system/boot/loader/file_systems/bfs/BPlusTree.h +++ b/src/system/boot/loader/file_systems/bfs/BPlusTree.h @@ -96,7 +96,7 @@ struct bplustree_node { static inline off_t FragmentOffset(off_t link); static inline uint32 FragmentIndex(off_t link); #endif -}; +} __attribute__ ((__packed__)); //#define BPLUSTREE_NODE 0 #define BPLUSTREE_DUPLICATE_NODE 2 diff --git a/src/system/boot/loader/file_systems/bfs/Directory.cpp b/src/system/boot/loader/file_systems/bfs/Directory.cpp index d2134e2271..8b770f5b22 100644 --- a/src/system/boot/loader/file_systems/bfs/Directory.cpp +++ b/src/system/boot/loader/file_systems/bfs/Directory.cpp @@ -89,6 +89,8 @@ Directory::Lookup(const char *name, bool traverseLinks) return NULL; Node *node = Stream::NodeFactory(fStream.GetVolume(), id); + if (!node) + return NULL; if (S_ISLNK(node->Type())) { // the node is a symbolic link, so we have to resolve the path