Some minor style changes.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6417 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-01-29 22:19:17 +00:00
parent 73e3e50c41
commit 01338285a9
4 changed files with 98 additions and 107 deletions
@@ -500,8 +500,7 @@ int32
BPlusTree::CompareKeys(const void *key1, int keyLength1, const void *key2, int keyLength2)
{
type_code type = 0;
switch (fHeader->data_type)
{
switch (fHeader->data_type) {
case BPLUSTREE_STRING_TYPE:
type = B_STRING_TYPE;
break;
@@ -677,7 +676,10 @@ BPlusTree::InsertDuplicate(Transaction *transaction, CachedNode *cached, bplustr
duplicate_array *array = duplicate->FragmentAt(bplustree_node::FragmentIndex(oldValue));
if (array->count > NUM_FRAGMENT_VALUES
|| array->count < 1) {
FATAL(("insertDuplicate: Invalid array[%ld] size in fragment %Ld == %Ld!\n",bplustree_node::FragmentIndex(oldValue),bplustree_node::FragmentOffset(oldValue),array->count));
FATAL(("insertDuplicate: Invalid array[%ld] size in fragment %Ld == %Ld!\n",
bplustree_node::FragmentIndex(oldValue),
bplustree_node::FragmentOffset(oldValue),
array->count));
return B_BAD_DATA;
}
@@ -1212,11 +1214,13 @@ BPlusTree::RemoveDuplicate(Transaction *transaction, bplustree_node *node, Cache
if (array->count > NUM_FRAGMENT_VALUES
|| array->count < 1) {
FATAL(("removeDuplicate: Invalid array[%ld] size in fragment %Ld == %Ld!\n",bplustree_node::FragmentIndex(oldValue),duplicateOffset,array->count));
FATAL(("removeDuplicate: Invalid array[%ld] size in fragment %Ld == %Ld!\n",
bplustree_node::FragmentIndex(oldValue), duplicateOffset, array->count));
return B_BAD_DATA;
}
if (!array->Remove(value))
FATAL(("Oh no, value %Ld not found in fragments of node %Ld...\n",value,duplicateOffset));
FATAL(("Oh no, value %Ld not found in fragments of node %Ld...\n",
value, duplicateOffset));
// remove the array from the fragment node if it is empty
if (array->count == 1) {
@@ -1255,7 +1259,8 @@ BPlusTree::RemoveDuplicate(Transaction *transaction, bplustree_node *node, Cache
array = duplicate->DuplicateArray();
if (array->count > NUM_DUPLICATE_VALUES
|| array->count < 0) {
FATAL(("removeDuplicate: Invalid array size in duplicate %Ld == %Ld!\n",duplicateOffset,array->count));
FATAL(("removeDuplicate: Invalid array size in duplicate %Ld == %Ld!\n",
duplicateOffset, array->count));
return B_BAD_DATA;
}
@@ -1336,10 +1341,12 @@ BPlusTree::RemoveDuplicate(Transaction *transaction, bplustree_node *node, Cache
bplustree_node *fragment = NULL;
uint32 fragmentIndex = 0;
off_t offset;
if (FindFreeDuplicateFragment(node,&cachedOther,&offset,&fragment,&fragmentIndex) < B_OK) {
if (FindFreeDuplicateFragment(node, &cachedOther, &offset,
&fragment, &fragmentIndex) < B_OK) {
// convert node
memmove(duplicate, array, (NUM_FRAGMENT_VALUES + 1) * sizeof(off_t));
memset((off_t *)duplicate + NUM_FRAGMENT_VALUES + 1,0,fNodeSize - (NUM_FRAGMENT_VALUES + 1) * sizeof(off_t));
memset((off_t *)duplicate + NUM_FRAGMENT_VALUES + 1, 0,
fNodeSize - (NUM_FRAGMENT_VALUES + 1) * sizeof(off_t));
} else {
// move to other node
duplicate_array *target = fragment->FragmentAt(fragmentIndex);
@@ -1348,7 +1355,8 @@ BPlusTree::RemoveDuplicate(Transaction *transaction, bplustree_node *node, Cache
cachedDuplicate.Free(transaction, duplicateOffset);
duplicateOffset = offset;
}
values[index] = bplustree_node::MakeLink(BPLUSTREE_DUPLICATE_FRAGMENT,duplicateOffset,fragmentIndex);
values[index] = bplustree_node::MakeLink(BPLUSTREE_DUPLICATE_FRAGMENT,
duplicateOffset, fragmentIndex);
if ((status = cached->WriteBack(transaction)) < B_OK)
return status;
@@ -1388,7 +1396,8 @@ BPlusTree::RemoveKey(bplustree_node *node,uint16 index)
uint8 *key = node->KeyAt(index, &length);
if (key + length + sizeof(off_t) + sizeof(uint16) > (uint8 *)node + fNodeSize
|| length > BPLUSTREE_MAX_KEY_LENGTH) {
FATAL(("Key length to long: %s, %u (inode at %ld,%u)\n", key, length, fStream->BlockRun().allocation_group, fStream->BlockRun().start));
FATAL(("Key length to long: %s, %u (inode at %ld,%u)\n", key, length,
fStream->BlockRun().allocation_group, fStream->BlockRun().start));
fStream->GetVolume()->Panic();
return;
}
@@ -1441,13 +1450,12 @@ BPlusTree::Remove(Transaction *transaction, const uint8 *key, uint16 keyLength,
bplustree_node *node;
CachedNode cached(this);
while (stack.Pop(&nodeAndKey) && (node = cached.SetTo(nodeAndKey.nodeOffset)) != NULL)
{
while (stack.Pop(&nodeAndKey) && (node = cached.SetTo(nodeAndKey.nodeOffset)) != NULL) {
#ifdef DEBUG
NodeChecker checker(node, fNodeSize);
#endif
if (node->IsLeaf()) // first round, check for duplicate entries
{
if (node->IsLeaf()) {
// first round, check for duplicate entries
status_t status = FindKey(node, key, keyLength, &nodeAndKey.keyIndex);
if (status < B_OK)
RETURN_ERROR(status);
@@ -1690,11 +1698,8 @@ TreeIterator::Goto(int8 to)
nodeOffset = nextOffset;
}
#if __MWERKS__
FATAL(("TreeIterator::Goto(int8 to) fails\n"));
#else
FATAL(("%s fails\n",__PRETTY_FUNCTION__));
#endif
FATAL(("%s fails\n", __FUNCTION__));
RETURN_ERROR(B_ERROR);
}
@@ -1731,8 +1736,7 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, uint16 maxL
CachedNode cached(fTree);
bplustree_node *node;
if (fDuplicateNode != BPLUSTREE_NULL)
{
if (fDuplicateNode != BPLUSTREE_NULL) {
// regardless of traverse direction the duplicates are always presented in
// the same order; since they are all considered as equal, this shouldn't
// cause any problems
@@ -1742,21 +1746,17 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, uint16 maxL
else
node = NULL;
if (node != NULL)
{
if (!fIsFragment && fDuplicate >= fNumDuplicates)
{
if (node != NULL) {
if (!fIsFragment && fDuplicate >= fNumDuplicates) {
// if the node is out of duplicates, we go directly to the next one
fDuplicateNode = node->RightLink();
if (fDuplicateNode != BPLUSTREE_NULL
&& (node = cached.SetTo(fDuplicateNode, false)) != NULL)
{
&& (node = cached.SetTo(fDuplicateNode, false)) != NULL) {
fNumDuplicates = node->CountDuplicates(fDuplicateNode, false);
fDuplicate = 0;
}
}
if (fDuplicate < fNumDuplicates)
{
if (fDuplicate < fNumDuplicates) {
*value = node->DuplicateAt(fDuplicateNode, fIsFragment, fDuplicate++);
if (duplicate)
*duplicate = 2;
@@ -1777,22 +1777,18 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, uint16 maxL
// is the current key in the current node?
while ((direction == BPLUSTREE_FORWARD && fCurrentKey >= node->NumKeys())
|| (direction == BPLUSTREE_BACKWARD && fCurrentKey < 0))
{
|| (direction == BPLUSTREE_BACKWARD && fCurrentKey < 0)) {
fCurrentNodeOffset = direction == BPLUSTREE_FORWARD ? node->RightLink() : node->LeftLink();
// are there any more nodes?
if (fCurrentNodeOffset != BPLUSTREE_NULL)
{
if (fCurrentNodeOffset != BPLUSTREE_NULL) {
node = cached.SetTo(fCurrentNodeOffset);
if (!node)
RETURN_ERROR(B_ERROR);
// reset current key
fCurrentKey = direction == BPLUSTREE_FORWARD ? 0 : node->NumKeys();
}
else
{
} else {
// there are no nodes left, so turn back to the last key
fCurrentNodeOffset = savedNodeOffset;
fCurrentKey = direction == BPLUSTREE_FORWARD ? node->NumKeys() : -1;
@@ -1815,8 +1811,8 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, uint16 maxL
length = min_c(length, maxLength);
memcpy(key, keyStart, length);
if (fTree->fHeader->data_type == BPLUSTREE_STRING_TYPE) // terminate string type
{
if (fTree->fHeader->data_type == BPLUSTREE_STRING_TYPE) {
// terminate string type
if (length == maxLength)
length--;
((char *)key)[length] = '\0';
@@ -1827,8 +1823,7 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, uint16 maxL
// duplicate fragments?
uint8 type = bplustree_node::LinkType(offset);
if (type == BPLUSTREE_DUPLICATE_FRAGMENT || type == BPLUSTREE_DUPLICATE_NODE)
{
if (type == BPLUSTREE_DUPLICATE_FRAGMENT || type == BPLUSTREE_DUPLICATE_NODE) {
fDuplicateNode = offset;
node = cached.SetTo(bplustree_node::FragmentOffset(fDuplicateNode), false);
@@ -1838,15 +1833,12 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, uint16 maxL
fIsFragment = type == BPLUSTREE_DUPLICATE_FRAGMENT;
fNumDuplicates = node->CountDuplicates(offset, fIsFragment);
if (fNumDuplicates)
{
if (fNumDuplicates) {
offset = node->DuplicateAt(offset, fIsFragment, 0);
fDuplicate = 1;
if (duplicate)
*duplicate = 1;
}
else
{
} else {
// shouldn't happen, but we're dealing here with potentially corrupt disks...
fDuplicateNode = BPLUSTREE_NULL;
offset = 0;
+2 -1
View File
@@ -96,7 +96,8 @@
extern void dump_data_stream(data_stream *stream);
extern void dump_inode(bfs_inode *inode);
extern void dump_bplustree_header(bplustree_header *header);
extern void dump_bplustree_node(bplustree_node *node,bplustree_header *header = NULL,Volume *volume = NULL);
extern void dump_bplustree_node(bplustree_node *node,
bplustree_header *header = NULL, Volume *volume = NULL);
extern void dump_block(const char *buffer, int size);
extern void remove_debugger_commands();
@@ -307,6 +307,7 @@ static int
bfs_write_fs_stat(void *_ns, struct fs_info *info, long mask)
{
FUNCTION_START(("mask = %ld\n", mask));
Volume *volume = (Volume *)_ns;
disk_super_block &superBlock = volume->SuperBlock();
@@ -508,7 +509,6 @@ static int
bfs_walk(void *_ns, void *_directory, const char *file, char **_resolvedPath, vnode_id *_vnodeID)
{
//FUNCTION_START(("file = %s\n", file));
if (_ns == NULL || _directory == NULL || file == NULL || _vnodeID == NULL)
return B_BAD_VALUE;
@@ -846,7 +846,8 @@ bfs_write_stat(void *_ns, void *_node, struct stat *stat, long mask)
if (mask & WSTAT_MTIME) {
// Index::UpdateLastModified() will set the new time in the inode
Index index(volume);
index.UpdateLastModified(&transaction,inode,(bigtime_t)stat->st_mtime << INODE_TIME_SHIFT);
index.UpdateLastModified(&transaction, inode,
(bigtime_t)stat->st_mtime << INODE_TIME_SHIFT);
}
if (mask & WSTAT_CRTIME) {
node->create_time = (bigtime_t)stat->st_crtime << INODE_TIME_SHIFT;
@@ -1767,8 +1768,7 @@ bfs_stat_attr(void *ns, void *_node, const char *name, struct attr_info *attrInf
// first, try to find it in the small data region
small_data *smallData = NULL;
if (inode->SmallDataLock().Lock() == B_OK)
{
if (inode->SmallDataLock().Lock() == B_OK) {
if ((smallData = inode->FindSmallData((const char *)name)) != NULL) {
attrInfo->type = smallData->Type();
attrInfo->size = smallData->DataSize();
@@ -1798,7 +1798,6 @@ bfs_write_attr(void *_ns, void *_node, const char *name, int type, const void *b
size_t *_length, off_t pos)
{
FUNCTION_START(("name = \"%s\"\n", name));
if (_ns == NULL || _node == NULL || name == NULL || *name == '\0')
RETURN_ERROR(B_BAD_VALUE);
@@ -1859,7 +1858,6 @@ static int
bfs_open_indexdir(void *_ns, void **_cookie)
{
FUNCTION();
if (_ns == NULL || _cookie == NULL)
RETURN_ERROR(B_BAD_VALUE);