diff --git a/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp b/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp index c64c07c3c4..0f870e9aeb 100644 --- a/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp +++ b/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp @@ -1055,7 +1055,7 @@ BPlusTree::_FindKey(const bplustree_node* node, const uint8* key, return B_ENTRY_NOT_FOUND; } - off_t* values = node->Values(); + Unaligned* values = node->Values(); int16 saveIndex = -1; // binary search in the key array @@ -2934,7 +2934,7 @@ bplustree_node::KeyAt(int32 index, uint16* keyLength) const return NULL; uint8* keyStart = Keys(); - uint16* keyLengths = KeyLengths(); + Unaligned* keyLengths = KeyLengths(); *keyLength = BFS_ENDIAN_TO_HOST_INT16(keyLengths[index]) - (index != 0 ? BFS_ENDIAN_TO_HOST_INT16(keyLengths[index - 1]) : 0); @@ -3008,7 +3008,7 @@ bplustree_node::CheckIntegrity(uint32 nodeSize) const } if (Values()[i] == -1) { dprintf("invalid node %p, value %d: %" B_PRIdOFF ": values " - "corrupted\n", this, (int)i, Values()[i]); + "corrupted\n", this, (int)i, Values()[i].value); return B_BAD_DATA; } } diff --git a/src/add-ons/kernel/file_systems/bfs/BPlusTree.h b/src/add-ons/kernel/file_systems/bfs/BPlusTree.h index 24bab65990..38444ca216 100644 --- a/src/add-ons/kernel/file_systems/bfs/BPlusTree.h +++ b/src/add-ons/kernel/file_systems/bfs/BPlusTree.h @@ -74,6 +74,18 @@ enum bplustree_types { struct duplicate_array; +template +struct __attribute__((packed)) Unaligned { + T value; + + Unaligned& operator=(const T& newValue) + { + value = newValue; return *this; + } + operator T() const { return value; } +}; + + struct bplustree_node { int64 left_link; int64 right_link; @@ -97,8 +109,8 @@ struct bplustree_node { { return BFS_ENDIAN_TO_HOST_INT16( all_key_length); } - inline uint16* KeyLengths() const; - inline off_t* Values() const; + inline Unaligned* KeyLengths() const; + inline Unaligned* Values() const; inline uint8* Keys() const; inline int32 Used() const; uint8* KeyAt(int32 index, uint16* keyLength) const; @@ -559,18 +571,19 @@ bplustree_header::IsValidLink(off_t link) const // #pragma mark - bplustree_node inline functions -inline uint16* +inline Unaligned* bplustree_node::KeyLengths() const { - return (uint16*)(((char*)this) + key_align(sizeof(bplustree_node) + return (Unaligned*)(((char*)this) + key_align(sizeof(bplustree_node) + AllKeyLength())); } -inline off_t* +inline Unaligned* bplustree_node::Values() const { - return (off_t*)((char*)KeyLengths() + NumKeys() * sizeof(uint16)); + return (Unaligned*)( + (char*)KeyLengths() + NumKeys() * sizeof(uint16)); }