Fixed endian issues - it now does work with big endian BFS disks as well.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4714 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2003-09-16 14:36:40 +00:00
parent d81d3bfa4c
commit fd5b021f86
3 changed files with 15 additions and 11 deletions
@@ -206,9 +206,12 @@ BPlusTree::TypeCodeToKeyType(type_code code)
case B_STRING_TYPE: case B_STRING_TYPE:
return BPLUSTREE_STRING_TYPE; return BPLUSTREE_STRING_TYPE;
case B_INT32_TYPE: case B_INT32_TYPE:
case B_SSIZE_T_TYPE:
return BPLUSTREE_INT32_TYPE; return BPLUSTREE_INT32_TYPE;
case B_UINT32_TYPE: case B_UINT32_TYPE:
case B_SIZE_T_TYPE:
return BPLUSTREE_UINT32_TYPE; return BPLUSTREE_UINT32_TYPE;
case B_OFF_T_TYPE:
case B_INT64_TYPE: case B_INT64_TYPE:
return BPLUSTREE_INT64_TYPE; return BPLUSTREE_INT64_TYPE;
case B_UINT64_TYPE: case B_UINT64_TYPE:
@@ -316,7 +319,7 @@ BPlusTree::FindKey(bplustree_node *node, const uint8 *key, uint16 keyLength, uin
if (index) if (index)
*index = i; *index = i;
if (next) if (next)
*next = values[i]; *next = BFS_ENDIAN_TO_HOST_INT64(values[i]);
return B_OK; return B_OK;
} }
} }
@@ -327,7 +330,7 @@ BPlusTree::FindKey(bplustree_node *node, const uint8 *key, uint16 keyLength, uin
if (saveIndex == node->NumKeys()) if (saveIndex == node->NumKeys())
*next = node->OverflowLink(); *next = node->OverflowLink();
else else
*next = values[saveIndex]; *next = BFS_ENDIAN_TO_HOST_INT64(values[saveIndex]);
} }
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
} }
@@ -727,7 +730,7 @@ TreeIterator::SkipDuplicates()
void void
bplustree_node::Initialize() bplustree_node::Initialize()
{ {
left_link = right_link = overflow_link = BPLUSTREE_NULL; left_link = right_link = overflow_link = HOST_ENDIAN_TO_BFS_INT64((uint64)BPLUSTREE_NULL);
all_key_count = 0; all_key_count = 0;
all_key_length = 0; all_key_length = 0;
} }
@@ -736,15 +739,16 @@ bplustree_node::Initialize()
uint8 * uint8 *
bplustree_node::KeyAt(int32 index, uint16 *keyLength) const bplustree_node::KeyAt(int32 index, uint16 *keyLength) const
{ {
if (index < 0 || index > all_key_count) if (index < 0 || index > NumKeys())
return NULL; return NULL;
uint8 *keyStart = Keys(); uint8 *keyStart = Keys();
uint16 *keyLengths = KeyLengths(); uint16 *keyLengths = KeyLengths();
*keyLength = keyLengths[index] - (index != 0 ? keyLengths[index - 1] : 0); *keyLength = BFS_ENDIAN_TO_HOST_INT16(keyLengths[index])
- (index != 0 ? BFS_ENDIAN_TO_HOST_INT16(keyLengths[index - 1]) : 0);
if (index > 0) if (index > 0)
keyStart += keyLengths[index - 1]; keyStart += BFS_ENDIAN_TO_HOST_INT16(keyLengths[index - 1]);
return keyStart; return keyStart;
} }
@@ -762,7 +766,7 @@ bplustree_node::CountDuplicates(off_t offset, bool isFragment) const
return ((off_t *)this)[fragment]; return ((off_t *)this)[fragment];
} }
return overflow_link; return OverflowLink();
} }
@@ -294,8 +294,8 @@ Stream::ReadAt(off_t pos, uint8 *buffer, size_t *_length)
// pos % block_size == (pos - offset) % block_size, offset % block_size == 0 // pos % block_size == (pos - offset) % block_size, offset % block_size == 0
if (pos % blockSize != 0) { if (pos % blockSize != 0) {
run.start += (pos - offset) / blockSize; run.start = HOST_ENDIAN_TO_BFS_INT16(run.Start() + ((pos - offset) >> blockShift));
run.length -= (pos - offset) / blockSize; run.length = HOST_ENDIAN_TO_BFS_INT16(run.Length() - ((pos - offset) >> blockShift));
CachedBlock cached(fVolume, run); CachedBlock cached(fVolume, run);
if ((block = cached.Block()) == NULL) { if ((block = cached.Block()) == NULL) {
@@ -45,8 +45,8 @@ class Volume {
uint32 AllocationGroupShift() const { return fSuperBlock.AllocationGroupShift(); } uint32 AllocationGroupShift() const { return fSuperBlock.AllocationGroupShift(); }
disk_super_block &SuperBlock() { return fSuperBlock; } disk_super_block &SuperBlock() { return fSuperBlock; }
off_t ToOffset(block_run run) const { return ToBlock(run) << fSuperBlock.block_shift; } off_t ToOffset(block_run run) const { return ToBlock(run) << BlockShift(); }
off_t ToOffset(off_t block) const { return block << fSuperBlock.block_shift; } off_t ToOffset(off_t block) const { return block << BlockShift(); }
off_t ToBlock(block_run run) const { return ((((off_t)run.AllocationGroup()) << AllocationGroupShift()) | (off_t)run.Start()); } off_t ToBlock(block_run run) const { return ((((off_t)run.AllocationGroup()) << AllocationGroupShift()) | (off_t)run.Start()); }
block_run ToBlockRun(off_t block) const; block_run ToBlockRun(off_t block) const;
status_t ValidateBlockRun(block_run run); status_t ValidateBlockRun(block_run run);