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) BPlusTree::CompareKeys(const void *key1, int keyLength1, const void *key2, int keyLength2)
{ {
type_code type = 0; type_code type = 0;
switch (fHeader->data_type) switch (fHeader->data_type) {
{
case BPLUSTREE_STRING_TYPE: case BPLUSTREE_STRING_TYPE:
type = B_STRING_TYPE; type = B_STRING_TYPE;
break; break;
@@ -677,7 +676,10 @@ BPlusTree::InsertDuplicate(Transaction *transaction, CachedNode *cached, bplustr
duplicate_array *array = duplicate->FragmentAt(bplustree_node::FragmentIndex(oldValue)); duplicate_array *array = duplicate->FragmentAt(bplustree_node::FragmentIndex(oldValue));
if (array->count > NUM_FRAGMENT_VALUES if (array->count > NUM_FRAGMENT_VALUES
|| array->count < 1) { || 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; return B_BAD_DATA;
} }
@@ -1212,11 +1214,13 @@ BPlusTree::RemoveDuplicate(Transaction *transaction, bplustree_node *node, Cache
if (array->count > NUM_FRAGMENT_VALUES if (array->count > NUM_FRAGMENT_VALUES
|| array->count < 1) { || 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; return B_BAD_DATA;
} }
if (!array->Remove(value)) 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 // remove the array from the fragment node if it is empty
if (array->count == 1) { if (array->count == 1) {
@@ -1255,7 +1259,8 @@ BPlusTree::RemoveDuplicate(Transaction *transaction, bplustree_node *node, Cache
array = duplicate->DuplicateArray(); array = duplicate->DuplicateArray();
if (array->count > NUM_DUPLICATE_VALUES if (array->count > NUM_DUPLICATE_VALUES
|| array->count < 0) { || 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; return B_BAD_DATA;
} }
@@ -1336,10 +1341,12 @@ BPlusTree::RemoveDuplicate(Transaction *transaction, bplustree_node *node, Cache
bplustree_node *fragment = NULL; bplustree_node *fragment = NULL;
uint32 fragmentIndex = 0; uint32 fragmentIndex = 0;
off_t offset; off_t offset;
if (FindFreeDuplicateFragment(node,&cachedOther,&offset,&fragment,&fragmentIndex) < B_OK) { if (FindFreeDuplicateFragment(node, &cachedOther, &offset,
&fragment, &fragmentIndex) < B_OK) {
// convert node // convert node
memmove(duplicate, array, (NUM_FRAGMENT_VALUES + 1) * sizeof(off_t)); 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 { } else {
// move to other node // move to other node
duplicate_array *target = fragment->FragmentAt(fragmentIndex); duplicate_array *target = fragment->FragmentAt(fragmentIndex);
@@ -1348,7 +1355,8 @@ BPlusTree::RemoveDuplicate(Transaction *transaction, bplustree_node *node, Cache
cachedDuplicate.Free(transaction, duplicateOffset); cachedDuplicate.Free(transaction, duplicateOffset);
duplicateOffset = offset; 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) if ((status = cached->WriteBack(transaction)) < B_OK)
return status; return status;
@@ -1388,7 +1396,8 @@ BPlusTree::RemoveKey(bplustree_node *node,uint16 index)
uint8 *key = node->KeyAt(index, &length); uint8 *key = node->KeyAt(index, &length);
if (key + length + sizeof(off_t) + sizeof(uint16) > (uint8 *)node + fNodeSize if (key + length + sizeof(off_t) + sizeof(uint16) > (uint8 *)node + fNodeSize
|| length > BPLUSTREE_MAX_KEY_LENGTH) { || 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(); fStream->GetVolume()->Panic();
return; return;
} }
@@ -1441,13 +1450,12 @@ BPlusTree::Remove(Transaction *transaction, const uint8 *key, uint16 keyLength,
bplustree_node *node; bplustree_node *node;
CachedNode cached(this); 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 #ifdef DEBUG
NodeChecker checker(node, fNodeSize); NodeChecker checker(node, fNodeSize);
#endif #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); status_t status = FindKey(node, key, keyLength, &nodeAndKey.keyIndex);
if (status < B_OK) if (status < B_OK)
RETURN_ERROR(status); RETURN_ERROR(status);
@@ -1690,11 +1698,8 @@ TreeIterator::Goto(int8 to)
nodeOffset = nextOffset; nodeOffset = nextOffset;
} }
#if __MWERKS__ FATAL(("%s fails\n", __FUNCTION__));
FATAL(("TreeIterator::Goto(int8 to) fails\n"));
#else
FATAL(("%s fails\n",__PRETTY_FUNCTION__));
#endif
RETURN_ERROR(B_ERROR); RETURN_ERROR(B_ERROR);
} }
@@ -1731,8 +1736,7 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, uint16 maxL
CachedNode cached(fTree); CachedNode cached(fTree);
bplustree_node *node; bplustree_node *node;
if (fDuplicateNode != BPLUSTREE_NULL) if (fDuplicateNode != BPLUSTREE_NULL) {
{
// regardless of traverse direction the duplicates are always presented in // regardless of traverse direction the duplicates are always presented in
// the same order; since they are all considered as equal, this shouldn't // the same order; since they are all considered as equal, this shouldn't
// cause any problems // cause any problems
@@ -1742,21 +1746,17 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, uint16 maxL
else else
node = NULL; node = NULL;
if (node != NULL) if (node != NULL) {
{ if (!fIsFragment && fDuplicate >= fNumDuplicates) {
if (!fIsFragment && fDuplicate >= fNumDuplicates)
{
// if the node is out of duplicates, we go directly to the next one // if the node is out of duplicates, we go directly to the next one
fDuplicateNode = node->RightLink(); fDuplicateNode = node->RightLink();
if (fDuplicateNode != BPLUSTREE_NULL if (fDuplicateNode != BPLUSTREE_NULL
&& (node = cached.SetTo(fDuplicateNode, false)) != NULL) && (node = cached.SetTo(fDuplicateNode, false)) != NULL) {
{
fNumDuplicates = node->CountDuplicates(fDuplicateNode, false); fNumDuplicates = node->CountDuplicates(fDuplicateNode, false);
fDuplicate = 0; fDuplicate = 0;
} }
} }
if (fDuplicate < fNumDuplicates) if (fDuplicate < fNumDuplicates) {
{
*value = node->DuplicateAt(fDuplicateNode, fIsFragment, fDuplicate++); *value = node->DuplicateAt(fDuplicateNode, fIsFragment, fDuplicate++);
if (duplicate) if (duplicate)
*duplicate = 2; *duplicate = 2;
@@ -1777,22 +1777,18 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, uint16 maxL
// is the current key in the current node? // is the current key in the current node?
while ((direction == BPLUSTREE_FORWARD && fCurrentKey >= node->NumKeys()) 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(); fCurrentNodeOffset = direction == BPLUSTREE_FORWARD ? node->RightLink() : node->LeftLink();
// are there any more nodes? // are there any more nodes?
if (fCurrentNodeOffset != BPLUSTREE_NULL) if (fCurrentNodeOffset != BPLUSTREE_NULL) {
{
node = cached.SetTo(fCurrentNodeOffset); node = cached.SetTo(fCurrentNodeOffset);
if (!node) if (!node)
RETURN_ERROR(B_ERROR); RETURN_ERROR(B_ERROR);
// reset current key // reset current key
fCurrentKey = direction == BPLUSTREE_FORWARD ? 0 : node->NumKeys(); fCurrentKey = direction == BPLUSTREE_FORWARD ? 0 : node->NumKeys();
} } else {
else
{
// there are no nodes left, so turn back to the last key // there are no nodes left, so turn back to the last key
fCurrentNodeOffset = savedNodeOffset; fCurrentNodeOffset = savedNodeOffset;
fCurrentKey = direction == BPLUSTREE_FORWARD ? node->NumKeys() : -1; 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); length = min_c(length, maxLength);
memcpy(key, keyStart, length); 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) if (length == maxLength)
length--; length--;
((char *)key)[length] = '\0'; ((char *)key)[length] = '\0';
@@ -1827,8 +1823,7 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, uint16 maxL
// duplicate fragments? // duplicate fragments?
uint8 type = bplustree_node::LinkType(offset); 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; fDuplicateNode = offset;
node = cached.SetTo(bplustree_node::FragmentOffset(fDuplicateNode), false); 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; fIsFragment = type == BPLUSTREE_DUPLICATE_FRAGMENT;
fNumDuplicates = node->CountDuplicates(offset, fIsFragment); fNumDuplicates = node->CountDuplicates(offset, fIsFragment);
if (fNumDuplicates) if (fNumDuplicates) {
{
offset = node->DuplicateAt(offset, fIsFragment, 0); offset = node->DuplicateAt(offset, fIsFragment, 0);
fDuplicate = 1; fDuplicate = 1;
if (duplicate) if (duplicate)
*duplicate = 1; *duplicate = 1;
} } else {
else
{
// shouldn't happen, but we're dealing here with potentially corrupt disks... // shouldn't happen, but we're dealing here with potentially corrupt disks...
fDuplicateNode = BPLUSTREE_NULL; fDuplicateNode = BPLUSTREE_NULL;
offset = 0; offset = 0;
+2 -1
View File
@@ -96,7 +96,8 @@
extern void dump_data_stream(data_stream *stream); extern void dump_data_stream(data_stream *stream);
extern void dump_inode(bfs_inode *inode); extern void dump_inode(bfs_inode *inode);
extern void dump_bplustree_header(bplustree_header *header); 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 dump_block(const char *buffer, int size);
extern void remove_debugger_commands(); extern void remove_debugger_commands();
@@ -307,6 +307,7 @@ static int
bfs_write_fs_stat(void *_ns, struct fs_info *info, long mask) bfs_write_fs_stat(void *_ns, struct fs_info *info, long mask)
{ {
FUNCTION_START(("mask = %ld\n", mask)); FUNCTION_START(("mask = %ld\n", mask));
Volume *volume = (Volume *)_ns; Volume *volume = (Volume *)_ns;
disk_super_block &superBlock = volume->SuperBlock(); 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) bfs_walk(void *_ns, void *_directory, const char *file, char **_resolvedPath, vnode_id *_vnodeID)
{ {
//FUNCTION_START(("file = %s\n", file)); //FUNCTION_START(("file = %s\n", file));
if (_ns == NULL || _directory == NULL || file == NULL || _vnodeID == NULL) if (_ns == NULL || _directory == NULL || file == NULL || _vnodeID == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -846,7 +846,8 @@ bfs_write_stat(void *_ns, void *_node, struct stat *stat, long mask)
if (mask & WSTAT_MTIME) { if (mask & WSTAT_MTIME) {
// Index::UpdateLastModified() will set the new time in the inode // Index::UpdateLastModified() will set the new time in the inode
Index index(volume); 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) { if (mask & WSTAT_CRTIME) {
node->create_time = (bigtime_t)stat->st_crtime << INODE_TIME_SHIFT; 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 // first, try to find it in the small data region
small_data *smallData = NULL; small_data *smallData = NULL;
if (inode->SmallDataLock().Lock() == B_OK) if (inode->SmallDataLock().Lock() == B_OK) {
{
if ((smallData = inode->FindSmallData((const char *)name)) != NULL) { if ((smallData = inode->FindSmallData((const char *)name)) != NULL) {
attrInfo->type = smallData->Type(); attrInfo->type = smallData->Type();
attrInfo->size = smallData->DataSize(); 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) size_t *_length, off_t pos)
{ {
FUNCTION_START(("name = \"%s\"\n", name)); FUNCTION_START(("name = \"%s\"\n", name));
if (_ns == NULL || _node == NULL || name == NULL || *name == '\0') if (_ns == NULL || _node == NULL || name == NULL || *name == '\0')
RETURN_ERROR(B_BAD_VALUE); RETURN_ERROR(B_BAD_VALUE);
@@ -1859,7 +1858,6 @@ static int
bfs_open_indexdir(void *_ns, void **_cookie) bfs_open_indexdir(void *_ns, void **_cookie)
{ {
FUNCTION(); FUNCTION();
if (_ns == NULL || _cookie == NULL) if (_ns == NULL || _cookie == NULL)
RETURN_ERROR(B_BAD_VALUE); RETURN_ERROR(B_BAD_VALUE);