From 697df4613d087ab37914e4dd229c35d3a00f3278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 6 Dec 2002 04:32:05 +0000 Subject: [PATCH] Style clean-ups *and* Index::Update() now correctly converts B_MIME_STRING_TYPE to B_STRING_TYPE for the lower layers - should probably find a better solution to handle this. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2166 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/bfs/Index.cpp | 70 +++++++++++-------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/Index.cpp b/src/add-ons/kernel/file_systems/bfs/Index.cpp index e0d6b6209a..bb5f6f1055 100644 --- a/src/add-ons/kernel/file_systems/bfs/Index.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Index.cpp @@ -14,6 +14,12 @@ #include +// B_MIME_STRING_TYPE is defined in storage/Mime.h, but we +// don't need the whole file here; the type can't change anyway +#ifndef _MIME_H +# define B_MIME_STRING_TYPE 'MIMS' +#endif + Index::Index(Volume *volume) : @@ -28,7 +34,7 @@ Index::~Index() if (fNode == NULL) return; - put_vnode(fVolume->ID(),fNode->ID()); + put_vnode(fVolume->ID(), fNode->ID()); } @@ -38,7 +44,7 @@ Index::Unset() if (fNode == NULL) return; - put_vnode(fVolume->ID(),fNode->ID()); + put_vnode(fVolume->ID(), fNode->ID()); fNode = NULL; } @@ -58,16 +64,16 @@ Index::SetTo(const char *name) return B_BAD_VALUE; vnode_id id; - status_t status = tree->Find((uint8 *)name,(uint16)strlen(name),&id); + status_t status = tree->Find((uint8 *)name, (uint16)strlen(name), &id); if (status != B_OK) return status; - if (get_vnode(fVolume->ID(),id,(void **)&fNode) != B_OK) + if (get_vnode(fVolume->ID(), id, (void **)&fNode) != B_OK) return B_ENTRY_NOT_FOUND; if (fNode == NULL) { FATAL(("fatal error at Index::InitCheck(), get_vnode() returned NULL pointer\n")); - put_vnode(fVolume->ID(),id); + put_vnode(fVolume->ID(), id); return B_ERROR; } fName = name; @@ -137,7 +143,7 @@ Index::KeySize() status_t -Index::Create(Transaction *transaction,const char *name,uint32 type) +Index::Create(Transaction *transaction, const char *name, uint32 type) { Unset(); @@ -190,7 +196,8 @@ Index::Create(Transaction *transaction,const char *name,uint32 type) */ status_t -Index::Update(Transaction *transaction,const char *name,int32 type,const uint8 *oldKey,uint16 oldLength,const uint8 *newKey,uint16 newLength,Inode *inode) +Index::Update(Transaction *transaction, const char *name, int32 type, const uint8 *oldKey, + uint16 oldLength, const uint8 *newKey, uint16 newLength, Inode *inode) { if (name == NULL || oldKey == NULL && newKey == NULL @@ -198,19 +205,23 @@ Index::Update(Transaction *transaction,const char *name,int32 type,const uint8 * || newKey != NULL && newLength == 0) return B_BAD_VALUE; + // B_MIME_STRING_TYPE is the only supported non-standard type + if (type == B_MIME_STRING_TYPE) + type = B_STRING_TYPE; + // if the two keys are identical, don't do anything - if (type != 0 && !compareKeys(type,oldKey,oldLength,newKey,newLength)) + if (type != 0 && !compareKeys(type, oldKey, oldLength, newKey, newLength)) return B_OK; // update all live queries about the change, if they have an index or not - fVolume->UpdateLiveQueries(inode,name,type,oldKey,oldLength,newKey,newLength); + fVolume->UpdateLiveQueries(inode, name, type, oldKey, oldLength, newKey, newLength); status_t status; if (name != fName && (status = SetTo(name)) < B_OK) return B_BAD_INDEX; // now that we have the type, check again for equality - if (type == 0 && !compareKeys(Type(),oldKey,oldLength,newKey,newLength)) + if (type == 0 && !compareKeys(Type(), oldKey, oldLength, newKey, newLength)) return B_OK; BPlusTree *tree; @@ -220,43 +231,44 @@ Index::Update(Transaction *transaction,const char *name,int32 type,const uint8 * // remove the old key from the tree if (oldKey != NULL) { - status = tree->Remove(transaction,(const uint8 *)oldKey,oldLength,inode->ID()); + status = tree->Remove(transaction, (const uint8 *)oldKey, oldLength, inode->ID()); if (status == B_ENTRY_NOT_FOUND) { // That's not nice, but should be no reason to let the whole thing fail - FATAL(("Could not find value in index \"%s\"!\n",name)); + FATAL(("Could not find value in index \"%s\"!\n", name)); } else if (status < B_OK) return status; } - // add the new key to the key + // add the new key to the tree if (newKey != NULL) - status = tree->Insert(transaction,(const uint8 *)newKey,newLength,inode->ID()); + status = tree->Insert(transaction, (const uint8 *)newKey, newLength, inode->ID()); return status; } status_t -Index::InsertName(Transaction *transaction,const char *name,Inode *inode) +Index::InsertName(Transaction *transaction, const char *name, Inode *inode) { - return UpdateName(transaction,NULL,name,inode); + return UpdateName(transaction, NULL, name, inode); } status_t -Index::RemoveName(Transaction *transaction,const char *name,Inode *inode) +Index::RemoveName(Transaction *transaction, const char *name, Inode *inode) { - return UpdateName(transaction,name,NULL,inode); + return UpdateName(transaction, name, NULL, inode); } status_t -Index::UpdateName(Transaction *transaction,const char *oldName, const char *newName,Inode *inode) +Index::UpdateName(Transaction *transaction, const char *oldName, const char *newName, Inode *inode) { uint16 oldLength = oldName ? strlen(oldName) : 0; uint16 newLength = newName ? strlen(newName) : 0; - return Update(transaction,"name",B_STRING_TYPE,(uint8 *)oldName,oldLength,(uint8 *)newName,newLength,inode); + return Update(transaction, "name", B_STRING_TYPE, (uint8 *)oldName, oldLength, + (uint8 *)newName, newLength, inode); } @@ -264,7 +276,7 @@ status_t Index::InsertSize(Transaction *transaction, Inode *inode) { off_t size = inode->Size(); - return Update(transaction,"size",B_INT64_TYPE,NULL,0,(uint8 *)&size,sizeof(int64),inode); + return Update(transaction, "size", B_INT64_TYPE, NULL, 0, (uint8 *)&size, sizeof(int64), inode); } @@ -273,7 +285,7 @@ Index::RemoveSize(Transaction *transaction, Inode *inode) { // Inode::OldSize() is the size that's in the index off_t size = inode->OldSize(); - return Update(transaction,"size",B_INT64_TYPE,(uint8 *)&size,sizeof(int64),NULL,0,inode); + return Update(transaction, "size", B_INT64_TYPE, (uint8 *)&size, sizeof(int64), NULL, 0, inode); } @@ -282,9 +294,9 @@ Index::UpdateSize(Transaction *transaction, Inode *inode) { off_t oldSize = inode->OldSize(); off_t newSize = inode->Size(); - status_t status = Update(transaction,"size",B_INT64_TYPE,(uint8 *)&oldSize,sizeof(int64), - (uint8 *)&newSize,sizeof(int64),inode); + status_t status = Update(transaction, "size", B_INT64_TYPE, (uint8 *)&oldSize, + sizeof(int64), (uint8 *)&newSize, sizeof(int64), inode); if (status == B_OK) inode->UpdateOldSize(); @@ -296,7 +308,8 @@ status_t Index::InsertLastModified(Transaction *transaction, Inode *inode) { off_t modified = inode->LastModified(); - return Update(transaction,"last_modified",B_INT64_TYPE,NULL,0,(uint8 *)&modified,sizeof(int64),inode); + return Update(transaction, "last_modified", B_INT64_TYPE, NULL, 0, + (uint8 *)&modified, sizeof(int64), inode); } @@ -305,7 +318,8 @@ Index::RemoveLastModified(Transaction *transaction, Inode *inode) { // Inode::OldLastModified() is the value which is in the index off_t modified = inode->OldLastModified(); - return Update(transaction,"last_modified",B_INT64_TYPE,(uint8 *)&modified,sizeof(int64),NULL,0,inode); + return Update(transaction, "last_modified", B_INT64_TYPE, (uint8 *)&modified, + sizeof(int64), NULL, 0, inode); } @@ -317,8 +331,8 @@ Index::UpdateLastModified(Transaction *transaction, Inode *inode, off_t modified modified = (bigtime_t)time(NULL) << INODE_TIME_SHIFT; modified |= fVolume->GetUniqueID() & INODE_TIME_MASK; - status_t status = Update(transaction,"last_modified",B_INT64_TYPE,(uint8 *)&oldModified,sizeof(int64), - (uint8 *)&modified,sizeof(int64),inode); + status_t status = Update(transaction, "last_modified", B_INT64_TYPE, (uint8 *)&oldModified, + sizeof(int64), (uint8 *)&modified, sizeof(int64), inode); inode->Node()->last_modified_time = modified; if (status == B_OK)