diff --git a/src/add-ons/kernel/file_systems/bfs/Attribute.cpp b/src/add-ons/kernel/file_systems/bfs/Attribute.cpp index d05c2bc643..4a0c5d7b3b 100644 --- a/src/add-ons/kernel/file_systems/bfs/Attribute.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Attribute.cpp @@ -10,13 +10,14 @@ // TODO: clean this up, find a better separation between Inode and this class -// TODO: even after Create(), the attribute cannot be stat() for until the first write +// TODO: even after Create(), the attribute cannot be stat() for until the +// first write -extern void fill_stat_buffer(Inode *inode, struct stat &stat); +extern void fill_stat_buffer(Inode* inode, struct stat& stat); -Attribute::Attribute(Inode *inode) +Attribute::Attribute(Inode* inode) : fNodeGetter(inode->GetVolume()), fInode(inode), @@ -27,7 +28,7 @@ Attribute::Attribute(Inode *inode) } -Attribute::Attribute(Inode *inode, attr_cookie *cookie) +Attribute::Attribute(Inode* inode, attr_cookie* cookie) : fNodeGetter(inode->GetVolume()), fInode(inode), @@ -53,7 +54,7 @@ Attribute::InitCheck() status_t -Attribute::CheckAccess(const char *name, int openMode) +Attribute::CheckAccess(const char* name, int openMode) { // Opening the name attribute using this function is not allowed, // also using the reserved indices name, last_modified, and size @@ -73,7 +74,7 @@ Attribute::CheckAccess(const char *name, int openMode) status_t -Attribute::Get(const char *name) +Attribute::Get(const char* name) { Put(); @@ -82,7 +83,7 @@ Attribute::Get(const char *name) // try to find it in the small data region if (recursive_lock_lock(&fInode->SmallDataLock()) == B_OK) { fNodeGetter.SetToNode(fInode); - fSmall = fInode->FindSmallData(fNodeGetter.Node(), (const char *)name); + fSmall = fInode->FindSmallData(fNodeGetter.Node(), (const char*)name); if (fSmall != NULL) return B_OK; @@ -112,14 +113,14 @@ Attribute::Put() status_t -Attribute::Create(const char *name, type_code type, int openMode, - attr_cookie **_cookie) +Attribute::Create(const char* name, type_code type, int openMode, + attr_cookie** _cookie) { status_t status = CheckAccess(name, openMode); if (status < B_OK) return status; - attr_cookie *cookie = new(std::nothrow) attr_cookie; + attr_cookie* cookie = new(std::nothrow) attr_cookie; if (cookie == NULL) RETURN_ERROR(B_NO_MEMORY); @@ -142,7 +143,7 @@ Attribute::Create(const char *name, type_code type, int openMode, status_t -Attribute::Open(const char *name, int openMode, attr_cookie **_cookie) +Attribute::Open(const char* name, int openMode, attr_cookie** _cookie) { status_t status = CheckAccess(name, openMode); if (status < B_OK) @@ -152,7 +153,7 @@ Attribute::Open(const char *name, int openMode, attr_cookie **_cookie) if (status < B_OK) return status; - attr_cookie *cookie = new(std::nothrow) attr_cookie; + attr_cookie* cookie = new(std::nothrow) attr_cookie; if (cookie == NULL) RETURN_ERROR(B_NO_MEMORY); @@ -171,7 +172,7 @@ Attribute::Open(const char *name, int openMode, attr_cookie **_cookie) status_t -Attribute::Stat(struct stat &stat) +Attribute::Stat(struct stat& stat) { if (fSmall == NULL && fAttribute == NULL) return B_NO_INIT; @@ -192,7 +193,7 @@ Attribute::Stat(struct stat &stat) status_t -Attribute::Read(attr_cookie *cookie, off_t pos, uint8 *buffer, size_t *_length) +Attribute::Read(attr_cookie* cookie, off_t pos, uint8* buffer, size_t* _length) { if (fSmall == NULL && fAttribute == NULL) return B_NO_INIT; @@ -203,8 +204,8 @@ Attribute::Read(attr_cookie *cookie, off_t pos, uint8 *buffer, size_t *_length) status_t -Attribute::Write(Transaction &transaction, attr_cookie *cookie, - off_t pos, const uint8 *buffer, size_t *_length) +Attribute::Write(Transaction& transaction, attr_cookie* cookie, off_t pos, + const uint8* buffer, size_t* _length) { if (!cookie->create && fSmall == NULL && fAttribute == NULL) return B_NO_INIT; diff --git a/src/add-ons/kernel/file_systems/bfs/Attribute.h b/src/add-ons/kernel/file_systems/bfs/Attribute.h index d4c08d2396..a0d3bfc1f9 100644 --- a/src/add-ons/kernel/file_systems/bfs/Attribute.h +++ b/src/add-ons/kernel/file_systems/bfs/Attribute.h @@ -1,6 +1,5 @@ -/* Attribute - connection between pure inode and kernel_interface attributes - * - * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. +/* + * Copyright 2004-2008, Axel Dörfler, axeld@pinc-software.de. * This file may be used under the terms of the MIT License. */ #ifndef ATTRIBUTE_H @@ -19,35 +18,38 @@ struct attr_cookie { class Attribute { - public: - Attribute(Inode *inode); - Attribute(Inode *inode, attr_cookie *cookie); - ~Attribute(); +public: + Attribute(Inode* inode); + Attribute(Inode* inode, attr_cookie* cookie); + ~Attribute(); - status_t InitCheck(); - status_t CheckAccess(const char *name, int openMode); + status_t InitCheck(); + status_t CheckAccess(const char* name, int openMode); - status_t Get(const char *name); - void Put(); + status_t Get(const char* name); + void Put(); - status_t Create(const char *name, type_code type, int openMode, - attr_cookie **_cookie); - status_t Open(const char *name, int openMode, attr_cookie **_cookie); + status_t Create(const char* name, type_code type, + int openMode, attr_cookie** _cookie); + status_t Open(const char* name, int openMode, + attr_cookie** _cookie); - status_t Stat(struct stat &stat); + status_t Stat(struct stat& stat); - status_t Read(attr_cookie *cookie, off_t pos, uint8 *buffer, size_t *_length); - status_t Write(Transaction &transaction, attr_cookie *cookie, - off_t pos, const uint8 *buffer, size_t *_length); + status_t Read(attr_cookie* cookie, off_t pos, uint8* buffer, + size_t* _length); + status_t Write(Transaction& transaction, attr_cookie* cookie, + off_t pos, const uint8* buffer, + size_t* _length); - private: - status_t _Truncate(); +private: + status_t _Truncate(); - NodeGetter fNodeGetter; - Inode *fInode; - small_data *fSmall; - Inode *fAttribute; - const char *fName; + NodeGetter fNodeGetter; + Inode* fInode; + small_data* fSmall; + Inode* fAttribute; + const char* fName; }; -#endif /* ATTRIBUTE_H */ +#endif // ATTRIBUTE_H diff --git a/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp b/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp index dd539639b6..b280f42ac3 100644 --- a/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp +++ b/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp @@ -17,32 +17,32 @@ #ifdef DEBUG class NodeChecker { - public: - NodeChecker(const bplustree_node *node, int32 nodeSize, const char *text) - : - fNode(node), - fSize(nodeSize), - fText(text) - { - Check("integrity check failed on construction."); - } +public: + NodeChecker(const bplustree_node* node, int32 nodeSize, const char* text) + : + fNode(node), + fSize(nodeSize), + fText(text) + { + Check("integrity check failed on construction."); + } - ~NodeChecker() - { - Check("integrity check failed on destruction."); - } + ~NodeChecker() + { + Check("integrity check failed on destruction."); + } - void - Check(const char *message) - { - if (fNode->CheckIntegrity(fSize) < B_OK) - dprintf("%s: %s\n", fText, message); - } + void + Check(const char* message) + { + if (fNode->CheckIntegrity(fSize) < B_OK) + dprintf("%s: %s\n", fText, message); + } - private: - const bplustree_node *fNode; - int32 fSize; - const char *fText; +private: + const bplustree_node* fNode; + int32 fSize; + const char* fText; }; #endif @@ -60,13 +60,13 @@ class NodeChecker { // is hard-coded to 1024 bytes, that's not an issue now. void -CachedNode::UnsetUnchanged(Transaction &transaction) +CachedNode::UnsetUnchanged(Transaction& transaction) { if (fTree == NULL || fTree->fStream == NULL) return; if (fNode != NULL) { - void *cache = fTree->fStream->GetVolume()->BlockCache(); + void* cache = fTree->fStream->GetVolume()->BlockCache(); block_cache_set_dirty(cache, fBlockNumber, false, transaction.ID()); block_cache_put(cache, fBlockNumber); @@ -82,13 +82,14 @@ CachedNode::Unset() return; if (fNode != NULL) { - block_cache_put(fTree->fStream->GetVolume()->BlockCache(), fBlockNumber); + block_cache_put(fTree->fStream->GetVolume()->BlockCache(), + fBlockNumber); fNode = NULL; } } -const bplustree_node * +const bplustree_node* CachedNode::SetTo(off_t offset, bool check) { if (fTree == NULL || fTree->fStream == NULL) { @@ -118,8 +119,8 @@ CachedNode::SetTo(off_t offset, bool check) } -bplustree_node * -CachedNode::SetToWritable(Transaction &transaction, off_t offset, bool check) +bplustree_node* +CachedNode::SetToWritable(Transaction& transaction, off_t offset, bool check) { if (fTree == NULL || fTree->fStream == NULL) { REPORT_ERROR(B_BAD_VALUE); @@ -148,8 +149,8 @@ CachedNode::SetToWritable(Transaction &transaction, off_t offset, bool check) } -bplustree_node * -CachedNode::MakeWritable(Transaction &transaction) +bplustree_node* +CachedNode::MakeWritable(Transaction& transaction) { if (fNode == NULL) return NULL; @@ -162,14 +163,14 @@ CachedNode::MakeWritable(Transaction &transaction) } -bplustree_header * -CachedNode::MakeWritableHeader(Transaction &transaction) +bplustree_header* +CachedNode::MakeWritableHeader(Transaction& transaction) { - return (bplustree_header *)MakeWritable(transaction); + return (bplustree_header*)MakeWritable(transaction); } -const bplustree_header * +const bplustree_header* CachedNode::SetToHeader() { if (fTree == NULL || fTree->fStream == NULL) { @@ -180,12 +181,12 @@ CachedNode::SetToHeader() Unset(); InternalSetTo(NULL, 0LL); - return (bplustree_header *)fNode; + return (bplustree_header*)fNode; } -bplustree_header * -CachedNode::SetToWritableHeader(Transaction &transaction) +bplustree_header* +CachedNode::SetToWritableHeader(Transaction& transaction) { if (fTree == NULL || fTree->fStream == NULL) { REPORT_ERROR(B_BAD_VALUE); @@ -195,12 +196,12 @@ CachedNode::SetToWritableHeader(Transaction &transaction) Unset(); InternalSetTo(&transaction, 0LL); - return (bplustree_header *)fNode; + return (bplustree_header*)fNode; } -bplustree_node * -CachedNode::InternalSetTo(Transaction *transaction, off_t offset) +bplustree_node* +CachedNode::InternalSetTo(Transaction* transaction, off_t offset) { fNode = NULL; fOffset = offset; @@ -209,25 +210,26 @@ CachedNode::InternalSetTo(Transaction *transaction, off_t offset) block_run run; if (offset < fTree->fStream->Size() && fTree->fStream->FindBlockRun(offset, run, fileOffset) == B_OK) { - Volume *volume = fTree->fStream->GetVolume(); + Volume* volume = fTree->fStream->GetVolume(); int32 blockOffset = (offset - fileOffset) / volume->BlockSize(); fBlockNumber = volume->ToBlock(run) + blockOffset; - uint8 *block; + uint8* block; if (transaction != NULL) { - block = (uint8 *)block_cache_get_writable(volume->BlockCache(), + block = (uint8*)block_cache_get_writable(volume->BlockCache(), fBlockNumber, transaction->ID()); fWritable = true; } else { - block = (uint8 *)block_cache_get(volume->BlockCache(), fBlockNumber); + block = (uint8*)block_cache_get(volume->BlockCache(), fBlockNumber); fWritable = false; } if (block) { - // the node is somewhere in that block... (confusing offset calculation) - fNode = (bplustree_node *)(block + offset - - (fileOffset + (blockOffset << volume->BlockShift()))); + // The node is somewhere in that block... + // (confusing offset calculation) + fNode = (bplustree_node*)(block + offset + - (fileOffset + (blockOffset << volume->BlockShift()))); } else REPORT_ERROR(B_IO_ERROR); } @@ -236,7 +238,7 @@ CachedNode::InternalSetTo(Transaction *transaction, off_t offset) status_t -CachedNode::Free(Transaction &transaction, off_t offset) +CachedNode::Free(Transaction& transaction, off_t offset) { if (fTree == NULL || fTree->fStream == NULL || offset == BPLUSTREE_NULL) RETURN_ERROR(B_BAD_VALUE); @@ -246,7 +248,8 @@ CachedNode::Free(Transaction &transaction, off_t offset) // function is called, perhaps it should be done when the directory // inode is closed or based on some calculation or whatever... - bplustree_header *header = fTree->fCachedHeader.MakeWritableHeader(transaction); + bplustree_header* header + = fTree->fCachedHeader.MakeWritableHeader(transaction); if (header == NULL) return B_IO_ERROR; @@ -276,15 +279,15 @@ CachedNode::Free(Transaction &transaction, off_t offset) status_t -CachedNode::Allocate(Transaction &transaction, bplustree_node **_node, - off_t *_offset) +CachedNode::Allocate(Transaction& transaction, bplustree_node** _node, + off_t* _offset) { if (fTree == NULL || fTree->fHeader == NULL || fTree->fStream == NULL) RETURN_ERROR(B_BAD_VALUE); Unset(); - bplustree_header *header; + bplustree_header* header; status_t status; // if there are any free nodes, recycle them @@ -303,7 +306,7 @@ CachedNode::Allocate(Transaction &transaction, bplustree_node **_node, } // allocate space for a new node - Inode *stream = fTree->fStream; + Inode* stream = fTree->fStream; if ((status = stream->Append(transaction, fTree->fNodeSize)) < B_OK) return status; @@ -335,7 +338,7 @@ CachedNode::Allocate(Transaction &transaction, bplustree_node **_node, // #pragma mark - -BPlusTree::BPlusTree(Transaction &transaction, Inode *stream, int32 nodeSize) +BPlusTree::BPlusTree(Transaction& transaction, Inode* stream, int32 nodeSize) : fStream(NULL), fHeader(NULL), @@ -346,7 +349,7 @@ BPlusTree::BPlusTree(Transaction &transaction, Inode *stream, int32 nodeSize) } -BPlusTree::BPlusTree(Inode *stream) +BPlusTree::BPlusTree(Inode* stream) : fStream(NULL), fHeader(NULL), @@ -388,13 +391,13 @@ BPlusTree::~BPlusTree() /*! Create a new B+Tree on the specified stream */ status_t -BPlusTree::SetTo(Transaction &transaction, Inode *stream, int32 nodeSize) +BPlusTree::SetTo(Transaction& transaction, Inode* stream, int32 nodeSize) { // initializes in-memory B+Tree fStream = stream; - bplustree_header *header = fCachedHeader.SetToWritableHeader(transaction); + bplustree_header* header = fCachedHeader.SetToWritableHeader(transaction); if (header == NULL) { // allocate space for new header + node! fStatus = stream->SetFileSize(transaction, nodeSize * 2); @@ -419,7 +422,8 @@ BPlusTree::SetTo(Transaction &transaction, Inode *stream, int32 nodeSize) header->max_number_of_levels = HOST_ENDIAN_TO_BFS_INT32(1); header->data_type = HOST_ENDIAN_TO_BFS_INT32(ModeToKeyType(stream->Mode())); header->root_node_pointer = HOST_ENDIAN_TO_BFS_INT64(nodeSize); - header->free_node_pointer = HOST_ENDIAN_TO_BFS_INT64((uint64)BPLUSTREE_NULL); + header->free_node_pointer + = HOST_ENDIAN_TO_BFS_INT64((uint64)BPLUSTREE_NULL); header->maximum_size = HOST_ENDIAN_TO_BFS_INT64(nodeSize * 2); // initialize b+tree root node @@ -435,7 +439,7 @@ BPlusTree::SetTo(Transaction &transaction, Inode *stream, int32 nodeSize) status_t -BPlusTree::SetTo(Inode *stream) +BPlusTree::SetTo(Inode* stream) { if (stream == NULL) RETURN_ERROR(fStatus = B_BAD_VALUE); @@ -463,7 +467,7 @@ BPlusTree::SetTo(Inode *stream) || !fHeader->IsValidLink(fHeader->FreeNode())) { #ifdef DEBUG dump_bplustree_header(fHeader); - dump_block((const char *)fHeader, 128); + dump_block((const char*)fHeader, 128); #endif RETURN_ERROR(fStatus = B_BAD_DATA); } @@ -537,7 +541,7 @@ int32 BPlusTree::ModeToKeyType(mode_t mode) { switch (mode & (S_STR_INDEX | S_INT_INDEX | S_UINT_INDEX | S_LONG_LONG_INDEX - | S_ULONG_LONG_INDEX | S_FLOAT_INDEX | S_DOUBLE_INDEX)) { + | S_ULONG_LONG_INDEX | S_FLOAT_INDEX | S_DOUBLE_INDEX)) { case S_INT_INDEX: return BPLUSTREE_INT32_TYPE; case S_UINT_INDEX: @@ -578,7 +582,7 @@ BPlusTree::_UpdateIterators(off_t offset, off_t nextOffset, uint16 keyIndex, void -BPlusTree::_AddIterator(TreeIterator *iterator) +BPlusTree::_AddIterator(TreeIterator* iterator) { MutexLocker _(fIteratorLock); fIterators.Add(iterator); @@ -586,7 +590,7 @@ BPlusTree::_AddIterator(TreeIterator *iterator) void -BPlusTree::_RemoveIterator(TreeIterator *iterator) +BPlusTree::_RemoveIterator(TreeIterator* iterator) { MutexLocker _(fIteratorLock); fIterators.Remove(iterator); @@ -594,7 +598,7 @@ BPlusTree::_RemoveIterator(TreeIterator *iterator) int32 -BPlusTree::_CompareKeys(const void *key1, int keyLength1, const void *key2, +BPlusTree::_CompareKeys(const void* key1, int keyLength1, const void* key2, int keyLength2) { type_code type = 0; @@ -626,8 +630,8 @@ BPlusTree::_CompareKeys(const void *key1, int keyLength1, const void *key2, status_t -BPlusTree::_FindKey(const bplustree_node *node, const uint8 *key, - uint16 keyLength, uint16 *_index, off_t *_next) +BPlusTree::_FindKey(const bplustree_node* node, const uint8* key, + uint16 keyLength, uint16* _index, off_t* _next) { #ifdef DEBUG NodeChecker checker(node, fNodeSize, "find"); @@ -641,7 +645,7 @@ BPlusTree::_FindKey(const bplustree_node *node, const uint8 *key, return B_ENTRY_NOT_FOUND; } - off_t *values = node->Values(); + off_t* values = node->Values(); int16 saveIndex = -1; // binary search in the key array @@ -649,9 +653,9 @@ BPlusTree::_FindKey(const bplustree_node *node, const uint8 *key, uint16 i = (first + last) >> 1; uint16 searchLength; - uint8 *searchKey = node->KeyAt(i, &searchLength); + uint8* searchKey = node->KeyAt(i, &searchLength); if (searchKey + searchLength + sizeof(off_t) + sizeof(uint16) - > (uint8 *)node + fNodeSize + > (uint8*)node + fNodeSize || searchLength > BPLUSTREE_MAX_KEY_LENGTH) { fStream->GetVolume()->Panic(); RETURN_ERROR(B_BAD_DATA); @@ -684,13 +688,12 @@ BPlusTree::_FindKey(const bplustree_node *node, const uint8 *key, } -/*! - Prepares the stack to contain all nodes that were passed while +/*! Prepares the stack to contain all nodes that were passed while following the key, from the root node to the leaf node that could or should contain that key. */ status_t -BPlusTree::_SeekDown(Stack &stack, const uint8 *key, +BPlusTree::_SeekDown(Stack& stack, const uint8* key, uint16 keyLength) { // set the root node to begin with @@ -698,7 +701,7 @@ BPlusTree::_SeekDown(Stack &stack, const uint8 *key, nodeAndKey.nodeOffset = fHeader->RootNode(); CachedNode cached(this); - const bplustree_node *node; + const bplustree_node* node; while ((node = cached.SetTo(nodeAndKey.nodeOffset)) != NULL) { // if we are already on leaf level, we're done if (node->OverflowLink() == BPLUSTREE_NULL) { @@ -733,16 +736,15 @@ BPlusTree::_SeekDown(Stack &stack, const uint8 *key, } -/*! - This will find a free duplicate fragment in the given bplustree_node. +/*! This will find a free duplicate fragment in the given bplustree_node. The CachedNode will be set to the writable fragment on success. */ status_t -BPlusTree::_FindFreeDuplicateFragment(Transaction &transaction, - const bplustree_node *node, CachedNode &cached, - off_t *_offset, bplustree_node **_fragment, uint32 *_index) +BPlusTree::_FindFreeDuplicateFragment(Transaction& transaction, + const bplustree_node* node, CachedNode& cached, + off_t* _offset, bplustree_node** _fragment, uint32* _index) { - off_t *values = node->Values(); + off_t* values = node->Values(); for (int32 i = 0; i < node->NumKeys(); i++) { off_t value = BFS_ENDIAN_TO_HOST_INT64(values[i]); @@ -750,7 +752,7 @@ BPlusTree::_FindFreeDuplicateFragment(Transaction &transaction, if (bplustree_node::LinkType(value) != BPLUSTREE_DUPLICATE_FRAGMENT) continue; - const bplustree_node *fragment = cached.SetTo( + const bplustree_node* fragment = cached.SetTo( bplustree_node::FragmentOffset(value), false); if (fragment == NULL) { FATAL(("Could not get duplicate fragment at %Ld\n", value)); @@ -760,7 +762,7 @@ BPlusTree::_FindFreeDuplicateFragment(Transaction &transaction, // see if there is some space left for us uint32 num = bplustree_node::MaxFragments(fNodeSize); for (uint32 j = 0; j < num; j++) { - duplicate_array *array = fragment->FragmentAt(j); + duplicate_array* array = fragment->FragmentAt(j); if (array->count == 0) { // found an unused fragment @@ -779,11 +781,11 @@ BPlusTree::_FindFreeDuplicateFragment(Transaction &transaction, status_t -BPlusTree::_InsertDuplicate(Transaction &transaction, CachedNode &cached, - const bplustree_node *node, uint16 index, off_t value) +BPlusTree::_InsertDuplicate(Transaction& transaction, CachedNode& cached, + const bplustree_node* node, uint16 index, off_t value) { CachedNode cachedDuplicate(this); - off_t *values = node->Values(); + off_t* values = node->Values(); off_t oldValue = BFS_ENDIAN_TO_HOST_INT64(values[index]); status_t status; off_t offset; @@ -792,29 +794,32 @@ BPlusTree::_InsertDuplicate(Transaction &transaction, CachedNode &cached, // If it's a duplicate fragment, try to insert it into that, or if it // doesn't fit anymore, create a new duplicate node - if (bplustree_node::LinkType(oldValue) == BPLUSTREE_DUPLICATE_FRAGMENT) { - bplustree_node *duplicate = cachedDuplicate.SetToWritable(transaction, + if (bplustree_node::LinkType(oldValue) + == BPLUSTREE_DUPLICATE_FRAGMENT) { + bplustree_node* duplicate + = cachedDuplicate.SetToWritable(transaction, bplustree_node::FragmentOffset(oldValue), false); if (duplicate == NULL) return B_IO_ERROR; - duplicate_array *array = duplicate->FragmentAt( + duplicate_array* array = duplicate->FragmentAt( bplustree_node::FragmentIndex(oldValue)); if (array->count > NUM_FRAGMENT_VALUES || array->count < 1) { - FATAL(("insertDuplicate: Invalid array[%d] size in fragment %Ld == %Ld!\n", + FATAL(("insertDuplicate: Invalid array[%d] size in fragment " + "%Ld == %Ld!\n", (int)bplustree_node::FragmentIndex(oldValue), - bplustree_node::FragmentOffset(oldValue), - array->count)); + bplustree_node::FragmentOffset(oldValue), array->count)); return B_BAD_DATA; } if (array->count < NUM_FRAGMENT_VALUES) { array->Insert(value); } else { - // test if the fragment will be empty if we remove this key's values + // Test if the fragment will be empty if we remove this key's + // values if (duplicate->FragmentsUsed(fNodeSize) < 2) { - // the node will be empty without our values, so let us + // The node will be empty without our values, so let us // reuse it as a duplicate node offset = bplustree_node::FragmentOffset(oldValue); @@ -826,19 +831,20 @@ BPlusTree::_InsertDuplicate(Transaction &transaction, CachedNode &cached, array = duplicate->DuplicateArray(); array->Insert(value); } else { - // create a new duplicate node + // Create a new duplicate node cachedDuplicate.UnsetUnchanged(transaction); - // the old duplicate has not been touched, so we can reuse it + // The old duplicate has not been touched, so we can + // reuse it - bplustree_node *newDuplicate; + bplustree_node* newDuplicate; status = cachedDuplicate.Allocate(transaction, &newDuplicate, &offset); if (status < B_OK) RETURN_ERROR(status); - // copy the array from the fragment node to the duplicate node - // and free the old entry (by zero'ing all values) + // Copy the array from the fragment node to the duplicate + // node and free the old entry (by zero'ing all values) newDuplicate->overflow_link = HOST_ENDIAN_TO_BFS_INT64( array->count); memcpy(&newDuplicate->all_key_count, &array->values[0], @@ -849,12 +855,13 @@ BPlusTree::_InsertDuplicate(Transaction &transaction, CachedNode &cached, array->Insert(value); } - // update the main pointer to link to a duplicate node + // Update the main pointer to link to a duplicate node if (cached.MakeWritable(transaction) == NULL) return B_IO_ERROR; - values[index] = HOST_ENDIAN_TO_BFS_INT64(bplustree_node::MakeLink( - BPLUSTREE_DUPLICATE_NODE, offset)); + values[index] + = HOST_ENDIAN_TO_BFS_INT64(bplustree_node::MakeLink( + BPLUSTREE_DUPLICATE_NODE, offset)); } return B_OK; @@ -863,8 +870,8 @@ BPlusTree::_InsertDuplicate(Transaction &transaction, CachedNode &cached, // Put the value into a dedicated duplicate node // search for free space in the duplicate nodes of that key - duplicate_array *array; - const bplustree_node *duplicate; + duplicate_array* array; + const bplustree_node* duplicate; off_t duplicateOffset; do { duplicateOffset = bplustree_node::FragmentOffset(oldValue); @@ -874,14 +881,15 @@ BPlusTree::_InsertDuplicate(Transaction &transaction, CachedNode &cached, 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; } } while (array->count >= NUM_DUPLICATE_VALUES && (oldValue = duplicate->RightLink()) != BPLUSTREE_NULL); - bplustree_node *writableDuplicate = cachedDuplicate.MakeWritable(transaction); + bplustree_node* writableDuplicate + = cachedDuplicate.MakeWritable(transaction); if (writableDuplicate == NULL) return B_IO_ERROR; @@ -891,8 +899,9 @@ BPlusTree::_InsertDuplicate(Transaction &transaction, CachedNode &cached, } else { // no space left - add a new duplicate node - bplustree_node *newDuplicate; - status = cachedDuplicate.Allocate(transaction, &newDuplicate, &offset); + bplustree_node* newDuplicate; + status = cachedDuplicate.Allocate(transaction, &newDuplicate, + &offset); if (status < B_OK) RETURN_ERROR(status); @@ -911,7 +920,7 @@ BPlusTree::_InsertDuplicate(Transaction &transaction, CachedNode &cached, // to insert the duplicate value into uint32 fragmentIndex = 0; - bplustree_node *fragment; + bplustree_node* fragment; if (_FindFreeDuplicateFragment(transaction, node, cachedDuplicate, &offset, &fragment, &fragmentIndex) != B_OK) { // allocate a new duplicate fragment node @@ -922,7 +931,7 @@ BPlusTree::_InsertDuplicate(Transaction &transaction, CachedNode &cached, memset(fragment, 0, fNodeSize); } - duplicate_array *array = fragment->FragmentAt(fragmentIndex); + duplicate_array* array = fragment->FragmentAt(fragmentIndex); array->Insert(oldValue); array->Insert(value); @@ -937,23 +946,23 @@ BPlusTree::_InsertDuplicate(Transaction &transaction, CachedNode &cached, void -BPlusTree::_InsertKey(bplustree_node *node, uint16 index, uint8 *key, +BPlusTree::_InsertKey(bplustree_node* node, uint16 index, uint8* key, uint16 keyLength, off_t value) { // should never happen, but who knows? if (index > node->NumKeys()) return; - off_t *values = node->Values(); - uint16 *keyLengths = node->KeyLengths(); - uint8 *keys = node->Keys(); + off_t* values = node->Values(); + uint16* keyLengths = node->KeyLengths(); + uint8* keys = node->Keys(); node->all_key_count = HOST_ENDIAN_TO_BFS_INT16(node->NumKeys() + 1); node->all_key_length = HOST_ENDIAN_TO_BFS_INT16(node->AllKeyLength() + keyLength); - off_t *newValues = node->Values(); - uint16 *newKeyLengths = node->KeyLengths(); + off_t* newValues = node->Values(); + uint16* newKeyLengths = node->KeyLengths(); // move values and copy new value into them memmove(newValues + index + 1, values + index, @@ -984,23 +993,22 @@ BPlusTree::_InsertKey(bplustree_node *node, uint16 index, uint8 *key, } -/*! - Splits the \a node into two halves - the other half will be put into \a other. - It also takes care to create a new overflow link if the node to split is an - index node. +/*! Splits the \a node into two halves - the other half will be put into + \a other. It also takes care to create a new overflow link if the node + to split is an index node. */ status_t -BPlusTree::_SplitNode(bplustree_node *node, off_t nodeOffset, - bplustree_node *other, off_t otherOffset, uint16 *_keyIndex, uint8 *key, - uint16 *_keyLength, off_t *_value) +BPlusTree::_SplitNode(bplustree_node* node, off_t nodeOffset, + bplustree_node* other, off_t otherOffset, uint16* _keyIndex, uint8* key, + uint16* _keyLength, off_t* _value) { if (*_keyIndex > node->NumKeys() + 1) return B_BAD_VALUE; - uint16 *inKeyLengths = node->KeyLengths(); - off_t *inKeyValues = node->Values(); - uint8 *inKeys = node->Keys(); - uint8 *outKeys = other->Keys(); + uint16* inKeyLengths = node->KeyLengths(); + off_t* inKeyValues = node->Values(); + uint8* inKeys = node->Keys(); + uint8* outKeys = other->Keys(); int32 keyIndex = *_keyIndex; // can become less than zero! if (keyIndex > node->NumKeys()) { @@ -1059,8 +1067,8 @@ BPlusTree::_SplitNode(bplustree_node *node, off_t nodeOffset, + bytesAfter); other->all_key_count = HOST_ENDIAN_TO_BFS_INT16(out); - uint16 *outKeyLengths = other->KeyLengths(); - off_t *outKeyValues = other->Values(); + uint16* outKeyLengths = other->KeyLengths(); + off_t* outKeyValues = other->Values(); int32 keys = out > keyIndex ? keyIndex : out; if (bytesBefore) { @@ -1082,7 +1090,8 @@ BPlusTree::_SplitNode(bplustree_node *node, off_t nodeOffset, keys = out - keyIndex - 1; for (int32 i = 0;i < keys;i++) { outKeyLengths[keyIndex + i + 1] = HOST_ENDIAN_TO_BFS_INT16( - BFS_ENDIAN_TO_HOST_INT16(inKeyLengths[keyIndex + i]) + bytes); + BFS_ENDIAN_TO_HOST_INT16(inKeyLengths[keyIndex + i]) + + bytes); } memcpy(outKeyValues + keyIndex + 1, inKeyValues + keyIndex, keys * sizeof(off_t)); @@ -1097,7 +1106,7 @@ BPlusTree::_SplitNode(bplustree_node *node, off_t nodeOffset, // these variables are for the key that will be returned // to the parent node - uint8 *newKey = NULL; + uint8* newKey = NULL; uint16 newLength; bool newAllocated = false; @@ -1115,14 +1124,14 @@ BPlusTree::_SplitNode(bplustree_node *node, off_t nodeOffset, } else { // If a key is dropped (is not the new key), we have to copy // it, because it would be lost if not. - uint8 *droppedKey = node->KeyAt(in, &newLength); + uint8* droppedKey = node->KeyAt(in, &newLength); if (droppedKey + newLength + sizeof(off_t) + sizeof(uint16) - > (uint8 *)node + fNodeSize + > (uint8*)node + fNodeSize || newLength > BPLUSTREE_MAX_KEY_LENGTH) { fStream->GetVolume()->Panic(); RETURN_ERROR(B_BAD_DATA); } - newKey = (uint8 *)malloc(newLength); + newKey = (uint8*)malloc(newLength); if (newKey == NULL) return B_NO_MEMORY; @@ -1249,7 +1258,7 @@ BPlusTree::_SplitNode(bplustree_node *node, off_t nodeOffset, You need to have the inode write locked. */ status_t -BPlusTree::Insert(Transaction &transaction, const uint8 *key, uint16 keyLength, +BPlusTree::Insert(Transaction& transaction, const uint8* key, uint16 keyLength, off_t value) { if (keyLength < BPLUSTREE_MIN_KEY_LENGTH @@ -1272,7 +1281,7 @@ BPlusTree::Insert(Transaction &transaction, const uint8 *key, uint16 keyLength, keyBuffer[keyLength] = 0; node_and_key nodeAndKey; - const bplustree_node *node; + const bplustree_node* node; CachedNode cached(this); while (stack.Pop(&nodeAndKey) @@ -1299,7 +1308,7 @@ BPlusTree::Insert(Transaction &transaction, const uint8 *key, uint16 keyLength, } } - bplustree_node *writableNode = cached.MakeWritable(transaction); + bplustree_node* writableNode = cached.MakeWritable(transaction); if (writableNode == NULL) return B_IO_ERROR; @@ -1322,7 +1331,7 @@ BPlusTree::Insert(Transaction &transaction, const uint8 *key, uint16 keyLength, // it now off_t newRoot = BPLUSTREE_NULL; if (nodeAndKey.nodeOffset == fHeader->RootNode()) { - bplustree_node *root; + bplustree_node* root; status_t status = cachedNewRoot.Allocate(transaction, &root, &newRoot); if (status < B_OK) { @@ -1337,7 +1346,7 @@ BPlusTree::Insert(Transaction &transaction, const uint8 *key, uint16 keyLength, } // reserve space for the other node - bplustree_node *other; + bplustree_node* other; off_t otherOffset; status_t status = cachedOther.Allocate(transaction, &other, &otherOffset); @@ -1371,14 +1380,14 @@ BPlusTree::Insert(Transaction &transaction, const uint8 *key, uint16 keyLength, // create a new root if necessary if (newRoot != BPLUSTREE_NULL) { - bplustree_node *root = cachedNewRoot.Node(); + bplustree_node* root = cachedNewRoot.Node(); _InsertKey(root, 0, keyBuffer, keyLength, writableNode->LeftLink()); root->overflow_link = HOST_ENDIAN_TO_BFS_INT64( nodeAndKey.nodeOffset); - bplustree_header *header + bplustree_header* header = fCachedHeader.MakeWritableHeader(transaction); if (header == NULL) return B_IO_ERROR; @@ -1400,29 +1409,30 @@ BPlusTree::Insert(Transaction &transaction, const uint8 *key, uint16 keyLength, It's part of the private tree interface. */ status_t -BPlusTree::_RemoveDuplicate(Transaction &transaction, - const bplustree_node *node, CachedNode &cached, uint16 index, +BPlusTree::_RemoveDuplicate(Transaction& transaction, + const bplustree_node* node, CachedNode& cached, uint16 index, off_t value) { - off_t *values = node->Values(); + off_t* values = node->Values(); off_t oldValue = BFS_ENDIAN_TO_HOST_INT64(values[index]); CachedNode cachedDuplicate(this); off_t duplicateOffset = bplustree_node::FragmentOffset(oldValue); - bplustree_node *duplicate = cachedDuplicate.SetToWritable(transaction, + bplustree_node* duplicate = cachedDuplicate.SetToWritable(transaction, duplicateOffset, false); if (duplicate == NULL) return B_IO_ERROR; // if it's a duplicate fragment, remove the entry from there if (bplustree_node::LinkType(oldValue) == BPLUSTREE_DUPLICATE_FRAGMENT) { - duplicate_array *array = duplicate->FragmentAt( + duplicate_array* array = duplicate->FragmentAt( bplustree_node::FragmentIndex(oldValue)); if (array->count > NUM_FRAGMENT_VALUES || array->count < 1) { - FATAL(("removeDuplicate: Invalid array[%d] size in fragment %Ld == %Ld!\n", - (int)bplustree_node::FragmentIndex(oldValue), duplicateOffset, array->count)); + FATAL(("removeDuplicate: Invalid array[%d] size in fragment %Ld " + "== %Ld!\n", (int)bplustree_node::FragmentIndex(oldValue), + duplicateOffset, array->count)); return B_BAD_DATA; } if (!array->Remove(value)) { @@ -1442,7 +1452,8 @@ BPlusTree::_RemoveDuplicate(Transaction &transaction, // Remove the whole fragment node, if this was the only array, // otherwise free just the array if (duplicate->FragmentsUsed(fNodeSize) == 1) { - status_t status = cachedDuplicate.Free(transaction, duplicateOffset); + status_t status = cachedDuplicate.Free(transaction, + duplicateOffset); if (status < B_OK) return status; } else @@ -1453,7 +1464,7 @@ BPlusTree::_RemoveDuplicate(Transaction &transaction, // Remove value from a duplicate node! - duplicate_array *array = NULL; + duplicate_array* array = NULL; if (duplicate->LeftLink() != BPLUSTREE_NULL) { FATAL(("invalid duplicate node: first left link points to %Ld!\n", @@ -1466,8 +1477,8 @@ BPlusTree::_RemoveDuplicate(Transaction &transaction, 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; } @@ -1478,7 +1489,8 @@ BPlusTree::_RemoveDuplicate(Transaction &transaction, RETURN_ERROR(B_ENTRY_NOT_FOUND); cachedDuplicate.UnsetUnchanged(transaction); - duplicate = cachedDuplicate.SetToWritable(transaction, duplicateOffset, false); + duplicate = cachedDuplicate.SetToWritable(transaction, duplicateOffset, + false); } if (duplicate == NULL) RETURN_ERROR(B_IO_ERROR); @@ -1502,41 +1514,48 @@ BPlusTree::_RemoveDuplicate(Transaction &transaction, return B_IO_ERROR; if (array->count == 1) { - // this is the last node, and there is only one value left; - // replace the duplicate link with that value, it's no duplicate - // anymore + // This is the last node, and there is only one value left; + // replace the duplicate link with that value, it's no + // duplicate anymore values[index] = array->values[0]; } else { - // move the duplicate link to the next node - values[index] = HOST_ENDIAN_TO_BFS_INT64(bplustree_node::MakeLink( - BPLUSTREE_DUPLICATE_NODE, right)); + // Move the duplicate link to the next node + values[index] = HOST_ENDIAN_TO_BFS_INT64( + bplustree_node::MakeLink( + BPLUSTREE_DUPLICATE_NODE, right)); } } - status_t status; - if ((status = cachedDuplicate.Free(transaction, duplicateOffset)) < B_OK) + status_t status = cachedDuplicate.Free(transaction, + duplicateOffset); + if (status < B_OK) return status; if (left != BPLUSTREE_NULL - && (duplicate = cachedDuplicate.SetToWritable(transaction, left, false)) != NULL) { + && (duplicate = cachedDuplicate.SetToWritable(transaction, left, + false)) != NULL) { duplicate->right_link = HOST_ENDIAN_TO_BFS_INT64(right); // If the next node is the last node, we need to free that node // and convert the duplicate entry back into a normal entry array = duplicate->DuplicateArray(); - if (right == BPLUSTREE_NULL && duplicate->LeftLink() == BPLUSTREE_NULL + if (right == BPLUSTREE_NULL + && duplicate->LeftLink() == BPLUSTREE_NULL && array->count <= NUM_FRAGMENT_VALUES) { duplicateOffset = left; continue; } } if (right != BPLUSTREE_NULL - && (duplicate = cachedDuplicate.SetToWritable(transaction, right, false)) != NULL) { + && (duplicate = cachedDuplicate.SetToWritable(transaction, + right, false)) != NULL) { duplicate->left_link = HOST_ENDIAN_TO_BFS_INT64(left); - // Again, we may need to turn the duplicate entry back into a normal entry + // Again, we may need to turn the duplicate entry back into a + // normal entry array = duplicate->DuplicateArray(); - if (left == BPLUSTREE_NULL && duplicate->RightLink() == BPLUSTREE_NULL + if (left == BPLUSTREE_NULL + && duplicate->RightLink() == BPLUSTREE_NULL && array->count <= NUM_FRAGMENT_VALUES) { duplicateOffset = right; continue; @@ -1549,21 +1568,23 @@ BPlusTree::_RemoveDuplicate(Transaction &transaction, // fragment node. CachedNode cachedOther(this); - bplustree_node *fragment = NULL; + bplustree_node* fragment = NULL; uint32 fragmentIndex = 0; off_t offset; if (_FindFreeDuplicateFragment(transaction, node, cachedOther, &offset, &fragment, &fragmentIndex) == B_OK) { // move to other node - duplicate_array *target = fragment->FragmentAt(fragmentIndex); - memcpy(target, array, (NUM_FRAGMENT_VALUES + 1) * sizeof(off_t)); + duplicate_array* target = fragment->FragmentAt(fragmentIndex); + memcpy(target, array, + (NUM_FRAGMENT_VALUES + 1) * sizeof(off_t)); cachedDuplicate.Free(transaction, duplicateOffset); duplicateOffset = offset; } else { // convert node - memmove(duplicate, array, (NUM_FRAGMENT_VALUES + 1) * sizeof(off_t)); - memset((off_t *)duplicate + NUM_FRAGMENT_VALUES + 1, 0, + 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)); } @@ -1584,7 +1605,7 @@ BPlusTree::_RemoveDuplicate(Transaction &transaction, the calling method (BPlusTree::Remove()) have this data. */ void -BPlusTree::_RemoveKey(bplustree_node *node, uint16 index) +BPlusTree::_RemoveKey(bplustree_node* node, uint16 index) { // should never happen, but who knows? if (index > node->NumKeys() && node->NumKeys() > 0) { @@ -1592,7 +1613,7 @@ BPlusTree::_RemoveKey(bplustree_node *node, uint16 index) return; } - off_t *values = node->Values(); + off_t* values = node->Values(); // if we would have to drop the overflow link, drop // the last key instead and update the overflow link @@ -1601,23 +1622,25 @@ BPlusTree::_RemoveKey(bplustree_node *node, uint16 index) node->overflow_link = values[--index]; uint16 length; - uint8 *key = node->KeyAt(index, &length); - if (key + length + sizeof(off_t) + sizeof(uint16) > (uint8 *)node + fNodeSize + 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 %d,%u)\n", key, length, - (int)fStream->BlockRun().allocation_group, fStream->BlockRun().start)); + (int)fStream->BlockRun().allocation_group, + fStream->BlockRun().start)); fStream->GetVolume()->Panic(); return; } - uint16 *keyLengths = node->KeyLengths(); - uint8 *keys = node->Keys(); + uint16* keyLengths = node->KeyLengths(); + uint8* keys = node->Keys(); node->all_key_count = HOST_ENDIAN_TO_BFS_INT16(node->NumKeys() - 1); - node->all_key_length = HOST_ENDIAN_TO_BFS_INT64(node->AllKeyLength() - length); + node->all_key_length = HOST_ENDIAN_TO_BFS_INT64( + node->AllKeyLength() - length); - off_t *newValues = node->Values(); - uint16 *newKeyLengths = node->KeyLengths(); + off_t* newValues = node->Values(); + uint16* newKeyLengths = node->KeyLengths(); // move key data memmove(key, key + length, node->AllKeyLength() - (key - keys)); @@ -1633,8 +1656,10 @@ BPlusTree::_RemoveKey(bplustree_node *node, uint16 index) // move values if (index > 0) memmove(newValues, values, index * sizeof(off_t)); - if (node->NumKeys() > index) - memmove(newValues + index, values + index + 1, (node->NumKeys() - index) * sizeof(off_t)); + if (node->NumKeys() > index) { + memmove(newValues + index, values + index + 1, + (node->NumKeys() - index) * sizeof(off_t)); + } } @@ -1644,7 +1669,7 @@ BPlusTree::_RemoveKey(bplustree_node *node, uint16 index) You need to have the inode write locked. */ status_t -BPlusTree::Remove(Transaction &transaction, const uint8 *key, uint16 keyLength, +BPlusTree::Remove(Transaction& transaction, const uint8* key, uint16 keyLength, off_t value) { if (keyLength < BPLUSTREE_MIN_KEY_LENGTH @@ -1658,7 +1683,7 @@ BPlusTree::Remove(Transaction &transaction, const uint8 *key, uint16 keyLength, RETURN_ERROR(B_ERROR); node_and_key nodeAndKey; - const bplustree_node *node; + const bplustree_node* node; CachedNode cached(this); while (stack.Pop(&nodeAndKey) @@ -1689,13 +1714,14 @@ BPlusTree::Remove(Transaction &transaction, const uint8 *key, uint16 keyLength, return _RemoveDuplicate(transaction, node, cached, nodeAndKey.keyIndex, value); } else { - FATAL(("dupliate node found where no duplicates are allowed!\n")); + FATAL(("dupliate node found where no duplicates are " + "allowed!\n")); RETURN_ERROR(B_ERROR); } } } - bplustree_node *writableNode = cached.MakeWritable(transaction); + bplustree_node* writableNode = cached.MakeWritable(transaction); if (writableNode == NULL) return B_IO_ERROR; @@ -1703,15 +1729,18 @@ BPlusTree::Remove(Transaction &transaction, const uint8 *key, uint16 keyLength, // to a leaf node by dropping the overflow link, or, // if it's already a leaf node, just empty it if (nodeAndKey.nodeOffset == fHeader->RootNode() - && (node->NumKeys() == 0 || (node->NumKeys() == 1 && node->IsLeaf()))) { - writableNode->overflow_link = HOST_ENDIAN_TO_BFS_INT64((uint64)BPLUSTREE_NULL); + && (node->NumKeys() == 0 + || (node->NumKeys() == 1 && node->IsLeaf()))) { + writableNode->overflow_link + = HOST_ENDIAN_TO_BFS_INT64((uint64)BPLUSTREE_NULL); writableNode->all_key_count = 0; writableNode->all_key_length = 0; // if we've made a leaf node out of the root node, we need // to reset the maximum number of levels in the header if (fHeader->MaxNumberOfLevels() != 1) { - bplustree_header *header = fCachedHeader.MakeWritableHeader(transaction); + bplustree_header* header + = fCachedHeader.MakeWritableHeader(transaction); if (header == NULL) return B_IO_ERROR; @@ -1733,13 +1762,15 @@ BPlusTree::Remove(Transaction &transaction, const uint8 *key, uint16 keyLength, // we have to update the right/left link of the // siblings first CachedNode otherCached(this); - bplustree_node *other = otherCached.SetToWritable(transaction, + bplustree_node* other = otherCached.SetToWritable(transaction, writableNode->LeftLink()); if (other != NULL) other->right_link = writableNode->right_link; - if ((other = otherCached.SetToWritable(transaction, node->RightLink())) != NULL) + if ((other = otherCached.SetToWritable(transaction, node->RightLink())) + != NULL) { other->left_link = writableNode->left_link; + } cached.Free(transaction, nodeAndKey.nodeOffset); } @@ -1757,8 +1788,8 @@ BPlusTree::Remove(Transaction &transaction, const uint8 *key, uint16 keyLength, You need to have the inode write locked. */ status_t -BPlusTree::Replace(Transaction &transaction, const uint8 *key, - uint16 keyLength, off_t value) +BPlusTree::Replace(Transaction& transaction, const uint8* key, uint16 keyLength, + off_t value) { if (keyLength < BPLUSTREE_MIN_KEY_LENGTH || keyLength > BPLUSTREE_MAX_KEY_LENGTH @@ -1772,19 +1803,21 @@ BPlusTree::Replace(Transaction &transaction, const uint8 *key, off_t nodeOffset = fHeader->RootNode(); CachedNode cached(this); - const bplustree_node *node; + const bplustree_node* node; while ((node = cached.SetTo(nodeOffset)) != NULL) { uint16 keyIndex = 0; off_t nextOffset; - status_t status = _FindKey(node, key, keyLength, &keyIndex, &nextOffset); + status_t status = _FindKey(node, key, keyLength, &keyIndex, + &nextOffset); if (node->OverflowLink() == BPLUSTREE_NULL) { if (status == B_OK) { - bplustree_node *writableNode = cached.MakeWritable(transaction); - if (writableNode != NULL) - writableNode->Values()[keyIndex] = HOST_ENDIAN_TO_BFS_INT64(value); - else + bplustree_node* writableNode = cached.MakeWritable(transaction); + if (writableNode != NULL) { + writableNode->Values()[keyIndex] + = HOST_ENDIAN_TO_BFS_INT64(value); + } else status = B_IO_ERROR; } @@ -1798,20 +1831,19 @@ BPlusTree::Replace(Transaction &transaction, const uint8 *key, } -/*! Searches the key in the tree, and stores the offset found in - _value, if successful. - It's very similar to BPlusTree::SeekDown(), but doesn't fill - a stack while it descends the tree. - Returns B_OK when the key could be found, B_ENTRY_NOT_FOUND - if not. It can also return other errors to indicate that - something went wrong. - Note that this doesn't work with duplicates - it will just - return B_BAD_TYPE if you call this function on a tree where - duplicates are allowed. +/*! Searches the key in the tree, and stores the offset found in _value, + if successful. + It's very similar to BPlusTree::SeekDown(), but doesn't fill a stack + while it descends the tree. + Returns B_OK when the key could be found, B_ENTRY_NOT_FOUND if not. + It can also return other errors to indicate that something went wrong. + Note that this doesn't work with duplicates - it will just return + B_BAD_TYPE if you call this function on a tree where duplicates are + allowed. You need to have the inode read or write locked. */ status_t -BPlusTree::Find(const uint8 *key, uint16 keyLength, off_t *_value) +BPlusTree::Find(const uint8* key, uint16 keyLength, off_t* _value) { if (keyLength < BPLUSTREE_MIN_KEY_LENGTH || keyLength > BPLUSTREE_MAX_KEY_LENGTH @@ -1825,7 +1857,7 @@ BPlusTree::Find(const uint8 *key, uint16 keyLength, off_t *_value) off_t nodeOffset = fHeader->RootNode(); CachedNode cached(this); - const bplustree_node *node; + const bplustree_node* node; #ifdef DEBUG int32 levels = 0; @@ -1834,7 +1866,8 @@ BPlusTree::Find(const uint8 *key, uint16 keyLength, off_t *_value) while ((node = cached.SetTo(nodeOffset)) != NULL) { uint16 keyIndex = 0; off_t nextOffset; - status_t status = _FindKey(node, key, keyLength, &keyIndex, &nextOffset); + status_t status = _FindKey(node, key, keyLength, &keyIndex, + &nextOffset); #ifdef DEBUG levels++; @@ -1861,7 +1894,7 @@ BPlusTree::Find(const uint8 *key, uint16 keyLength, off_t *_value) // #pragma mark - -TreeIterator::TreeIterator(BPlusTree *tree) +TreeIterator::TreeIterator(BPlusTree* tree) : fTree(tree), fCurrentNodeOffset(BPLUSTREE_NULL) @@ -1888,7 +1921,7 @@ TreeIterator::Goto(int8 to) off_t nodeOffset = fTree->fHeader->RootNode(); CachedNode cached(fTree); - const bplustree_node *node; + const bplustree_node* node; while ((node = cached.SetTo(nodeOffset)) != NULL) { // is the node a leaf node? @@ -1924,8 +1957,7 @@ TreeIterator::Goto(int8 to) } -/*! - Iterates through the tree in the specified direction. +/*! Iterates through the tree in the specified direction. When it iterates through duplicates, the "key" is only updated for the first entry - if you need to know when this happens, use the "duplicate" parameter which is 0 for no duplicate, 1 for the first, and 2 for all @@ -1937,8 +1969,8 @@ TreeIterator::Goto(int8 to) at once when they are not relevant to them. */ status_t -TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, - uint16 maxLength, off_t *value, uint16 *duplicate) +TreeIterator::Traverse(int8 direction, void* key, uint16* keyLength, + uint16 maxLength, off_t* value, uint16* duplicate) { if (fTree == NULL) return B_INTERRUPTED; @@ -1957,30 +1989,34 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, InodeReadLocker locker(fTree->fStream); CachedNode cached(fTree); - const bplustree_node *node; + const bplustree_node* node; 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 + // 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 - if (!fIsFragment || fDuplicate < fNumDuplicates) - node = cached.SetTo(bplustree_node::FragmentOffset(fDuplicateNode), false); - else + if (!fIsFragment || fDuplicate < fNumDuplicates) { + node = cached.SetTo(bplustree_node::FragmentOffset(fDuplicateNode), + false); + } else node = NULL; if (node != NULL) { 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(); if (fDuplicateNode != BPLUSTREE_NULL && (node = cached.SetTo(fDuplicateNode, false)) != NULL) { - fNumDuplicates = node->CountDuplicates(fDuplicateNode, false); + fNumDuplicates = node->CountDuplicates(fDuplicateNode, + false); fDuplicate = 0; } } if (fDuplicate < fNumDuplicates) { - *value = node->DuplicateAt(fDuplicateNode, fIsFragment, fDuplicate++); + *value = node->DuplicateAt(fDuplicateNode, fIsFragment, + fDuplicate++); if (duplicate) *duplicate = 2; return B_OK; @@ -2026,8 +2062,9 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, RETURN_ERROR(B_ERROR); // B_ENTRY_NOT_FOUND ? uint16 length; - uint8 *keyStart = node->KeyAt(fCurrentKey, &length); - if (keyStart + length + sizeof(off_t) + sizeof(uint16) > (uint8 *)node + fTree->fNodeSize + uint8* keyStart = node->KeyAt(fCurrentKey, &length); + if (keyStart + length + sizeof(off_t) + sizeof(uint16) + > (uint8*)node + fTree->fNodeSize || length > BPLUSTREE_MAX_KEY_LENGTH) { fTree->fStream->GetVolume()->Panic(); RETURN_ERROR(B_BAD_DATA); @@ -2040,7 +2077,7 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, // terminate string type if (length == maxLength) length--; - ((char *)key)[length] = '\0'; + ((char*)key)[length] = '\0'; } *keyLength = length; @@ -2048,10 +2085,12 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, // 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); + node = cached.SetTo(bplustree_node::FragmentOffset(fDuplicateNode), + false); if (node == NULL) RETURN_ERROR(B_ERROR); @@ -2064,7 +2103,8 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, if (duplicate) *duplicate = 1; } 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; offset = 0; } @@ -2080,11 +2120,12 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, key could be found or not. */ status_t -TreeIterator::Find(const uint8 *key, uint16 keyLength) +TreeIterator::Find(const uint8* key, uint16 keyLength) { if (fTree == NULL) return B_INTERRUPTED; - if (keyLength < BPLUSTREE_MIN_KEY_LENGTH || keyLength > BPLUSTREE_MAX_KEY_LENGTH + if (keyLength < BPLUSTREE_MIN_KEY_LENGTH + || keyLength > BPLUSTREE_MAX_KEY_LENGTH || key == NULL) RETURN_ERROR(B_BAD_VALUE); @@ -2094,7 +2135,7 @@ TreeIterator::Find(const uint8 *key, uint16 keyLength) off_t nodeOffset = fTree->fHeader->RootNode(); CachedNode cached(fTree); - const bplustree_node *node; + const bplustree_node* node; while ((node = cached.SetTo(nodeOffset)) != NULL) { uint16 keyIndex = 0; off_t nextOffset; @@ -2163,7 +2204,9 @@ TreeIterator::Dump() __out("\tfTree = %p\n", fTree); __out("\tfCurrentNodeOffset = %Ld\n", fCurrentNodeOffset); __out("\tfCurrentKey = %ld\n", fCurrentKey); - __out("\tfDuplicateNode = %Ld (%Ld, 0x%Lx)\n", bplustree_node::FragmentOffset(fDuplicateNode), fDuplicateNode, fDuplicateNode); + __out("\tfDuplicateNode = %Ld (%Ld, 0x%Lx)\n", + bplustree_node::FragmentOffset(fDuplicateNode), fDuplicateNode, + fDuplicateNode); __out("\tfDuplicate = %u\n", fDuplicate); __out("\tfNumDuplicates = %u\n", fNumDuplicates); __out("\tfIsFragment = %s\n", fIsFragment ? "true" : "false"); @@ -2177,20 +2220,21 @@ TreeIterator::Dump() void bplustree_node::Initialize() { - left_link = right_link = overflow_link = HOST_ENDIAN_TO_BFS_INT64((uint64)BPLUSTREE_NULL); + left_link = right_link = overflow_link + = HOST_ENDIAN_TO_BFS_INT64((uint64)BPLUSTREE_NULL); all_key_count = 0; all_key_length = 0; } -uint8 * -bplustree_node::KeyAt(int32 index, uint16 *keyLength) const +uint8* +bplustree_node::KeyAt(int32 index, uint16* keyLength) const { if (index < 0 || index > NumKeys()) return NULL; - uint8 *keyStart = Keys(); - uint16 *keyLengths = KeyLengths(); + uint8* keyStart = Keys(); + uint16* keyLengths = KeyLengths(); *keyLength = BFS_ENDIAN_TO_HOST_INT16(keyLengths[index]) - (index != 0 ? BFS_ENDIAN_TO_HOST_INT16(keyLengths[index - 1]) : 0); @@ -2210,7 +2254,7 @@ bplustree_node::CountDuplicates(off_t offset, bool isFragment) const if (isFragment) { uint32 fragment = (NUM_FRAGMENT_VALUES + 1) * ((uint64)offset & 0x3ff); - return ((off_t *)this)[fragment]; + return ((off_t*)this)[fragment]; } return OverflowLink(); } @@ -2225,7 +2269,7 @@ bplustree_node::DuplicateAt(off_t offset, bool isFragment, int8 index) const else start = 2; - return ((off_t *)this)[start + 1 + index]; + return ((off_t*)this)[start + 1 + index]; } @@ -2239,7 +2283,7 @@ bplustree_node::FragmentsUsed(uint32 nodeSize) const { uint32 used = 0; for (uint32 i = 0; i < MaxFragments(nodeSize); i++) { - duplicate_array *array = FragmentAt(i); + duplicate_array* array = FragmentAt(i); if (array->count > 0 && ++used > 1) return used; } @@ -2256,8 +2300,9 @@ bplustree_node::CheckIntegrity(uint32 nodeSize) const for (int32 i = 0; i < NumKeys(); i++) { uint16 length; - uint8 *key = KeyAt(i, &length); - if (key + length + sizeof(off_t) + sizeof(uint16) > (uint8 *)this + nodeSize + uint8* key = KeyAt(i, &length); + if (key + length + sizeof(off_t) + sizeof(uint16) + > (uint8*)this + nodeSize || length > BPLUSTREE_MAX_KEY_LENGTH) { dprintf("node %p, key %ld\n", this, i); DEBUGGER(("invalid node: keys corrupted")); @@ -2278,8 +2323,8 @@ bplustree_node::CheckIntegrity(uint32 nodeSize) const int32 -compareKeys(type_code type, const void *key1, int keyLength1, - const void *key2, int keyLength2) +compareKeys(type_code type, const void* key1, int keyLength1, + const void* key2, int keyLength2) { // if one of the keys is NULL, bail out gracefully if (key1 == NULL || key2 == NULL) { @@ -2300,9 +2345,9 @@ compareKeys(type_code type, const void *key1, int keyLength1, if (result == 0) { // ignore trailing null bytes if ((keyLength1 == keyLength2 + 1 - && ((uint8 *)key1)[keyLength2] == '\0') + && ((uint8*)key1)[keyLength2] == '\0') || (keyLength2 == keyLength1 + 1 - && ((uint8 *)key2)[keyLength1] == '\0')) + && ((uint8*)key2)[keyLength1] == '\0')) return 0; result = keyLength1 - keyLength2; @@ -2313,37 +2358,37 @@ compareKeys(type_code type, const void *key1, int keyLength1, case B_SSIZE_T_TYPE: case B_INT32_TYPE: - return *(int32 *)key1 - *(int32 *)key2; + return *(int32*)key1 - *(int32*)key2; case B_SIZE_T_TYPE: case B_UINT32_TYPE: - if (*(uint32 *)key1 == *(uint32 *)key2) + if (*(uint32*)key1 == *(uint32*)key2) return 0; - if (*(uint32 *)key1 > *(uint32 *)key2) + if (*(uint32*)key1 > *(uint32*)key2) return 1; return -1; case B_OFF_T_TYPE: case B_INT64_TYPE: - if (*(int64 *)key1 == *(int64 *)key2) + if (*(int64*)key1 == *(int64*)key2) return 0; - if (*(int64 *)key1 > *(int64 *)key2) + if (*(int64*)key1 > *(int64*)key2) return 1; return -1; case B_UINT64_TYPE: - if (*(uint64 *)key1 == *(uint64 *)key2) + if (*(uint64*)key1 == *(uint64*)key2) return 0; - if (*(uint64 *)key1 > *(uint64 *)key2) + if (*(uint64*)key1 > *(uint64*)key2) return 1; return -1; case B_FLOAT_TYPE: { - float result = *(float *)key1 - *(float *)key2; + float result = *(float*)key1 - *(float*)key2; if (result == 0.0f) return 0; @@ -2352,7 +2397,7 @@ compareKeys(type_code type, const void *key1, int keyLength1, case B_DOUBLE_TYPE: { - double result = *(double *)key1 - *(double *)key2; + double result = *(double*)key1 - *(double*)key2; if (result == 0.0) return 0; diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h index 2fe0487de8..317f9b8689 100644 --- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h +++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h @@ -20,56 +20,63 @@ struct check_cookie; class BlockAllocator { - public: - BlockAllocator(Volume *volume); - ~BlockAllocator(); +public: + BlockAllocator(Volume* volume); + ~BlockAllocator(); - status_t Initialize(bool full = true); - status_t InitializeAndClearBitmap(Transaction &transaction); + status_t Initialize(bool full = true); + status_t InitializeAndClearBitmap(Transaction& transaction); - void Uninitialize(); + void Uninitialize(); - status_t AllocateForInode(Transaction &transaction, const block_run *parent, - mode_t type, block_run &run); - status_t Allocate(Transaction &transaction, Inode *inode, off_t numBlocks, - block_run &run, uint16 minimum = 1); - status_t Free(Transaction &transaction, block_run run); + status_t AllocateForInode(Transaction& transaction, + const block_run* parent, mode_t type, + block_run& run); + status_t Allocate(Transaction& transaction, Inode* inode, + off_t numBlocks, block_run& run, + uint16 minimum = 1); + status_t Free(Transaction& transaction, block_run run); - status_t AllocateBlocks(Transaction &transaction, int32 group, uint16 start, - uint16 numBlocks, uint16 minimum, block_run &run); + status_t AllocateBlocks(Transaction& transaction, + int32 group, uint16 start, uint16 numBlocks, + uint16 minimum, block_run& run); - status_t StartChecking(check_control *control); - status_t StopChecking(check_control *control); - status_t CheckNextNode(check_control *control); + status_t StartChecking(check_control* control); + status_t StopChecking(check_control* control); + status_t CheckNextNode(check_control* control); - status_t CheckBlockRun(block_run run, const char *type = NULL, check_control *control = NULL, bool allocated = true); - status_t CheckInode(Inode *inode, check_control *control = NULL); + status_t CheckBlockRun(block_run run, + const char* type = NULL, + check_control* control = NULL, + bool allocated = true); + status_t CheckInode(Inode* inode, + check_control* control = NULL); - size_t BitmapSize() const; + size_t BitmapSize() const; #ifdef BFS_DEBUGGER_COMMANDS - void Dump(int32 index); + void Dump(int32 index); #endif - private: - bool _IsValidCheckControl(check_control *control); - bool _CheckBitmapIsUsedAt(off_t block) const; - void _SetCheckBitmapAt(off_t block); +private: + bool _IsValidCheckControl(check_control* control); + bool _CheckBitmapIsUsedAt(off_t block) const; + void _SetCheckBitmapAt(off_t block); - static status_t _Initialize(BlockAllocator *); + static status_t _Initialize(BlockAllocator* self); - Volume *fVolume; - mutex fLock; - AllocationGroup *fGroups; - int32 fNumGroups; - uint32 fBlocksPerGroup; + Volume* fVolume; + mutex fLock; + AllocationGroup* fGroups; + int32 fNumGroups; + uint32 fBlocksPerGroup; - uint32 *fCheckBitmap; - check_cookie *fCheckCookie; + uint32* fCheckBitmap; + check_cookie* fCheckCookie; }; #ifdef BFS_DEBUGGER_COMMANDS -int dump_block_allocator(int argc, char **argv); +int dump_block_allocator(int argc, char** argv); #endif -#endif /* BLOCK_ALLOCATOR_H */ +#endif // BLOCK_ALLOCATOR_H diff --git a/src/add-ons/kernel/file_systems/bfs/Index.cpp b/src/add-ons/kernel/file_systems/bfs/Index.cpp index 757d730763..03e3cb2582 100644 --- a/src/add-ons/kernel/file_systems/bfs/Index.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Index.cpp @@ -20,7 +20,7 @@ #endif -Index::Index(Volume *volume) +Index::Index(Volume* volume) : fVolume(volume), fNode(NULL) @@ -51,15 +51,14 @@ Index::Unset() } -/*! - Sets the index to specified one. Returns an error if the index could +/*! Sets the index to specified one. Returns an error if the index could not be found or initialized. Note, Index::Update() may be called on the object even if this method failed previously. In this case, it will only update live queries for the updated attribute. */ status_t -Index::SetTo(const char *name) +Index::SetTo(const char* name) { // remove the old node, if the index is set for the second time Unset(); @@ -71,18 +70,18 @@ Index::SetTo(const char *name) // Note, the name is saved even if the index couldn't be initialized! // This is used to optimize Index::Update() in case there is no index - Inode *indices = fVolume->IndicesNode(); + Inode* indices = fVolume->IndicesNode(); if (indices == NULL) return B_ENTRY_NOT_FOUND; InodeReadLocker locker(indices); - BPlusTree *tree; + BPlusTree* tree; if (indices->GetTree(&tree) != B_OK) return B_BAD_VALUE; ino_t 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; @@ -167,7 +166,7 @@ Index::KeySize() status_t -Index::Create(Transaction &transaction, const char *name, uint32 type) +Index::Create(Transaction &transaction, const char* name, uint32 type) { Unset(); @@ -222,9 +221,9 @@ Index::Create(Transaction &transaction, const char *name, uint32 type) You may not want to let the whole transaction fail because of that. */ 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) @@ -262,7 +261,7 @@ Index::Update(Transaction &transaction, const char *name, int32 type, newKey, newLength); } - BPlusTree *tree; + BPlusTree* tree; status_t status = Node()->GetTree(&tree); if (status < B_OK) return status; @@ -272,7 +271,7 @@ Index::Update(Transaction &transaction, const char *name, int32 type, Node()->WriteLockInTransaction(transaction); if (oldKey != NULL) { - status = tree->Remove(transaction, (const uint8 *)oldKey, oldLength, + status = tree->Remove(transaction, (const uint8*)oldKey, oldLength, inode->ID()); if (status == B_ENTRY_NOT_FOUND) { // That's not nice, but no reason to let the whole thing fail @@ -284,7 +283,7 @@ Index::Update(Transaction &transaction, const char *name, int32 type, // add the new key to the tree if (newKey != NULL) { - status = tree->Insert(transaction, (const uint8 *)newKey, newLength, + status = tree->Insert(transaction, (const uint8*)newKey, newLength, inode->ID()); } @@ -293,57 +292,57 @@ Index::Update(Transaction &transaction, const char *name, int32 type, 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); } 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); } 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) { ASSERT(inode->IsRegularNode()); uint16 oldLength = oldName != NULL ? strlen(oldName) : 0; uint16 newLength = newName != NULL ? 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); } status_t -Index::InsertSize(Transaction &transaction, Inode *inode) +Index::InsertSize(Transaction &transaction, Inode* inode) { ASSERT(inode->IsFile()); off_t size = inode->Size(); - return Update(transaction, "size", B_INT64_TYPE, NULL, 0, (uint8 *)&size, + return Update(transaction, "size", B_INT64_TYPE, NULL, 0, (uint8*)&size, sizeof(int64), inode); } status_t -Index::RemoveSize(Transaction &transaction, Inode *inode) +Index::RemoveSize(Transaction &transaction, Inode* inode) { ASSERT(inode->IsFile()); // Inode::OldSize() is the size that's in the index off_t size = inode->OldSize(); - return Update(transaction, "size", B_INT64_TYPE, (uint8 *)&size, + return Update(transaction, "size", B_INT64_TYPE, (uint8*)&size, sizeof(int64), NULL, 0, inode); } status_t -Index::UpdateSize(Transaction &transaction, Inode *inode) +Index::UpdateSize(Transaction &transaction, Inode* inode) { ASSERT(inode->IsFile()); @@ -351,7 +350,7 @@ Index::UpdateSize(Transaction &transaction, Inode *inode) off_t newSize = inode->Size(); status_t status = Update(transaction, "size", B_INT64_TYPE, - (uint8 *)&oldSize, sizeof(int64), (uint8 *)&newSize, sizeof(int64), + (uint8*)&oldSize, sizeof(int64), (uint8*)&newSize, sizeof(int64), inode); if (status == B_OK) inode->UpdateOldSize(); @@ -361,30 +360,30 @@ Index::UpdateSize(Transaction &transaction, Inode *inode) status_t -Index::InsertLastModified(Transaction &transaction, Inode *inode) +Index::InsertLastModified(Transaction &transaction, Inode* inode) { ASSERT(inode->IsFile() || inode->IsSymLink()); off_t modified = inode->LastModified(); return Update(transaction, "last_modified", B_INT64_TYPE, NULL, 0, - (uint8 *)&modified, sizeof(int64), inode); + (uint8*)&modified, sizeof(int64), inode); } status_t -Index::RemoveLastModified(Transaction &transaction, Inode *inode) +Index::RemoveLastModified(Transaction &transaction, Inode* inode) { ASSERT(inode->IsFile() || inode->IsSymLink()); // 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); + (uint8*)&modified, sizeof(int64), NULL, 0, inode); } status_t -Index::UpdateLastModified(Transaction &transaction, Inode *inode, +Index::UpdateLastModified(Transaction &transaction, Inode* inode, off_t modified) { ASSERT(inode->IsFile() || inode->IsSymLink()); @@ -395,7 +394,7 @@ Index::UpdateLastModified(Transaction &transaction, Inode *inode, modified |= fVolume->GetUniqueID() & INODE_TIME_MASK; status_t status = Update(transaction, "last_modified", B_INT64_TYPE, - (uint8 *)&oldModified, sizeof(int64), (uint8 *)&modified, + (uint8*)&oldModified, sizeof(int64), (uint8*)&modified, sizeof(int64), inode); inode->Node().last_modified_time = HOST_ENDIAN_TO_BFS_INT64(modified); diff --git a/src/add-ons/kernel/file_systems/bfs/Index.h b/src/add-ons/kernel/file_systems/bfs/Index.h index e2887edf39..8d8ba070d5 100644 --- a/src/add-ons/kernel/file_systems/bfs/Index.h +++ b/src/add-ons/kernel/file_systems/bfs/Index.h @@ -1,6 +1,5 @@ -/* Index - index access functions - * - * Copyright 2001-2004, Axel Dörfler, axeld@pinc-software.de. +/* + * Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de. * This file may be used under the terms of the MIT License. */ #ifndef INDEX_H @@ -9,49 +8,59 @@ #include "system_dependencies.h" + class Transaction; class Volume; class Inode; class Index { - public: - Index(Volume *volume); - ~Index(); +public: + Index(Volume* volume); + ~Index(); + + status_t SetTo(const char* name); + void Unset(); - status_t SetTo(const char *name); - void Unset(); + Inode* Node() const { return fNode; }; + uint32 Type(); + size_t KeySize(); + + status_t Create(Transaction& transaction, const char* name, + uint32 type); + + status_t Update(Transaction& transaction, const char* name, + int32 type, const uint8* oldKey, + uint16 oldLength, const uint8* newKey, + uint16 newLength, Inode* inode); - Inode *Node() const { return fNode; }; - uint32 Type(); - size_t KeySize(); + status_t InsertName(Transaction& transaction, + const char* name, Inode* inode); + status_t RemoveName(Transaction& transaction, + const char* name, Inode* inode); + status_t UpdateName(Transaction& transaction, + const char* oldName, const char* newName, + Inode* inode); - status_t Create(Transaction &transaction, const char *name, uint32 type); + status_t InsertSize(Transaction& transaction, Inode* inode); + status_t RemoveSize(Transaction& transaction, Inode* inode); + status_t UpdateSize(Transaction& transaction, Inode* inode); + + status_t InsertLastModified(Transaction& transaction, + Inode* inode); + status_t RemoveLastModified(Transaction& transaction, + Inode* inode); + status_t UpdateLastModified(Transaction& transaction, + Inode* inode, off_t modified = -1); - status_t Update(Transaction &transaction, const char *name, int32 type, const uint8 *oldKey, - uint16 oldLength, const uint8 *newKey, uint16 newLength, Inode *inode); +private: + Index(const Index& other); + Index& operator=(const Index& other); + // no implementation - status_t InsertName(Transaction &transaction, const char *name, Inode *inode); - status_t RemoveName(Transaction &transaction, const char *name, Inode *inode); - status_t UpdateName(Transaction &transaction, const char *oldName, const char *newName, - Inode *inode); - - status_t InsertSize(Transaction &transaction, Inode *inode); - status_t RemoveSize(Transaction &transaction, Inode *inode); - status_t UpdateSize(Transaction &transaction, Inode *inode); - - status_t InsertLastModified(Transaction &transaction, Inode *inode); - status_t RemoveLastModified(Transaction &transaction, Inode *inode); - status_t UpdateLastModified(Transaction &transaction, Inode *inode, off_t modified = -1); - - private: - Index(const Index &); - Index &operator=(const Index &); - // no implementation - - Volume *fVolume; - Inode *fNode; - const char *fName; + Volume* fVolume; + Inode* fNode; + const char* fName; }; -#endif /* INDEX_H */ +#endif // INDEX_H diff --git a/src/add-ons/kernel/file_systems/bfs/Inode.cpp b/src/add-ons/kernel/file_systems/bfs/Inode.cpp index b28d037b48..02719f0e7c 100644 --- a/src/add-ons/kernel/file_systems/bfs/Inode.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Inode.cpp @@ -16,114 +16,113 @@ namespace BFSInodeTracing { class Create : public AbstractTraceEntry { - public: - Create(Inode* inode, Inode* parent, const char* name, int32 mode, - int openMode, uint32 type) - : - fInode(inode), - fID(inode->ID()), - fParent(parent), - fParentID(parent != NULL ? parent->ID() : 0), - fMode(mode), - fOpenMode(openMode), - fType(type) - { - if (name != NULL) - strlcpy(fName, name, sizeof(fName)); - else - fName[0] = '\0'; +public: + Create(Inode* inode, Inode* parent, const char* name, int32 mode, + int openMode, uint32 type) + : + fInode(inode), + fID(inode->ID()), + fParent(parent), + fParentID(parent != NULL ? parent->ID() : 0), + fMode(mode), + fOpenMode(openMode), + fType(type) + { + if (name != NULL) + strlcpy(fName, name, sizeof(fName)); + else + fName[0] = '\0'; - Initialized(); - } + Initialized(); + } - virtual void AddDump(TraceOutput& out) - { - out.Print("bfs:Create %Ld (%p), parent %Ld (%p), \"%s\", " - "mode %lx, omode %x, type %lx", fID, fInode, fParentID, - fParent, fName, fMode, fOpenMode, fType); - } - - private: - Inode* fInode; - ino_t fID; - Inode* fParent; - ino_t fParentID; - char fName[32]; - int32 fMode; - int fOpenMode; - uint32 fType; + virtual void AddDump(TraceOutput& out) + { + out.Print("bfs:Create %Ld (%p), parent %Ld (%p), \"%s\", " + "mode %lx, omode %x, type %lx", fID, fInode, fParentID, + fParent, fName, fMode, fOpenMode, fType); + } +private: + Inode* fInode; + ino_t fID; + Inode* fParent; + ino_t fParentID; + char fName[32]; + int32 fMode; + int fOpenMode; + uint32 fType; }; class Remove : public AbstractTraceEntry { - public: - Remove(Inode* inode, const char* name) - : - fInode(inode), - fID(inode->ID()) - { - strlcpy(fName, name, sizeof(fName)); - Initialized(); - } +public: + Remove(Inode* inode, const char* name) + : + fInode(inode), + fID(inode->ID()) + { + strlcpy(fName, name, sizeof(fName)); + Initialized(); + } - virtual void AddDump(TraceOutput& out) - { - out.Print("bfs:Remove %Ld (%p), \"%s\"", fID, fInode, fName); - } + virtual void AddDump(TraceOutput& out) + { + out.Print("bfs:Remove %Ld (%p), \"%s\"", fID, fInode, fName); + } - private: - Inode* fInode; - ino_t fID; - char fName[32]; +private: + Inode* fInode; + ino_t fID; + char fName[32]; }; class Action : public AbstractTraceEntry { - public: - Action(const char* action, Inode* inode) - : - fInode(inode), - fID(inode->ID()) - { - strlcpy(fAction, action, sizeof(fAction)); - Initialized(); - } +public: + Action(const char* action, Inode* inode) + : + fInode(inode), + fID(inode->ID()) + { + strlcpy(fAction, action, sizeof(fAction)); + Initialized(); + } - virtual void AddDump(TraceOutput& out) - { - out.Print("bfs:%s %Ld (%p)\n", fAction, fID, fInode); - } + virtual void AddDump(TraceOutput& out) + { + out.Print("bfs:%s %Ld (%p)\n", fAction, fID, fInode); + } - private: - Inode* fInode; - ino_t fID; - char fAction[16]; +private: + Inode* fInode; + ino_t fID; + char fAction[16]; }; class Resize : public AbstractTraceEntry { - public: - Resize(Inode* inode, off_t oldSize, off_t newSize, bool trim) - : - fInode(inode), - fID(inode->ID()), - fOldSize(oldSize), - fNewSize(newSize), - fTrim(trim) - { - Initialized(); - } +public: + Resize(Inode* inode, off_t oldSize, off_t newSize, bool trim) + : + fInode(inode), + fID(inode->ID()), + fOldSize(oldSize), + fNewSize(newSize), + fTrim(trim) + { + Initialized(); + } - virtual void AddDump(TraceOutput& out) - { - out.Print("bfs:%s %Ld (%p), %Ld -> %Ld", fTrim ? "Trim" : "Resize", - fID, fInode, fOldSize, fNewSize); - } + virtual void AddDump(TraceOutput& out) + { + out.Print("bfs:%s %Ld (%p), %Ld -> %Ld", fTrim ? "Trim" : "Resize", + fID, fInode, fOldSize, fNewSize); + } - private: - Inode* fInode; - ino_t fID; - off_t fOldSize; - off_t fNewSize; - bool fTrim; +private: + Inode* fInode; + ino_t fID; + off_t fOldSize; + off_t fNewSize; + bool fTrim; }; } // namespace BFSInodeTracing @@ -134,25 +133,27 @@ class Resize : public AbstractTraceEntry { #endif class InodeAllocator { - public: - InodeAllocator(Transaction &transaction); - ~InodeAllocator(); +public: + InodeAllocator(Transaction& transaction); + ~InodeAllocator(); - status_t New(block_run *parentRun, mode_t mode, block_run &run, - fs_vnode_ops *vnodeOps, Inode **_inode); - status_t CreateTree(); - status_t Keep(fs_vnode_ops *vnodeOps, uint32 publishFlags); + status_t New(block_run* parentRun, mode_t mode, + block_run& run, fs_vnode_ops* vnodeOps, + Inode** _inode); + status_t CreateTree(); + status_t Keep(fs_vnode_ops* vnodeOps, uint32 publishFlags); - private: - static void _TransactionListener(int32 id, int32 event, void *_inode); +private: + static void _TransactionListener(int32 id, int32 event, + void* _inode); - Transaction *fTransaction; - block_run fRun; - Inode *fInode; + Transaction* fTransaction; + block_run fRun; + Inode* fInode; }; -InodeAllocator::InodeAllocator(Transaction &transaction) +InodeAllocator::InodeAllocator(Transaction& transaction) : fTransaction(&transaction), fInode(NULL) @@ -163,7 +164,7 @@ InodeAllocator::InodeAllocator(Transaction &transaction) InodeAllocator::~InodeAllocator() { if (fTransaction != NULL) { - Volume *volume = fTransaction->GetVolume(); + Volume* volume = fTransaction->GetVolume(); if (fInode != NULL) { fInode->Node().flags &= ~HOST_ENDIAN_TO_BFS_INT32(INODE_IN_USE); @@ -179,10 +180,10 @@ InodeAllocator::~InodeAllocator() status_t -InodeAllocator::New(block_run *parentRun, mode_t mode, block_run &run, - fs_vnode_ops *vnodeOps, Inode **_inode) +InodeAllocator::New(block_run* parentRun, mode_t mode, block_run& run, + fs_vnode_ops* vnodeOps, Inode** _inode) { - Volume *volume = fTransaction->GetVolume(); + Volume* volume = fTransaction->GetVolume(); status_t status = volume->AllocateForInode(*fTransaction, parentRun, mode, fRun); @@ -217,13 +218,13 @@ InodeAllocator::New(block_run *parentRun, mode_t mode, block_run &run, status_t InodeAllocator::CreateTree() { - Volume *volume = fTransaction->GetVolume(); + Volume* volume = fTransaction->GetVolume(); // force S_STR_INDEX to be set, if no type is set if ((fInode->Mode() & S_INDEX_TYPES) == 0) fInode->Node().mode |= HOST_ENDIAN_TO_BFS_INT32(S_STR_INDEX); - BPlusTree *tree = fInode->fTree = new BPlusTree(*fTransaction, fInode); + BPlusTree* tree = fInode->fTree = new BPlusTree(*fTransaction, fInode); if (tree == NULL || tree->InitCheck() < B_OK) return B_ERROR; @@ -238,10 +239,10 @@ InodeAllocator::CreateTree() status_t -InodeAllocator::Keep(fs_vnode_ops *vnodeOps, uint32 publishFlags) +InodeAllocator::Keep(fs_vnode_ops* vnodeOps, uint32 publishFlags) { ASSERT(fInode != NULL && fTransaction != NULL); - Volume *volume = fTransaction->GetVolume(); + Volume* volume = fTransaction->GetVolume(); status_t status = fInode->WriteBack(*fTransaction); if (status < B_OK) { @@ -268,9 +269,9 @@ InodeAllocator::Keep(fs_vnode_ops *vnodeOps, uint32 publishFlags) /*static*/ void -InodeAllocator::_TransactionListener(int32 id, int32 event, void *_inode) +InodeAllocator::_TransactionListener(int32 id, int32 event, void* _inode) { - Inode *inode = (Inode *)_inode; + Inode* inode = (Inode*)_inode; if (event == TRANSACTION_ABORTED) panic("transaction %d aborted, inode %p still around!\n", (int)id, inode); @@ -281,7 +282,7 @@ InodeAllocator::_TransactionListener(int32 id, int32 event, void *_inode) status_t -bfs_inode::InitCheck(Volume *volume) +bfs_inode::InitCheck(Volume* volume) { if (Magic1() != INODE_MAGIC1 || !(Flags() & INODE_IN_USE) @@ -312,7 +313,7 @@ bfs_inode::InitCheck(Volume *volume) // #pragma mark - Inode -Inode::Inode(Volume *volume, ino_t id) +Inode::Inode(Volume* volume, ino_t id) : fVolume(volume), fID(id), @@ -346,8 +347,8 @@ Inode::Inode(Volume *volume, ino_t id) } -Inode::Inode(Volume *volume, Transaction &transaction, ino_t id, mode_t mode, - block_run &run) +Inode::Inode(Volume* volume, Transaction& transaction, ino_t id, mode_t mode, + block_run& run) : fVolume(volume), fID(id), @@ -437,7 +438,7 @@ Inode::InitCheck(bool checkNode) status_t -Inode::WriteBack(Transaction &transaction) +Inode::WriteBack(Transaction& transaction) { NodeGetter node(fVolume, transaction, this); if (node.WritableNode() == NULL) @@ -455,7 +456,7 @@ Inode::CheckPermissions(int accessMode) const gid_t group = getegid(); // you never have write access to a read-only volume - if (accessMode & W_OK && fVolume->IsReadOnly()) + if ((accessMode & W_OK) != 0 && fVolume->IsReadOnly()) return B_READ_ONLY_DEVICE; // root users always have full access (but they can't execute files without @@ -485,7 +486,7 @@ Inode::CheckPermissions(int accessMode) const void -Inode::_AddIterator(AttributeIterator *iterator) +Inode::_AddIterator(AttributeIterator* iterator) { RecursiveLocker _(fSmallDataLock); fIterators.Add(iterator); @@ -493,7 +494,7 @@ Inode::_AddIterator(AttributeIterator *iterator) void -Inode::_RemoveIterator(AttributeIterator *iterator) +Inode::_RemoveIterator(AttributeIterator* iterator) { RecursiveLocker _(fSmallDataLock); fIterators.Remove(iterator); @@ -505,13 +506,14 @@ Inode::_RemoveIterator(AttributeIterator *iterator) You need to hold the fSmallDataLock when you call this method */ status_t -Inode::_MakeSpaceForSmallData(Transaction &transaction, bfs_inode *node, - const char *name, int32 bytes) +Inode::_MakeSpaceForSmallData(Transaction& transaction, bfs_inode* node, + const char* name, int32 bytes) { ASSERT_LOCKED_RECURSIVE(&fSmallDataLock); while (bytes > 0) { - small_data *item = node->SmallDataStart(), *max = NULL; + small_data* item = node->SmallDataStart(); + small_data* max = NULL; int32 index = 0, maxIndex = 0; for (; !item->IsLast(node); item = item->Next(), index++) { // should not remove those @@ -537,7 +539,7 @@ Inode::_MakeSpaceForSmallData(Transaction &transaction, bfs_inode *node, // Move the attribute to a real attribute file // Luckily, this doesn't cause any index updates - Inode *attribute; + Inode* attribute; status_t status = CreateAttribute(transaction, item->Name(), item->Type(), &attribute); if (status < B_OK) @@ -550,7 +552,7 @@ Inode::_MakeSpaceForSmallData(Transaction &transaction, bfs_inode *node, if (status < B_OK) { Vnode vnode(fVolume, Attributes()); - Inode *attributes; + Inode* attributes; if (vnode.Get(&attributes) < B_OK || attributes->Remove(transaction, name) < B_OK) { FATAL(("Could not remove newly created attribute!\n")); @@ -570,28 +572,28 @@ Inode::_MakeSpaceForSmallData(Transaction &transaction, bfs_inode *node, You need to hold the fSmallDataLock when you call this method */ status_t -Inode::_RemoveSmallData(bfs_inode *node, small_data *item, int32 index) +Inode::_RemoveSmallData(bfs_inode* node, small_data* item, int32 index) { ASSERT_LOCKED_RECURSIVE(&fSmallDataLock); - small_data *next = item->Next(); + small_data* next = item->Next(); if (!next->IsLast(node)) { // find the last attribute - small_data *last = next; + small_data* last = next; while (!last->IsLast(node)) last = last->Next(); - int32 size = (uint8 *)last - (uint8 *)next; + int32 size = (uint8*)last - (uint8*)next; if (size < 0 - || size > (uint8 *)node + fVolume->BlockSize() - (uint8 *)next) + || size > (uint8*)node + fVolume->BlockSize() - (uint8*)next) return B_BAD_DATA; memmove(item, next, size); // Move the "last" one to its new location and // correctly terminate the small_data section - last = (small_data *)((uint8 *)last - ((uint8 *)next - (uint8 *)item)); - memset(last, 0, (uint8 *)node + fVolume->BlockSize() - (uint8 *)last); + last = (small_data*)((uint8*)last - ((uint8*)next - (uint8*)item)); + memset(last, 0, (uint8*)node + fVolume->BlockSize() - (uint8*)last); } else memset(item, 0, item->Size()); @@ -608,18 +610,18 @@ Inode::_RemoveSmallData(bfs_inode *node, small_data *item, int32 index) //! Removes the given attribute from the small_data section. status_t -Inode::_RemoveSmallData(Transaction &transaction, NodeGetter &nodeGetter, - const char *name) +Inode::_RemoveSmallData(Transaction& transaction, NodeGetter& nodeGetter, + const char* name) { if (name == NULL) return B_BAD_VALUE; - bfs_inode *node = nodeGetter.WritableNode(); + bfs_inode* node = nodeGetter.WritableNode(); RecursiveLocker locker(fSmallDataLock); // search for the small_data item - small_data *item = node->SmallDataStart(); + small_data* item = node->SmallDataStart(); int32 index = 0; while (!item->IsLast(node) && strcmp(item->Name(), name)) { item = item->Next(); @@ -650,11 +652,11 @@ Inode::_RemoveSmallData(Transaction &transaction, NodeGetter &nodeGetter, in most cases... */ status_t -Inode::_AddSmallData(Transaction &transaction, NodeGetter &nodeGetter, - const char *name, uint32 type, const uint8 *data, size_t length, bool force) +Inode::_AddSmallData(Transaction& transaction, NodeGetter& nodeGetter, + const char* name, uint32 type, const uint8* data, size_t length, bool force) { // TODO: support new write attr semantics and write offset! - bfs_inode *node = nodeGetter.WritableNode(); + bfs_inode* node = nodeGetter.WritableNode(); if (node == NULL || name == NULL || data == NULL) return B_BAD_VALUE; @@ -669,7 +671,7 @@ Inode::_AddSmallData(Transaction &transaction, NodeGetter &nodeGetter, RecursiveLocker locker(fSmallDataLock); // Find the last item or one with the same name we have to add - small_data *item = node->SmallDataStart(); + small_data* item = node->SmallDataStart(); int32 index = 0; while (!item->IsLast(node) && strcmp(item->Name(), name)) { item = item->Next(); @@ -680,24 +682,24 @@ Inode::_AddSmallData(Transaction &transaction, NodeGetter &nodeGetter, // then just replace the data part of that one if (!item->IsLast(node)) { // find last attribute - small_data *last = item; + small_data* last = item; while (!last->IsLast(node)) last = last->Next(); // try to change the attributes value if (item->data_size > length || force - || ((uint8 *)last + length - item->DataSize()) - <= ((uint8 *)node + fVolume->InodeSize())) { + || ((uint8*)last + length - item->DataSize()) + <= ((uint8*)node + fVolume->InodeSize())) { // Make room for the new attribute if needed (and we are forced // to do so) - if (force && ((uint8 *)last + length - item->DataSize()) - > ((uint8 *)node + fVolume->InodeSize())) { + if (force && ((uint8*)last + length - item->DataSize()) + > ((uint8*)node + fVolume->InodeSize())) { // We also take the free space at the end of the small_data // section into account, and request only what's really needed uint32 needed = length - item->DataSize() - - (uint32)((uint8 *)node + fVolume->InodeSize() - - (uint8 *)last); + (uint32)((uint8*)node + fVolume->InodeSize() + - (uint8*)last); if (_MakeSpaceForSmallData(transaction, node, name, needed) < B_OK) @@ -720,19 +722,19 @@ Inode::_AddSmallData(Transaction &transaction, NodeGetter &nodeGetter, // is specified by the type and does not change that often if (length != item->DataSize()) { // move the attributes after the current one - small_data *next = item->Next(); + small_data* next = item->Next(); if (!next->IsLast(node)) { - memmove((uint8 *)item + spaceNeeded, next, - (uint8 *)last - (uint8 *)next); + memmove((uint8*)item + spaceNeeded, next, + (uint8*)last - (uint8*)next); } // Move the "last" one to its new location and // correctly terminate the small_data section - last = (small_data *)((uint8 *)last - - ((uint8 *)next - ((uint8 *)item + spaceNeeded))); - if ((uint8 *)last < (uint8 *)node + fVolume->BlockSize()) { - memset(last, 0, (uint8 *)node + fVolume->BlockSize() - - (uint8 *)last); + last = (small_data*)((uint8*)last + - ((uint8*)next - ((uint8*)item + spaceNeeded))); + if ((uint8*)last < (uint8*)node + fVolume->BlockSize()) { + memset(last, 0, (uint8*)node + fVolume->BlockSize() + - (uint8*)last); } item->data_size = HOST_ENDIAN_TO_BFS_INT16(length); @@ -750,7 +752,7 @@ Inode::_AddSmallData(Transaction &transaction, NodeGetter &nodeGetter, // try to add the new attribute! - if ((uint8 *)item + spaceNeeded > (uint8 *)node + fVolume->InodeSize()) { + if ((uint8*)item + spaceNeeded > (uint8*)node + fVolume->InodeSize()) { // there is not enough space for it! if (!force) return B_DEVICE_FULL; @@ -778,7 +780,7 @@ Inode::_AddSmallData(Transaction &transaction, NodeGetter &nodeGetter, // correctly terminate the small_data section item = item->Next(); if (!item->IsLast(node)) - memset(item, 0, (uint8 *)node + fVolume->InodeSize() - (uint8 *)item); + memset(item, 0, (uint8*)node + fVolume->InodeSize() - (uint8*)item); // update all current iterators SinglyLinkedList::Iterator iterator @@ -794,7 +796,7 @@ Inode::_AddSmallData(Transaction &transaction, NodeGetter &nodeGetter, /*! Iterates through the small_data section of an inode. To start at the beginning of this section, you let smallData point to NULL, like: - small_data *data = NULL; + small_data* data = NULL; while (inode->GetNextSmallData(&data) { ... } This function is reentrant and doesn't allocate any memory; @@ -803,14 +805,14 @@ Inode::_AddSmallData(Transaction &transaction, NodeGetter &nodeGetter, You need to hold the fSmallDataLock when you call this method */ status_t -Inode::_GetNextSmallData(bfs_inode *node, small_data **_smallData) const +Inode::_GetNextSmallData(bfs_inode* node, small_data** _smallData) const { if (node == NULL) RETURN_ERROR(B_BAD_VALUE); ASSERT_LOCKED_RECURSIVE(&fSmallDataLock); - small_data *data = *_smallData; + small_data* data = *_smallData; // begin from the start? if (data == NULL) @@ -832,13 +834,13 @@ Inode::_GetNextSmallData(bfs_inode *node, small_data **_smallData) const returns a pointer to it (or NULL if it doesn't exist). You need to hold the fSmallDataLock when you call this method */ -small_data * -Inode::FindSmallData(const bfs_inode *node, const char *name) const +small_data* +Inode::FindSmallData(const bfs_inode* node, const char* name) const { ASSERT_LOCKED_RECURSIVE(&fSmallDataLock); - small_data *smallData = NULL; - while (_GetNextSmallData(const_cast(node), &smallData) + small_data* smallData = NULL; + while (_GetNextSmallData(const_cast(node), &smallData) == B_OK) { if (!strcmp(smallData->Name(), name)) return smallData; @@ -851,16 +853,16 @@ Inode::FindSmallData(const bfs_inode *node, const char *name) const section, NULL otherwise. You need to hold the fSmallDataLock when you call this method */ -const char * -Inode::Name(const bfs_inode *node) const +const char* +Inode::Name(const bfs_inode* node) const { ASSERT_LOCKED_RECURSIVE(&fSmallDataLock); - small_data *smallData = NULL; - while (_GetNextSmallData((bfs_inode *)node, &smallData) == B_OK) { + small_data* smallData = NULL; + while (_GetNextSmallData((bfs_inode*)node, &smallData) == B_OK) { if (*smallData->Name() == FILE_NAME_NAME && smallData->NameSize() == FILE_NAME_NAME_LENGTH) - return (const char *)smallData->Data(); + return (const char*)smallData->Data(); } return NULL; } @@ -870,12 +872,12 @@ Inode::Name(const bfs_inode *node) const The buffer should be B_FILE_NAME_LENGTH bytes large. */ status_t -Inode::GetName(char *buffer, size_t size) const +Inode::GetName(char* buffer, size_t size) const { NodeGetter node(fVolume, this); RecursiveLocker locker(fSmallDataLock); - const char *name = Name(node.Node()); + const char* name = Name(node.Node()); if (name == NULL) return B_ENTRY_NOT_FOUND; @@ -891,7 +893,7 @@ Inode::GetName(char *buffer, size_t size) const (and for the same reason). */ status_t -Inode::SetName(Transaction &transaction, const char *name) +Inode::SetName(Transaction& transaction, const char* name) { if (name == NULL || *name == '\0') return B_BAD_VALUE; @@ -900,24 +902,24 @@ Inode::SetName(Transaction &transaction, const char *name) const char nameTag[2] = {FILE_NAME_NAME, 0}; return _AddSmallData(transaction, node, nameTag, FILE_NAME_TYPE, - (uint8 *)name, strlen(name), true); + (uint8*)name, strlen(name), true); } status_t -Inode::_RemoveAttribute(Transaction &transaction, const char *name, - bool hasIndex, Index *index) +Inode::_RemoveAttribute(Transaction& transaction, const char* name, + bool hasIndex, Index* index) { // remove the attribute file if it exists Vnode vnode(fVolume, Attributes()); - Inode *attributes; + Inode* attributes; status_t status = vnode.Get(&attributes); if (status < B_OK) return status; // update index if (index != NULL) { - Inode *attribute; + Inode* attribute; if ((hasIndex || fVolume->CheckForLiveQuery(name)) && GetAttribute(name, &attribute) == B_OK) { uint8 data[BPLUSTREE_MAX_KEY_LENGTH]; @@ -956,8 +958,8 @@ Inode::_RemoveAttribute(Transaction &transaction, const char *name, in the small_data section as well as real attribute files. */ status_t -Inode::ReadAttribute(const char *name, int32 type, off_t pos, uint8 *buffer, - size_t *_length) +Inode::ReadAttribute(const char* name, int32 type, off_t pos, uint8* buffer, + size_t* _length) { if (pos < 0) pos = 0; @@ -967,7 +969,7 @@ Inode::ReadAttribute(const char *name, int32 type, off_t pos, uint8 *buffer, NodeGetter node(fVolume, this); RecursiveLocker locker(fSmallDataLock); - small_data *smallData = FindSmallData(node.Node(), name); + small_data* smallData = FindSmallData(node.Node(), name); if (smallData != NULL) { size_t length = *_length; if (pos >= smallData->data_size) { @@ -984,10 +986,10 @@ Inode::ReadAttribute(const char *name, int32 type, off_t pos, uint8 *buffer, } // search in the attribute directory - Inode *attribute; + Inode* attribute; status_t status = GetAttribute(name, &attribute); if (status == B_OK) { - status = attribute->ReadAt(pos, (uint8 *)buffer, _length); + status = attribute->ReadAt(pos, (uint8*)buffer, _length); ReleaseAttribute(attribute); } @@ -1001,8 +1003,8 @@ Inode::ReadAttribute(const char *name, int32 type, off_t pos, uint8 *buffer, in the small_data section as well as real attribute files. */ status_t -Inode::WriteAttribute(Transaction &transaction, const char *name, int32 type, - off_t pos, const uint8 *buffer, size_t *_length) +Inode::WriteAttribute(Transaction& transaction, const char* name, int32 type, + off_t pos, const uint8* buffer, size_t* _length) { // needed to maintain the index uint8 oldBuffer[BPLUSTREE_MAX_KEY_LENGTH], *oldData = NULL; @@ -1018,7 +1020,7 @@ Inode::WriteAttribute(Transaction &transaction, const char *name, int32 type, Index index(fVolume); index.SetTo(name); - Inode *attribute = NULL; + Inode* attribute = NULL; status_t status = B_OK; if (GetAttribute(name, &attribute) < B_OK) { @@ -1026,7 +1028,7 @@ Inode::WriteAttribute(Transaction &transaction, const char *name, int32 type, NodeGetter node(fVolume, transaction, this); recursive_lock_lock(&fSmallDataLock); - small_data *smallData = FindSmallData(node.Node(), name); + small_data* smallData = FindSmallData(node.Node(), name); if (smallData != NULL) { oldLength = smallData->DataSize(); if (oldLength > 0) { @@ -1120,7 +1122,7 @@ Inode::WriteAttribute(Transaction &transaction, const char *name, int32 type, in the small_data section as well as real attribute files. */ status_t -Inode::RemoveAttribute(Transaction &transaction, const char *name) +Inode::RemoveAttribute(Transaction& transaction, const char* name) { Index index(fVolume); bool hasIndex = index.SetTo(name) == B_OK; @@ -1130,7 +1132,7 @@ Inode::RemoveAttribute(Transaction &transaction, const char *name) { RecursiveLocker _(fSmallDataLock); - small_data *smallData = FindSmallData(node.Node(), name); + small_data* smallData = FindSmallData(node.Node(), name); if (smallData != NULL) { uint32 length = smallData->DataSize(); if (length > BPLUSTREE_MAX_KEY_LENGTH) @@ -1150,30 +1152,30 @@ Inode::RemoveAttribute(Transaction &transaction, const char *name) status_t -Inode::GetAttribute(const char *name, Inode **_attribute) +Inode::GetAttribute(const char* name, Inode** _attribute) { // does this inode even have attributes? if (Attributes().IsZero()) return B_ENTRY_NOT_FOUND; Vnode vnode(fVolume, Attributes()); - Inode *attributes; + Inode* attributes; if (vnode.Get(&attributes) < B_OK) { FATAL(("get_vnode() failed in Inode::GetAttribute(name = \"%s\")\n", name)); return B_ERROR; } - BPlusTree *tree; + BPlusTree* tree; status_t status = attributes->GetTree(&tree); if (status == B_OK) { InodeReadLocker locker(attributes); ino_t id; - status = tree->Find((uint8 *)name, (uint16)strlen(name), &id); + status = tree->Find((uint8*)name, (uint16)strlen(name), &id); if (status == B_OK) { Vnode vnode(fVolume, id); - Inode *inode; + Inode* inode; // Check if the attribute is really an attribute if (vnode.Get(&inode) < B_OK || !inode->IsAttribute()) return B_ERROR; @@ -1188,7 +1190,7 @@ Inode::GetAttribute(const char *name, Inode **_attribute) void -Inode::ReleaseAttribute(Inode *attribute) +Inode::ReleaseAttribute(Inode* attribute) { if (attribute == NULL) return; @@ -1198,8 +1200,8 @@ Inode::ReleaseAttribute(Inode *attribute) status_t -Inode::CreateAttribute(Transaction &transaction, const char *name, uint32 type, - Inode **attribute) +Inode::CreateAttribute(Transaction& transaction, const char* name, uint32 type, + Inode** attribute) { // do we need to create the attribute directory first? if (Attributes().IsZero()) { @@ -1209,7 +1211,7 @@ Inode::CreateAttribute(Transaction &transaction, const char *name, uint32 type, RETURN_ERROR(status); } Vnode vnode(fVolume, Attributes()); - Inode *attributes; + Inode* attributes; if (vnode.Get(&attributes) < B_OK) return B_ERROR; @@ -1228,7 +1230,7 @@ Inode::CreateAttribute(Transaction &transaction, const char *name, uint32 type, and should work as good (though a bit slower). */ status_t -Inode::GetTree(BPlusTree **tree) +Inode::GetTree(BPlusTree** tree) { if (fTree) { *tree = fTree; @@ -1242,7 +1244,7 @@ Inode::GetTree(BPlusTree **tree) bool Inode::IsEmpty() { - BPlusTree *tree; + BPlusTree* tree; status_t status = GetTree(&tree); if (status < B_OK) return status; @@ -1280,9 +1282,9 @@ Inode::IsEmpty() The caller has to make sure that "pos" is inside the stream. */ status_t -Inode::FindBlockRun(off_t pos, block_run &run, off_t &offset) +Inode::FindBlockRun(off_t pos, block_run& run, off_t& offset) { - data_stream *data = &Node().data; + data_stream* data = &Node().data; // find matching block run @@ -1301,14 +1303,14 @@ Inode::FindBlockRun(off_t pos, block_run &run, off_t &offset) int32 index = start / indirectSize; int32 runsPerBlock = cached.BlockSize() / sizeof(block_run); - block_run *indirect = (block_run *)cached.SetTo( + block_run* indirect = (block_run*)cached.SetTo( fVolume->ToBlock(data->double_indirect) + index / runsPerBlock); if (indirect == NULL) RETURN_ERROR(B_ERROR); int32 current = (start % indirectSize) / directSize; - indirect = (block_run *)cached.SetTo( + indirect = (block_run*)cached.SetTo( fVolume->ToBlock(indirect[index % runsPerBlock]) + current / runsPerBlock); if (indirect == NULL) @@ -1327,7 +1329,7 @@ Inode::FindBlockRun(off_t pos, block_run &run, off_t &offset) off_t block = fVolume->ToBlock(data->indirect); for (int32 i = 0; i < data->indirect.Length(); i++) { - block_run *indirect = (block_run *)cached.SetTo(block + i); + block_run* indirect = (block_run*)cached.SetTo(block + i); if (indirect == NULL) RETURN_ERROR(B_IO_ERROR); @@ -1374,7 +1376,7 @@ Inode::FindBlockRun(off_t pos, block_run &run, off_t &offset) status_t -Inode::ReadAt(off_t pos, uint8 *buffer, size_t *_length) +Inode::ReadAt(off_t pos, uint8* buffer, size_t* _length) { size_t length = *_length; @@ -1396,8 +1398,8 @@ Inode::ReadAt(off_t pos, uint8 *buffer, size_t *_length) status_t -Inode::WriteAt(Transaction &transaction, off_t pos, const uint8 *buffer, - size_t *_length) +Inode::WriteAt(Transaction& transaction, off_t pos, const uint8* buffer, + size_t* _length) { InodeReadLocker locker(this); @@ -1494,7 +1496,7 @@ Inode::FillGapWithZeros(off_t pos, off_t newSize) The allocated block_run is saved in "run" */ status_t -Inode::_AllocateBlockArray(Transaction &transaction, block_run &run) +Inode::_AllocateBlockArray(Transaction& transaction, block_run& run) { if (!run.IsZero()) return B_BAD_VALUE; @@ -1509,7 +1511,7 @@ Inode::_AllocateBlockArray(Transaction &transaction, block_run &run) off_t block = fVolume->ToBlock(run); for (int32 i = 0; i < run.Length(); i++) { - block_run *runs = (block_run *)cached.SetToWritable(transaction, + block_run* runs = (block_run*)cached.SetToWritable(transaction, block + i, true); if (runs == NULL) return B_IO_ERROR; @@ -1519,9 +1521,9 @@ Inode::_AllocateBlockArray(Transaction &transaction, block_run &run) status_t -Inode::_GrowStream(Transaction &transaction, off_t size) +Inode::_GrowStream(Transaction& transaction, off_t size) { - data_stream *data = &Node().data; + data_stream* data = &Node().data; // is the data stream already large enough to hold the new size? // (can be the case with preallocated blocks) @@ -1625,7 +1627,7 @@ Inode::_GrowStream(Transaction &transaction, off_t size) if (data->Size() <= data->MaxIndirectRange() || !data->MaxIndirectRange()) { CachedBlock cached(fVolume); - block_run *runs = NULL; + block_run* runs = NULL; uint32 free = 0; off_t block; @@ -1638,7 +1640,7 @@ Inode::_GrowStream(Transaction &transaction, off_t size) data->max_indirect_range = HOST_ENDIAN_TO_BFS_INT64( data->MaxDirectRange()); // insert the block_run in the first block - runs = (block_run *)cached.SetTo(data->indirect); + runs = (block_run*)cached.SetTo(data->indirect); } else { uint32 numberOfRuns = fVolume->BlockSize() / sizeof(block_run); block = fVolume->ToBlock(data->indirect); @@ -1646,7 +1648,7 @@ Inode::_GrowStream(Transaction &transaction, off_t size) // search first empty entry int32 i = 0; for (; i < data->indirect.Length(); i++) { - if ((runs = (block_run *)cached.SetTo(block + i)) == NULL) + if ((runs = (block_run*)cached.SetTo(block + i)) == NULL) return B_IO_ERROR; for (free = 0; free < numberOfRuns; free++) @@ -1743,13 +1745,13 @@ Inode::_GrowStream(Transaction &transaction, off_t size) CachedBlock cached(fVolume); CachedBlock cachedDirect(fVolume); - block_run *array = NULL; + block_run* array = NULL; uint32 runLength = run.Length(); while (run.length != 0) { // get the indirect array block if (array == NULL) { - array = (block_run *)cached.SetTo(fVolume->ToBlock( + array = (block_run*)cached.SetTo(fVolume->ToBlock( data->double_indirect) + indirectIndex / runsPerBlock); if (array == NULL) return B_IO_ERROR; @@ -1766,7 +1768,7 @@ Inode::_GrowStream(Transaction &transaction, off_t size) return status; } - block_run *runs = (block_run *)cachedDirect.SetToWritable( + block_run* runs = (block_run*)cachedDirect.SetToWritable( transaction, fVolume->ToBlock(array[indirectIndex % runsPerBlock]) + index / runsPerBlock); if (runs == NULL) @@ -1811,8 +1813,8 @@ Inode::_GrowStream(Transaction &transaction, off_t size) status_t -Inode::_FreeStaticStreamArray(Transaction &transaction, int32 level, - block_run run, off_t size, off_t offset, off_t &max) +Inode::_FreeStaticStreamArray(Transaction& transaction, int32 level, + block_run run, off_t size, off_t offset, off_t& max) { int32 indirectSize = 0; if (level == 0) @@ -1837,7 +1839,7 @@ Inode::_FreeStaticStreamArray(Transaction &transaction, int32 level, offset += (off_t)index * indirectSize; for (int32 i = index / runsPerBlock; i < run.Length(); i++) { - block_run *array = (block_run *)cached.SetToWritable(transaction, + block_run* array = (block_run*)cached.SetToWritable(transaction, blockNumber + i); if (array == NULL) RETURN_ERROR(B_ERROR); @@ -1880,8 +1882,8 @@ Inode::_FreeStaticStreamArray(Transaction &transaction, int32 level, "max" is considered to be in file system byte order. */ status_t -Inode::_FreeStreamArray(Transaction &transaction, block_run *array, - uint32 arrayLength, off_t size, off_t &offset, off_t &max) +Inode::_FreeStreamArray(Transaction& transaction, block_run* array, + uint32 arrayLength, off_t size, off_t& offset, off_t& max) { PRINT(("FreeStreamArray: arrayLength %lu, size %Ld, offset %Ld, max %Ld\n", arrayLength, size, offset, max)); @@ -1932,17 +1934,17 @@ Inode::_FreeStreamArray(Transaction &transaction, block_run *array, status_t -Inode::_ShrinkStream(Transaction &transaction, off_t size) +Inode::_ShrinkStream(Transaction& transaction, off_t size) { - data_stream *data = &Node().data; + data_stream* data = &Node().data; status_t status; if (data->MaxDoubleIndirectRange() > size) { - off_t *maxDoubleIndirect = &data->max_double_indirect_range; + off_t* maxDoubleIndirect = &data->max_double_indirect_range; // gcc 4 work-around: "error: cannot bind packed field // 'data->data_stream::max_double_indirect_range' to 'off_t&'" status = _FreeStaticStreamArray(transaction, 0, data->double_indirect, - size, data->MaxIndirectRange(), *maxDoubleIndirect); + size, data->MaxIndirectRange(),* maxDoubleIndirect); if (status < B_OK) return status; @@ -1959,12 +1961,12 @@ Inode::_ShrinkStream(Transaction &transaction, off_t size) off_t offset = data->MaxDirectRange(); for (int32 i = 0; i < data->indirect.Length(); i++) { - block_run *array = (block_run *)cached.SetToWritable(transaction, + block_run* array = (block_run*)cached.SetToWritable(transaction, block + i); if (array == NULL) break; - off_t *maxIndirect = &data->max_indirect_range; + off_t* maxIndirect = &data->max_indirect_range; // gcc 4 work-around: "error: cannot bind packed field // 'data->data_stream::max_indirect_range' to 'off_t&'" if (_FreeStreamArray(transaction, array, fVolume->BlockSize() @@ -1995,7 +1997,7 @@ Inode::_ShrinkStream(Transaction &transaction, off_t size) status_t -Inode::SetFileSize(Transaction &transaction, off_t size) +Inode::SetFileSize(Transaction& transaction, off_t size) { if (size < 0) return B_BAD_VALUE; @@ -2030,7 +2032,7 @@ Inode::SetFileSize(Transaction &transaction, off_t size) status_t -Inode::Append(Transaction &transaction, off_t bytes) +Inode::Append(Transaction& transaction, off_t bytes) { return SetFileSize(transaction, Size() + bytes); } @@ -2059,7 +2061,7 @@ Inode::NeedsTrimming() status_t -Inode::TrimPreallocation(Transaction &transaction) +Inode::TrimPreallocation(Transaction& transaction) { T(Resize(this, max_c(Node().data.MaxDirectRange(), Node().data.MaxIndirectRange()), Size(), true)); @@ -2074,7 +2076,7 @@ Inode::TrimPreallocation(Transaction &transaction) //! Frees the file's data stream and removes all attributes status_t -Inode::Free(Transaction &transaction) +Inode::Free(Transaction& transaction) { FUNCTION(); @@ -2122,7 +2124,7 @@ Inode::Sync() InodeReadLocker locker(this); - data_stream *data = &Node().data; + data_stream* data = &Node().data; status_t status = B_OK; // flush direct range @@ -2147,7 +2149,7 @@ Inode::Sync() int32 count = fVolume->BlockSize() / sizeof(block_run); for (int32 j = 0; j < data->indirect.Length(); j++) { - block_run *runs = (block_run *)cached.SetTo(block + j); + block_run* runs = (block_run*)cached.SetTo(block + j); if (runs == NULL) break; @@ -2170,7 +2172,7 @@ Inode::Sync() off_t indirectBlock = fVolume->ToBlock(data->double_indirect); for (int32 l = 0; l < data->double_indirect.Length(); l++) { - block_run *indirectRuns = (block_run *)cached.SetTo(indirectBlock + l); + block_run* indirectRuns = (block_run*)cached.SetTo(indirectBlock + l); if (indirectRuns == NULL) return B_FILE_ERROR; @@ -2182,7 +2184,7 @@ Inode::Sync() block = fVolume->ToBlock(indirectRuns[k]); for (int32 j = 0; j < indirectRuns[k].Length(); j++) { - block_run *runs = (block_run *)directCached.SetTo(block + j); + block_run* runs = (block_run*)directCached.SetTo(block + j); if (runs == NULL) return B_FILE_ERROR; @@ -2208,10 +2210,10 @@ Inode::Sync() status_t -Inode::Remove(Transaction &transaction, const char *name, ino_t *_id, +Inode::Remove(Transaction& transaction, const char* name, ino_t* _id, bool isDirectory) { - BPlusTree *tree; + BPlusTree* tree; if (GetTree(&tree) != B_OK) RETURN_ERROR(B_BAD_VALUE); @@ -2219,14 +2221,14 @@ Inode::Remove(Transaction &transaction, const char *name, ino_t *_id, // does the file even exist? off_t id; - if (tree->Find((uint8 *)name, (uint16)strlen(name), &id) < B_OK) + if (tree->Find((uint8*)name, (uint16)strlen(name), &id) < B_OK) return B_ENTRY_NOT_FOUND; if (_id) *_id = id; Vnode vnode(fVolume, id); - Inode *inode; + Inode* inode; status_t status = vnode.Get(&inode); if (status < B_OK) { REPORT_ERROR(status); @@ -2261,7 +2263,7 @@ Inode::Remove(Transaction &transaction, const char *name, ino_t *_id, } #ifdef DEBUG - if (tree->Find((uint8 *)name, (uint16)strlen(name), &id) == B_OK) { + if (tree->Find((uint8*)name, (uint16)strlen(name), &id) == B_OK) { DIE(("deleted entry still there")); } #endif @@ -2306,15 +2308,15 @@ Inode::Remove(Transaction &transaction, const char *name, ino_t *_id, has been specified, the file will also be truncated. */ status_t -Inode::Create(Transaction &transaction, Inode *parent, const char *name, - int32 mode, int openMode, uint32 type, bool *_created, ino_t *_id, - Inode **_inode, fs_vnode_ops *vnodeOps, uint32 publishFlags) +Inode::Create(Transaction& transaction, Inode* parent, const char* name, + int32 mode, int openMode, uint32 type, bool* _created, ino_t* _id, + Inode** _inode, fs_vnode_ops* vnodeOps, uint32 publishFlags) { FUNCTION_START(("name = %s, mode = %ld\n", name, mode)); block_run parentRun = parent ? parent->BlockRun() : block_run::Run(0, 0, 0); - Volume *volume = transaction.GetVolume(); - BPlusTree *tree = NULL; + Volume* volume = transaction.GetVolume(); + BPlusTree* tree = NULL; if (parent && (mode & S_ATTR_DIR) == 0 && parent->IsContainer()) { // check if the file already exists in the directory @@ -2339,14 +2341,14 @@ Inode::Create(Transaction &transaction, Inode *parent, const char *name, if (tree != NULL) { // Does the file already exist? off_t offset; - if (tree->Find((uint8 *)name, (uint16)strlen(name), &offset) == B_OK) { + if (tree->Find((uint8*)name, (uint16)strlen(name), &offset) == B_OK) { // Return if the file should be a directory/link or opened in // exclusive mode if (S_ISDIR(mode) || S_ISLNK(mode) || openMode & O_EXCL) return B_FILE_EXISTS; Vnode vnode(volume, offset); - Inode *inode; + Inode* inode; status_t status = vnode.Get(&inode); if (status < B_OK) { REPORT_ERROR(status); @@ -2404,7 +2406,7 @@ Inode::Create(Transaction &transaction, Inode *parent, const char *name, // allocate space for the new inode InodeAllocator allocator(transaction); block_run run; - Inode *inode; + Inode* inode; status = allocator.New(&parentRun, mode, run, vnodeOps, &inode); if (status < B_OK) return status; @@ -2414,7 +2416,7 @@ Inode::Create(Transaction &transaction, Inode *parent, const char *name, // Initialize the parts of the bfs_inode structure that // InodeAllocator::New() hasn't touched yet - bfs_inode *node = &inode->Node(); + bfs_inode* node = &inode->Node(); if (parent == NULL) { // we set the parent to itself in this case @@ -2525,7 +2527,7 @@ Inode::Create(Transaction &transaction, Inode *parent, const char *name, // #pragma mark - AttributeIterator -AttributeIterator::AttributeIterator(Inode *inode) +AttributeIterator::AttributeIterator(Inode* inode) : fCurrentSmallData(0), fInode(inode), @@ -2560,15 +2562,15 @@ AttributeIterator::Rewind() status_t -AttributeIterator::GetNext(char *name, size_t *_length, uint32 *_type, - ino_t *_id) +AttributeIterator::GetNext(char* name, size_t* _length, uint32* _type, + ino_t* _id) { // read attributes out of the small data section if (fCurrentSmallData >= 0) { NodeGetter nodeGetter(fInode->GetVolume(), fInode); - const bfs_inode *node = nodeGetter.Node(); - const small_data *item = ((bfs_inode *)node)->SmallDataStart(); + const bfs_inode* node = nodeGetter.Node(); + const small_data* item = ((bfs_inode*)node)->SmallDataStart(); RecursiveLocker _(&fInode->SmallDataLock()); @@ -2607,18 +2609,18 @@ AttributeIterator::GetNext(char *name, size_t *_length, uint32 *_type, if (fInode->Attributes().IsZero()) return B_ENTRY_NOT_FOUND; - Volume *volume = fInode->GetVolume(); + Volume* volume = fInode->GetVolume(); // if you haven't yet access to the attributes directory, get it if (fAttributes == NULL) { if (get_vnode(volume->FSVolume(), volume->ToVnode(fInode->Attributes()), - (void **)&fAttributes) != B_OK) { + (void**)&fAttributes) != B_OK) { FATAL(("get_vnode() failed in AttributeIterator::GetNext(ino_t" " = %Ld,name = \"%s\")\n",fInode->ID(),name)); return B_ENTRY_NOT_FOUND; } - BPlusTree *tree; + BPlusTree* tree; if (fAttributes->GetTree(&tree) < B_OK || (fIterator = new TreeIterator(tree)) == NULL) { FATAL(("could not get tree in AttributeIterator::GetNext(ino_t" @@ -2635,7 +2637,7 @@ AttributeIterator::GetNext(char *name, size_t *_length, uint32 *_type, return status; Vnode vnode(volume,id); - Inode *attribute; + Inode* attribute; if ((status = vnode.Get(&attribute)) == B_OK) { *_type = attribute->Type(); *_length = length; diff --git a/src/add-ons/kernel/file_systems/bfs/Journal.cpp b/src/add-ons/kernel/file_systems/bfs/Journal.cpp index 1de343816f..831c30331d 100644 --- a/src/add-ons/kernel/file_systems/bfs/Journal.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Journal.cpp @@ -18,67 +18,69 @@ struct run_array { block_run runs[0]; void Init(int32 blockSize); - void Insert(block_run &run); + void Insert(block_run& run); int32 CountRuns() const { return BFS_ENDIAN_TO_HOST_INT32(count); } int32 MaxRuns() const { return BFS_ENDIAN_TO_HOST_INT32(max_runs) - 1; } // that -1 accounts for an off-by-one error in Be's BFS implementation - const block_run &RunAt(int32 i) const { return runs[i]; } + const block_run& RunAt(int32 i) const { return runs[i]; } static int32 MaxRuns(int32 blockSize); private: - static int _Compare(block_run &a, block_run &b); - int32 _FindInsertionIndex(block_run &run); + static int _Compare(block_run& a, block_run& b); + int32 _FindInsertionIndex(block_run& run); }; class RunArrays { - public: - RunArrays(Journal *journal); - ~RunArrays(); +public: + RunArrays(Journal* journal); + ~RunArrays(); - status_t Insert(off_t blockNumber); + status_t Insert(off_t blockNumber); - run_array *ArrayAt(int32 i) { return fArrays.Array()[i]; } - int32 CountArrays() const { return fArrays.CountItems(); } + run_array* ArrayAt(int32 i) { return fArrays.Array()[i]; } + int32 CountArrays() const { return fArrays.CountItems(); } - uint32 CountBlocks() const { return fBlockCount; } - uint32 LogEntryLength() const { return CountBlocks() + CountArrays(); } + uint32 CountBlocks() const { return fBlockCount; } + uint32 LogEntryLength() const + { return CountBlocks() + CountArrays(); } - int32 MaxArrayLength(); + int32 MaxArrayLength(); - private: - status_t _AddArray(); - bool _ContainsRun(block_run &run); - bool _AddRun(block_run &run); +private: + status_t _AddArray(); + bool _ContainsRun(block_run& run); + bool _AddRun(block_run& run); - Journal *fJournal; - uint32 fBlockCount; - Stack fArrays; - run_array *fLastArray; + Journal* fJournal; + uint32 fBlockCount; + Stack fArrays; + run_array* fLastArray; }; class LogEntry : public DoublyLinkedListLinkImpl { - public: - LogEntry(Journal *journal, uint32 logStart, uint32 length); - ~LogEntry(); +public: + LogEntry(Journal* journal, uint32 logStart, + uint32 length); + ~LogEntry(); - uint32 Start() const { return fStart; } - uint32 Length() const { return fLength; } + uint32 Start() const { return fStart; } + uint32 Length() const { return fLength; } #ifdef BFS_DEBUGGER_COMMANDS - void SetTransactionID(int32 id) { fTransactionID = id; } - int32 TransactionID() const { return fTransactionID; } + void SetTransactionID(int32 id) { fTransactionID = id; } + int32 TransactionID() const { return fTransactionID; } #endif - Journal *GetJournal() { return fJournal; } + Journal* GetJournal() { return fJournal; } - private: - Journal *fJournal; - uint32 fStart; - uint32 fLength; +private: + Journal* fJournal; + uint32 fStart; + uint32 fLength; #ifdef BFS_DEBUGGER_COMMANDS - int32 fTransactionID; + int32 fTransactionID; #endif }; @@ -87,44 +89,44 @@ class LogEntry : public DoublyLinkedListLinkImpl { namespace BFSJournalTracing { class LogEntry : public AbstractTraceEntry { - public: - LogEntry(::LogEntry* entry, off_t logPosition, bool started) - : - fEntry(entry), +public: + LogEntry(::LogEntry* entry, off_t logPosition, bool started) + : + fEntry(entry), #ifdef BFS_DEBUGGER_COMMANDS - fTransactionID(entry->TransactionID()), + fTransactionID(entry->TransactionID()), #endif - fStart(entry->Start()), - fLength(entry->Length()), - fLogPosition(logPosition), - fStarted(started) - { - Initialized(); - } + fStart(entry->Start()), + fLength(entry->Length()), + fLogPosition(logPosition), + fStarted(started) + { + Initialized(); + } - virtual void AddDump(TraceOutput& out) - { + virtual void AddDump(TraceOutput& out) + { #ifdef BFS_DEBUGGER_COMMANDS - out.Print("bfs:j:%s entry %p id %ld, start %lu, length %lu, log %s " - "%lu\n", fStarted ? "Started" : "Written", fEntry, - fTransactionID, fStart, fLength, - fStarted ? "end" : "start", fLogPosition); + out.Print("bfs:j:%s entry %p id %ld, start %lu, length %lu, log %s " + "%lu\n", fStarted ? "Started" : "Written", fEntry, + fTransactionID, fStart, fLength, + fStarted ? "end" : "start", fLogPosition); #else - out.Print("bfs:j:%s entry %p start %lu, length %lu, log %s %lu\n", - fStarted ? "Started" : "Written", fEntry, fStart, fLength, - fStarted ? "end" : "start", fLogPosition); + out.Print("bfs:j:%s entry %p start %lu, length %lu, log %s %lu\n", + fStarted ? "Started" : "Written", fEntry, fStart, fLength, + fStarted ? "end" : "start", fLogPosition); #endif - } + } - private: - ::LogEntry* fEntry; +private: + ::LogEntry* fEntry; #ifdef BFS_DEBUGGER_COMMANDS - int32 fTransactionID; + int32 fTransactionID; #endif - uint32 fStart; - uint32 fLength; - uint32 fLogPosition; - bool fStarted; + uint32 fStart; + uint32 fLength; + uint32 fLogPosition; + bool fStarted; }; } // namespace BFSJournalTracing @@ -139,7 +141,7 @@ class LogEntry : public AbstractTraceEntry { static void -add_to_iovec(iovec *vecs, int32 &index, int32 max, const void *address, +add_to_iovec(iovec* vecs, int32& index, int32 max, const void* address, size_t size) { if (index > 0 && (addr_t)vecs[index - 1].iov_base @@ -153,7 +155,7 @@ add_to_iovec(iovec *vecs, int32 &index, int32 max, const void *address, panic("no more space for iovecs!"); // we need to start a new iovec - vecs[index].iov_base = const_cast(address); + vecs[index].iov_base = const_cast(address); vecs[index].iov_len = size; index++; } @@ -162,7 +164,7 @@ add_to_iovec(iovec *vecs, int32 &index, int32 max, const void *address, // #pragma mark - LogEntry -LogEntry::LogEntry(Journal *journal, uint32 start, uint32 length) +LogEntry::LogEntry(Journal* journal, uint32 start, uint32 length) : fJournal(journal), fStart(start), @@ -196,7 +198,7 @@ run_array::Init(int32 blockSize) array is large enough to contain the entry before calling this function. */ void -run_array::Insert(block_run &run) +run_array::Insert(block_run& run) { int32 index = _FindInsertionIndex(run); if (index == -1) { @@ -226,7 +228,7 @@ run_array::MaxRuns(int32 blockSize) /*static*/ int -run_array::_Compare(block_run &a, block_run &b) +run_array::_Compare(block_run& a, block_run& b) { int cmp = a.AllocationGroup() - b.AllocationGroup(); if (cmp == 0) @@ -237,7 +239,7 @@ run_array::_Compare(block_run &a, block_run &b) int32 -run_array::_FindInsertionIndex(block_run &run) +run_array::_FindInsertionIndex(block_run& run) { int32 min = 0, max = CountRuns() - 1; int32 i = 0; @@ -272,7 +274,7 @@ run_array::_FindInsertionIndex(block_run &run) // #pragma mark - RunArrays -RunArrays::RunArrays(Journal *journal) +RunArrays::RunArrays(Journal* journal) : fJournal(journal), fBlockCount(0), @@ -284,20 +286,20 @@ RunArrays::RunArrays(Journal *journal) RunArrays::~RunArrays() { - run_array *array; + run_array* array; while (fArrays.Pop(&array)) free(array); } bool -RunArrays::_ContainsRun(block_run &run) +RunArrays::_ContainsRun(block_run& run) { for (int32 i = 0; i < CountArrays(); i++) { - run_array *array = ArrayAt(i); + run_array* array = ArrayAt(i); for (int32 j = 0; j < array->CountRuns(); j++) { - block_run &arrayRun = array->runs[j]; + block_run& arrayRun = array->runs[j]; if (run.AllocationGroup() != arrayRun.AllocationGroup()) continue; @@ -317,7 +319,7 @@ RunArrays::_ContainsRun(block_run &run) with block_runs of length 1! */ bool -RunArrays::_AddRun(block_run &run) +RunArrays::_AddRun(block_run& run) { ASSERT(run.length == 1); @@ -338,7 +340,7 @@ RunArrays::_AddArray() { int32 blockSize = fJournal->GetVolume()->BlockSize(); - run_array *array = (run_array *)malloc(blockSize); + run_array* array = (run_array*)malloc(blockSize); if (array == NULL) return B_NO_MEMORY; @@ -356,7 +358,7 @@ RunArrays::_AddArray() status_t RunArrays::Insert(off_t blockNumber) { - Volume *volume = fJournal->GetVolume(); + Volume* volume = fJournal->GetVolume(); block_run run = volume->ToBlockRun(blockNumber); if (fLastArray != NULL) { @@ -393,7 +395,7 @@ RunArrays::MaxArrayLength() // #pragma mark - Journal -Journal::Journal(Volume *volume) +Journal::Journal(Volume* volume) : fVolume(volume), fOwner(NULL), @@ -429,7 +431,7 @@ Journal::InitCheck() within a the volume. */ status_t -Journal::_CheckRunArray(const run_array *array) +Journal::_CheckRunArray(const run_array* array) { int32 maxRuns = run_array::MaxRuns(fVolume->BlockSize()) - 1; // the -1 works around an off-by-one bug in Be's BFS implementation, @@ -458,7 +460,7 @@ Journal::_CheckRunArray(const run_array *array) one if replaying succeeded. */ status_t -Journal::_ReplayRunArray(int32 *_start) +Journal::_ReplayRunArray(int32* _start) { PRINT(("ReplayRunArray(start = %ld)\n", *_start)); @@ -467,7 +469,7 @@ Journal::_ReplayRunArray(int32 *_start) CachedBlock cachedArray(fVolume); - const run_array *array = (const run_array *)cachedArray.SetTo(logOffset + const run_array* array = (const run_array*)cachedArray.SetTo(logOffset + firstBlockNumber); if (array == NULL) return B_IO_ERROR; @@ -484,11 +486,11 @@ Journal::_ReplayRunArray(int32 *_start) int32 blockSize = fVolume->BlockSize(); for (int32 index = 0; index < array->CountRuns(); index++) { - const block_run &run = array->RunAt(index); + const block_run& run = array->RunAt(index); off_t offset = fVolume->ToOffset(run); for (int32 i = 0; i < run.Length(); i++) { - const uint8 *data = cached.SetTo(logOffset + blockNumber); + const uint8* data = cached.SetTo(logOffset + blockNumber); if (data == NULL) RETURN_ERROR(B_IO_ERROR); @@ -514,13 +516,13 @@ Journal::_ReplayRunArray(int32 *_start) int32 count = 1; for (int32 index = 0; index < array->CountRuns(); index++) { - const block_run &run = array->RunAt(index); + const block_run& run = array->RunAt(index); INFORM(("replay block run %u:%u:%u in log at %Ld!\n", (int)run.AllocationGroup(), run.Start(), run.Length(), blockNumber)); off_t offset = fVolume->ToOffset(run); for (int32 i = 0; i < run.Length(); i++) { - const uint8 *data = cached.SetTo(logOffset + blockNumber); + const uint8* data = cached.SetTo(logOffset + blockNumber); if (data == NULL) RETURN_ERROR(B_IO_ERROR); @@ -597,15 +599,15 @@ Journal::ReplayLog() completed in the order they were written. */ /*static*/ void -Journal::_TransactionWritten(int32 transactionID, int32 event, void *_logEntry) +Journal::_TransactionWritten(int32 transactionID, int32 event, void* _logEntry) { - LogEntry *logEntry = (LogEntry *)_logEntry; + LogEntry* logEntry = (LogEntry*)_logEntry; PRINT(("Log entry %p has been finished, transaction ID = %ld\n", logEntry, transactionID)); - Journal *journal = logEntry->GetJournal(); - disk_super_block &superBlock = journal->fVolume->SuperBlock(); + Journal* journal = logEntry->GetJournal(); + disk_super_block& superBlock = journal->fVolume->SuperBlock(); bool update = false; // Set log_start pointer if possible... @@ -613,7 +615,7 @@ Journal::_TransactionWritten(int32 transactionID, int32 event, void *_logEntry) mutex_lock(&journal->fEntriesLock); if (logEntry == journal->fEntries.First()) { - LogEntry *next = journal->fEntries.GetNext(logEntry); + LogEntry* next = journal->fEntries.GetNext(logEntry); if (next != NULL) { superBlock.log_start = HOST_ENDIAN_TO_BFS_INT64(next->Start() % journal->fLogSize); @@ -652,11 +654,11 @@ Journal::_TransactionWritten(int32 transactionID, int32 event, void *_logEntry) /*! Listens to TRANSACTION_IDLE events, and flushes the log when that happens */ /*static*/ void -Journal::_TransactionIdle(int32 transactionID, int32 event, void *_journal) +Journal::_TransactionIdle(int32 transactionID, int32 event, void* _journal) { // The current transaction seems to be idle - flush it - Journal *journal = (Journal *)_journal; + Journal* journal = (Journal*)_journal; journal->_FlushLog(false, false); } @@ -745,23 +747,23 @@ Journal::_WriteTransactionToLog() int32 maxVecs = runArrays.MaxArrayLength() + 1; // one extra for the index block - iovec *vecs = (iovec *)malloc(sizeof(iovec) * maxVecs); + iovec* vecs = (iovec*)malloc(sizeof(iovec) * maxVecs); if (vecs == NULL) { // TODO: write back log entries directly? return B_NO_MEMORY; } for (int32 k = 0; k < runArrays.CountArrays(); k++) { - run_array *array = runArrays.ArrayAt(k); + run_array* array = runArrays.ArrayAt(k); int32 index = 0, count = 1; int32 wrap = fLogSize - logStart; - add_to_iovec(vecs, index, maxVecs, (void *)array, fVolume->BlockSize()); + add_to_iovec(vecs, index, maxVecs, (void*)array, fVolume->BlockSize()); // add block runs for (int32 i = 0; i < array->CountRuns(); i++) { - const block_run &run = array->RunAt(i); + const block_run& run = array->RunAt(i); off_t blockNumber = fVolume->ToBlock(run); for (int32 j = 0; j < run.Length(); j++) { @@ -780,7 +782,7 @@ Journal::_WriteTransactionToLog() } // make blocks available in the cache - const void *data = block_cache_get(fVolume->BlockCache(), + const void* data = block_cache_get(fVolume->BlockCache(), blockNumber + j); if (data == NULL) { free(vecs); @@ -802,7 +804,7 @@ Journal::_WriteTransactionToLog() // release blocks again for (int32 i = 0; i < array->CountRuns(); i++) { - const block_run &run = array->RunAt(i); + const block_run& run = array->RunAt(i); off_t blockNumber = fVolume->ToBlock(run); for (int32 j = 0; j < run.Length(); j++) { @@ -815,7 +817,7 @@ Journal::_WriteTransactionToLog() free(vecs); - LogEntry *logEntry = new LogEntry(this, fVolume->LogEnd(), + LogEntry* logEntry = new LogEntry(this, fVolume->LogEnd(), runArrays.LogEntryLength()); if (logEntry == NULL) { FATAL(("no memory to allocate log entries!")); @@ -907,7 +909,7 @@ Journal::FlushLogAndBlocks() status_t -Journal::Lock(Transaction *owner) +Journal::Lock(Transaction* owner) { status_t status = recursive_lock_lock(&fLock); if (status != B_OK) @@ -947,7 +949,7 @@ Journal::Lock(Transaction *owner) void -Journal::Unlock(Transaction *owner, bool success) +Journal::Unlock(Transaction* owner, bool success) { if (recursive_lock_get_recursion(&fLock) == 1) { // we only end the transaction if we would really unlock it @@ -1022,7 +1024,7 @@ Journal::Dump() LogEntryList::Iterator iterator = fEntries.GetIterator(); while (iterator.HasNext()) { - LogEntry *entry = iterator.Next(); + LogEntry* entry = iterator.Next(); kprintf(" %p %6ld %6lu %6lu\n", entry, entry->TransactionID(), entry->Start(), entry->Length()); @@ -1031,15 +1033,15 @@ Journal::Dump() int -dump_journal(int argc, char **argv) +dump_journal(int argc, char** argv) { if (argc != 2 || !strcmp(argv[1], "--help")) { kprintf("usage: %s \n", argv[0]); return 0; } - Volume *volume = (Volume *)parse_expression(argv[1]); - Journal *journal = volume->GetJournal(0); + Volume* volume = (Volume*)parse_expression(argv[1]); + Journal* journal = volume->GetJournal(0); journal->Dump(); return 0; @@ -1052,7 +1054,7 @@ dump_journal(int argc, char **argv) status_t -Transaction::Start(Volume *volume, off_t refBlock) +Transaction::Start(Volume* volume, off_t refBlock) { // has it already been started? if (fJournal != NULL) diff --git a/src/add-ons/kernel/file_systems/bfs/Journal.h b/src/add-ons/kernel/file_systems/bfs/Journal.h index 6db3994438..b5e0743405 100644 --- a/src/add-ons/kernel/file_systems/bfs/Journal.h +++ b/src/add-ons/kernel/file_systems/bfs/Journal.h @@ -8,10 +8,6 @@ #include "system_dependencies.h" -#ifndef _IMPEXP_KERNEL -# define _IMPEXP_KERNEL -#endif - #include "Volume.h" #include "Utility.h" @@ -23,62 +19,56 @@ typedef DoublyLinkedList LogEntryList; typedef SinglyLinkedList InodeList; -// Locking policy in BFS: if you need both, the volume lock and the -// journal lock, you must lock the volume first - or else you will -// end up in a deadlock. -// That is, if you start a transaction, and will need to lock the -// volume while the transaction is in progress (for the unsafe -// get_vnode() call, for example), you must lock the volume before -// starting the transaction. - class Journal { - public: - Journal(Volume *); - ~Journal(); +public: + Journal(Volume* volume); + ~Journal(); - status_t InitCheck(); + status_t InitCheck(); - status_t Lock(Transaction *owner); - void Unlock(Transaction *owner, bool success); + status_t Lock(Transaction* owner); + void Unlock(Transaction* owner, bool success); - status_t ReplayLog(); + status_t ReplayLog(); - Transaction *CurrentTransaction() const { return fOwner; } + Transaction* CurrentTransaction() const { return fOwner; } - status_t FlushLogAndBlocks(); - Volume *GetVolume() const { return fVolume; } - int32 TransactionID() const { return fTransactionID; } + status_t FlushLogAndBlocks(); + Volume* GetVolume() const { return fVolume; } + int32 TransactionID() const { return fTransactionID; } - inline uint32 FreeLogBlocks() const; + inline uint32 FreeLogBlocks() const; #ifdef BFS_DEBUGGER_COMMANDS - void Dump(); + void Dump(); #endif - private: - bool _HasSubTransaction() { return fHasSubtransaction; } - status_t _FlushLog(bool canWait, bool flushBlocks); - uint32 _TransactionSize() const; - status_t _WriteTransactionToLog(); - status_t _CheckRunArray(const run_array *array); - status_t _ReplayRunArray(int32 *start); - status_t _TransactionDone(bool success); +private: + bool _HasSubTransaction() { return fHasSubtransaction; } + status_t _FlushLog(bool canWait, bool flushBlocks); + uint32 _TransactionSize() const; + status_t _WriteTransactionToLog(); + status_t _CheckRunArray(const run_array* array); + status_t _ReplayRunArray(int32* start); + status_t _TransactionDone(bool success); - static void _TransactionWritten(int32 transactionID, int32 event, - void *_logEntry); - static void _TransactionIdle(int32 transactionID, int32 event, - void *_journal); + static void _TransactionWritten(int32 transactionID, + int32 event, void* _logEntry); + static void _TransactionIdle(int32 transactionID, int32 event, + void* _journal); - Volume *fVolume; - recursive_lock fLock; - Transaction *fOwner; - uint32 fLogSize, fMaxTransactionSize, fUsed; - int32 fUnwrittenTransactions; - mutex fEntriesLock; - LogEntryList fEntries; - bigtime_t fTimestamp; - int32 fTransactionID; - bool fHasSubtransaction; + Volume* fVolume; + recursive_lock fLock; + Transaction* fOwner; + uint32 fLogSize; + uint32 fMaxTransactionSize; + uint32 fUsed; + int32 fUnwrittenTransactions; + mutex fEntriesLock; + LogEntryList fEntries; + bigtime_t fTimestamp; + int32 fTransactionID; + bool fHasSubtransaction; }; @@ -96,99 +86,99 @@ Journal::FreeLogBlocks() const // It doesn't yet use logging. class Transaction { - public: - Transaction(Volume *volume, off_t refBlock) - : - fJournal(NULL) - { - Start(volume, refBlock); +public: + Transaction(Volume* volume, off_t refBlock) + : + fJournal(NULL) + { + Start(volume, refBlock); + } + + Transaction(Volume* volume, block_run refRun) + : + fJournal(NULL) + { + Start(volume, volume->ToBlock(refRun)); + } + + Transaction() + : + fJournal(NULL) + { + } + + ~Transaction() + { + if (fJournal != NULL) { + fJournal->Unlock(this, false); + _UnlockInodes(); + } + } + + status_t Start(Volume* volume, off_t refBlock); + bool IsStarted() const { return fJournal != NULL; } + + void Done() + { + if (fJournal != NULL) { + fJournal->Unlock(this, true); + _UnlockInodes(); + } + fJournal = NULL; + } + + bool HasParent() + { + if (fJournal != NULL) + return fJournal->CurrentTransaction() == this; + + return false; + } + + status_t WriteBlocks(off_t blockNumber, const uint8* buffer, + size_t numBlocks = 1) + { + if (fJournal == NULL) + return B_NO_INIT; + + void* cache = GetVolume()->BlockCache(); + size_t blockSize = GetVolume()->BlockSize(); + + for (size_t i = 0; i < numBlocks; i++) { + void* block = block_cache_get_empty(cache, blockNumber + i, + ID()); + if (block == NULL) + return B_ERROR; + + memcpy(block, buffer, blockSize); + buffer += blockSize; + + block_cache_put(cache, blockNumber + i); } - Transaction(Volume *volume, block_run refRun) - : - fJournal(NULL) - { - Start(volume, volume->ToBlock(refRun)); - } + return B_OK; + } - Transaction() - : - fJournal(NULL) - { - } + Volume *GetVolume() + { return fJournal != NULL ? fJournal->GetVolume() : NULL; } + int32 ID() const + { return fJournal->TransactionID(); } - ~Transaction() - { - if (fJournal != NULL) { - fJournal->Unlock(this, false); - _UnlockInodes(); - } - } + void AddInode(Inode* inode); - status_t Start(Volume *volume, off_t refBlock); - bool IsStarted() const { return fJournal != NULL; } +private: + Transaction(const Transaction& other); + Transaction& operator=(const Transaction& other); + // no implementation - void Done() - { - if (fJournal != NULL) { - fJournal->Unlock(this, true); - _UnlockInodes(); - } - fJournal = NULL; - } + void _UnlockInodes(); - bool HasParent() - { - if (fJournal != NULL) - return fJournal->CurrentTransaction() == this; - - return false; - } - - status_t WriteBlocks(off_t blockNumber, const uint8 *buffer, - size_t numBlocks = 1) - { - if (fJournal == NULL) - return B_NO_INIT; - - void *cache = GetVolume()->BlockCache(); - size_t blockSize = GetVolume()->BlockSize(); - - for (size_t i = 0; i < numBlocks; i++) { - void *block = block_cache_get_empty(cache, blockNumber + i, - ID()); - if (block == NULL) - return B_ERROR; - - memcpy(block, buffer, blockSize); - buffer += blockSize; - - block_cache_put(cache, blockNumber + i); - } - - return B_OK; - } - - Volume *GetVolume() - { return fJournal != NULL ? fJournal->GetVolume() : NULL; } - int32 ID() const - { return fJournal->TransactionID(); } - - void AddInode(Inode* inode); - - private: - Transaction(const Transaction &); - Transaction &operator=(const Transaction &); - // no implementation - - void _UnlockInodes(); - - Journal* fJournal; - InodeList fLockedInodes; + Journal* fJournal; + InodeList fLockedInodes; }; #ifdef BFS_DEBUGGER_COMMANDS -int dump_journal(int argc, char **argv); +int dump_journal(int argc, char** argv); #endif -#endif /* JOURNAL_H */ +#endif // JOURNAL_H diff --git a/src/add-ons/kernel/file_systems/bfs/Utility.cpp b/src/add-ons/kernel/file_systems/bfs/Utility.cpp index 50e33ba29c..95f57dab58 100644 --- a/src/add-ons/kernel/file_systems/bfs/Utility.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Utility.cpp @@ -11,7 +11,7 @@ bool -sorted_array::_FindInternal(off_t value, int32 &index) const +sorted_array::_FindInternal(off_t value, int32& index) const { int32 min = 0, max = count - 1; off_t cmp; @@ -61,7 +61,8 @@ sorted_array::Remove(off_t value) return false; count--; - memmove(&values[index], &values[index + 1], (count - index) * sizeof(off_t)); + memmove(&values[index], &values[index + 1], + (count - index) * sizeof(off_t)); return true; } diff --git a/src/add-ons/kernel/file_systems/bfs/Utility.h b/src/add-ons/kernel/file_systems/bfs/Utility.h index 6e9582a250..27d95147bd 100644 --- a/src/add-ons/kernel/file_systems/bfs/Utility.h +++ b/src/add-ons/kernel/file_systems/bfs/Utility.h @@ -13,16 +13,15 @@ // TODO: this is not endian safe!!! struct sorted_array { - public: - off_t count; - off_t values[0]; + off_t count; + off_t values[0]; - inline int32 Find(off_t value) const; - void Insert(off_t value); - bool Remove(off_t value); + inline int32 Find(off_t value) const; + void Insert(off_t value); + bool Remove(off_t value); - private: - bool _FindInternal(off_t value, int32 &index) const; +private: + bool _FindInternal(off_t value, int32& index) const; }; diff --git a/src/add-ons/kernel/file_systems/bfs/Volume.h b/src/add-ons/kernel/file_systems/bfs/Volume.h index 020bab86cd..2ee013e006 100644 --- a/src/add-ons/kernel/file_systems/bfs/Volume.h +++ b/src/add-ons/kernel/file_systems/bfs/Volume.h @@ -24,116 +24,132 @@ enum volume_initialize_flags { }; class Volume { - public: - Volume(fs_volume *volume); - ~Volume(); +public: + Volume(fs_volume* volume); + ~Volume(); - status_t Mount(const char *device, uint32 flags); - status_t Unmount(); - status_t Initialize(int fd, const char *name, + status_t Mount(const char* device, uint32 flags); + status_t Unmount(); + status_t Initialize(int fd, const char* name, uint32 blockSize, uint32 flags); - bool IsInitializing() const { return fVolume == NULL; } + bool IsInitializing() const { return fVolume == NULL; } - bool IsValidSuperBlock(); - bool IsReadOnly() const; - void Panic(); - mutex &Lock(); + bool IsValidSuperBlock(); + bool IsReadOnly() const; + void Panic(); + mutex& Lock(); - block_run Root() const { return fSuperBlock.root_dir; } - Inode *RootNode() const { return fRootNode; } - block_run Indices() const { return fSuperBlock.indices; } - Inode *IndicesNode() const { return fIndicesNode; } - block_run Log() const { return fSuperBlock.log_blocks; } - vint32 &LogStart() { return fLogStart; } - vint32 &LogEnd() { return fLogEnd; } - int Device() const { return fDevice; } + block_run Root() const { return fSuperBlock.root_dir; } + Inode* RootNode() const { return fRootNode; } + block_run Indices() const { return fSuperBlock.indices; } + Inode* IndicesNode() const { return fIndicesNode; } + block_run Log() const { return fSuperBlock.log_blocks; } + vint32& LogStart() { return fLogStart; } + vint32& LogEnd() { return fLogEnd; } + int Device() const { return fDevice; } - dev_t ID() const { return fVolume ? fVolume->id : -1; } - fs_volume *FSVolume() const { return fVolume; } - const char *Name() const { return fSuperBlock.name; } + dev_t ID() const { return fVolume ? fVolume->id : -1; } + fs_volume* FSVolume() const { return fVolume; } + const char* Name() const { return fSuperBlock.name; } - off_t NumBlocks() const { return fSuperBlock.NumBlocks(); } - off_t UsedBlocks() const { return fSuperBlock.UsedBlocks(); } - off_t FreeBlocks() const { return NumBlocks() - UsedBlocks(); } + off_t NumBlocks() const + { return fSuperBlock.NumBlocks(); } + off_t UsedBlocks() const + { return fSuperBlock.UsedBlocks(); } + off_t FreeBlocks() const + { return NumBlocks() - UsedBlocks(); } - uint32 BlockSize() const { return fBlockSize; } - uint32 BlockShift() const { return fBlockShift; } - uint32 InodeSize() const { return fSuperBlock.InodeSize(); } - uint32 AllocationGroups() const { return fSuperBlock.AllocationGroups(); } - uint32 AllocationGroupShift() const { return fAllocationGroupShift; } - disk_super_block &SuperBlock() { return fSuperBlock; } + uint32 BlockSize() const { return fBlockSize; } + uint32 BlockShift() const { return fBlockShift; } + uint32 InodeSize() const + { return fSuperBlock.InodeSize(); } + uint32 AllocationGroups() const + { return fSuperBlock.AllocationGroups(); } + uint32 AllocationGroupShift() const + { return fAllocationGroupShift; } + disk_super_block& SuperBlock() { return fSuperBlock; } - off_t ToOffset(block_run run) const { return ToBlock(run) << BlockShift(); } - off_t ToBlock(block_run run) const { return ((((off_t)run.AllocationGroup()) << AllocationGroupShift()) | (off_t)run.Start()); } - block_run ToBlockRun(off_t block) const; - status_t ValidateBlockRun(block_run run); + off_t ToOffset(block_run run) const + { return ToBlock(run) << BlockShift(); } + off_t ToBlock(block_run run) const + { return ((((off_t)run.AllocationGroup()) + << AllocationGroupShift()) + | (off_t)run.Start()); } + block_run ToBlockRun(off_t block) const; + status_t ValidateBlockRun(block_run run); - off_t ToVnode(block_run run) const { return ToBlock(run); } - off_t ToVnode(off_t block) const { return block; } - off_t VnodeToBlock(ino_t id) const { return (off_t)id; } + off_t ToVnode(block_run run) const + { return ToBlock(run); } + off_t ToVnode(off_t block) const { return block; } + off_t VnodeToBlock(ino_t id) const { return (off_t)id; } - status_t CreateIndicesRoot(Transaction &transaction); + status_t CreateIndicesRoot(Transaction& transaction); - // block bitmap - BlockAllocator &Allocator(); - status_t AllocateForInode(Transaction &transaction, const Inode *parent, - mode_t type, block_run &run); - status_t AllocateForInode(Transaction &transaction, const block_run *parent, - mode_t type, block_run &run); - status_t Allocate(Transaction &transaction, Inode *inode, - off_t numBlocks, block_run &run, uint16 minimum = 1); - status_t Free(Transaction &transaction, block_run run); + // block bitmap + BlockAllocator& Allocator(); + status_t AllocateForInode(Transaction& transaction, + const Inode* parent, mode_t type, + block_run& run); + status_t AllocateForInode(Transaction& transaction, + const block_run* parent, mode_t type, + block_run& run); + status_t Allocate(Transaction& transaction, Inode* inode, + off_t numBlocks, block_run& run, + uint16 minimum = 1); + status_t Free(Transaction& transaction, block_run run); - // cache access - status_t WriteSuperBlock(); - status_t FlushDevice(); + // cache access + status_t WriteSuperBlock(); + status_t FlushDevice(); - // queries - void UpdateLiveQueries(Inode *inode, const char *attribute, int32 type, - const uint8 *oldKey, size_t oldLength, - const uint8 *newKey, size_t newLength); - bool CheckForLiveQuery(const char *attribute); - void AddQuery(Query *query); - void RemoveQuery(Query *query); + // queries + void UpdateLiveQueries(Inode* inode, + const char* attribute, int32 type, + const uint8* oldKey, size_t oldLength, + const uint8* newKey, size_t newLength); + bool CheckForLiveQuery(const char* attribute); + void AddQuery(Query* query); + void RemoveQuery(Query* query); - status_t Sync(); - Journal *GetJournal(off_t refBlock) const; + status_t Sync(); + Journal* GetJournal(off_t refBlock) const; - void *BlockCache() { return fBlockCache; } + void* BlockCache() { return fBlockCache; } - uint32 GetUniqueID(); + uint32 GetUniqueID(); - static status_t CheckSuperBlock(const uint8* data, + static status_t CheckSuperBlock(const uint8* data, uint32* _offset = NULL); - static status_t Identify(int fd, disk_super_block *superBlock); + static status_t Identify(int fd, disk_super_block* superBlock); protected: - fs_volume *fVolume; - int fDevice; - disk_super_block fSuperBlock; + fs_volume* fVolume; + int fDevice; + disk_super_block fSuperBlock; - uint32 fBlockSize; - uint32 fBlockShift; - uint32 fAllocationGroupShift; + uint32 fBlockSize; + uint32 fBlockShift; + uint32 fAllocationGroupShift; - BlockAllocator fBlockAllocator; - mutex fLock; - Journal *fJournal; - vint32 fLogStart, fLogEnd; + BlockAllocator fBlockAllocator; + mutex fLock; + Journal* fJournal; + vint32 fLogStart; + vint32 fLogEnd; - Inode *fRootNode; - Inode *fIndicesNode; + Inode* fRootNode; + Inode* fIndicesNode; - vint32 fDirtyCachedBlocks; + vint32 fDirtyCachedBlocks; - mutex fQueryLock; - SinglyLinkedList fQueries; + mutex fQueryLock; + SinglyLinkedList fQueries; - int32 fUniqueID; - uint32 fFlags; + int32 fUniqueID; + uint32 fFlags; - void *fBlockCache; + void* fBlockCache; }; @@ -146,14 +162,14 @@ Volume::IsReadOnly() const } -inline mutex & +inline mutex& Volume::Lock() { return fLock; } -inline BlockAllocator & +inline BlockAllocator& Volume::Allocator() { return fBlockAllocator; @@ -161,21 +177,24 @@ Volume::Allocator() inline status_t -Volume::AllocateForInode(Transaction &transaction, const block_run *parent, mode_t type, block_run &run) +Volume::AllocateForInode(Transaction& transaction, const block_run* parent, + mode_t type, block_run& run) { return fBlockAllocator.AllocateForInode(transaction, parent, type, run); } inline status_t -Volume::Allocate(Transaction &transaction, Inode *inode, off_t numBlocks, block_run &run, uint16 minimum) +Volume::Allocate(Transaction& transaction, Inode* inode, off_t numBlocks, + block_run& run, uint16 minimum) { - return fBlockAllocator.Allocate(transaction, inode, numBlocks, run, minimum); + return fBlockAllocator.Allocate(transaction, inode, numBlocks, run, + minimum); } inline status_t -Volume::Free(Transaction &transaction, block_run run) +Volume::Free(Transaction& transaction, block_run run) { return fBlockAllocator.Free(transaction, run); } @@ -188,7 +207,7 @@ Volume::FlushDevice() } -inline Journal * +inline Journal* Volume::GetJournal(off_t /*refBlock*/) const { return fJournal; @@ -201,4 +220,4 @@ Volume::GetUniqueID() return atomic_add(&fUniqueID, 1); } -#endif /* VOLUME_H */ +#endif // VOLUME_H diff --git a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp index fb222aa83c..623a4f345d 100644 --- a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp @@ -24,13 +24,13 @@ struct identify_cookie { disk_super_block super_block; }; -extern void fill_stat_buffer(Inode *inode, struct stat &stat); +extern void fill_stat_buffer(Inode* inode, struct stat& stat); void -fill_stat_buffer(Inode *inode, struct stat &stat) +fill_stat_buffer(Inode* inode, struct stat& stat) { - const bfs_inode &node = inode->Node(); + const bfs_inode& node = inode->Node(); stat.st_dev = inode->GetVolume()->ID(); stat.st_ino = inode->ID(); @@ -56,20 +56,20 @@ fill_stat_buffer(Inode *inode, struct stat &stat) //! bfs_io() callback hook static status_t -iterative_io_get_vecs_hook(void* cookie, io_request *request, off_t offset, - size_t size, struct file_io_vec *vecs, size_t *_count) +iterative_io_get_vecs_hook(void* cookie, io_request* request, off_t offset, + size_t size, struct file_io_vec* vecs, size_t* _count) { - Inode *inode = (Inode*)cookie; + Inode* inode = (Inode*)cookie; return file_map_translate(inode->Map(), offset, size, vecs, _count); } //! bfs_io() callback hook static status_t -iterative_io_finished_hook(void *cookie, io_request *request, status_t status, +iterative_io_finished_hook(void* cookie, io_request* request, status_t status, bool partialTransfer, size_t bytesTransferred) { - Inode *inode = (Inode*)cookie; + Inode* inode = (Inode*)cookie; rw_lock_read_unlock(&inode->Lock()); return B_OK; @@ -80,14 +80,14 @@ iterative_io_finished_hook(void *cookie, io_request *request, status_t status, static float -bfs_identify_partition(int fd, partition_data *partition, void **_cookie) +bfs_identify_partition(int fd, partition_data* partition, void** _cookie) { disk_super_block superBlock; status_t status = Volume::Identify(fd, &superBlock); if (status != B_OK) return status; - identify_cookie *cookie = new(std::nothrow) identify_cookie; + identify_cookie* cookie = new(std::nothrow) identify_cookie; if (cookie == NULL) return B_NO_MEMORY; @@ -99,9 +99,9 @@ bfs_identify_partition(int fd, partition_data *partition, void **_cookie) static status_t -bfs_scan_partition(int fd, partition_data *partition, void *_cookie) +bfs_scan_partition(int fd, partition_data* partition, void* _cookie) { - identify_cookie *cookie = (identify_cookie *)_cookie; + identify_cookie* cookie = (identify_cookie*)_cookie; partition->status = B_PARTITION_VALID; partition->flags |= B_PARTITION_FILE_SYSTEM; @@ -117,9 +117,9 @@ bfs_scan_partition(int fd, partition_data *partition, void *_cookie) static void -bfs_free_identify_partition_cookie(partition_data *partition, void *_cookie) +bfs_free_identify_partition_cookie(partition_data* partition, void* _cookie) { - identify_cookie *cookie = (identify_cookie *)_cookie; + identify_cookie* cookie = (identify_cookie*)_cookie; delete cookie; } @@ -128,12 +128,12 @@ bfs_free_identify_partition_cookie(partition_data *partition, void *_cookie) static status_t -bfs_mount(fs_volume *_volume, const char *device, uint32 flags, - const char *args, ino_t *_rootID) +bfs_mount(fs_volume* _volume, const char* device, uint32 flags, + const char* args, ino_t* _rootID) { FUNCTION(); - Volume *volume = new(std::nothrow) Volume(_volume); + Volume* volume = new(std::nothrow) Volume(_volume); if (volume == NULL) return B_NO_MEMORY; @@ -154,10 +154,10 @@ bfs_mount(fs_volume *_volume, const char *device, uint32 flags, static status_t -bfs_unmount(fs_volume *_volume) +bfs_unmount(fs_volume* _volume) { FUNCTION(); - Volume* volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; status_t status = volume->Unmount(); delete volume; @@ -167,11 +167,11 @@ bfs_unmount(fs_volume *_volume) static status_t -bfs_read_fs_stat(fs_volume *_volume, struct fs_info *info) +bfs_read_fs_stat(fs_volume* _volume, struct fs_info* info) { FUNCTION(); - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; MutexLocker locker(volume->Lock()); // File system flags. @@ -196,11 +196,11 @@ bfs_read_fs_stat(fs_volume *_volume, struct fs_info *info) static status_t -bfs_write_fs_stat(fs_volume *_volume, const struct fs_info *info, uint32 mask) +bfs_write_fs_stat(fs_volume* _volume, const struct fs_info* info, uint32 mask) { FUNCTION_START(("mask = %ld\n", mask)); - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; if (volume->IsReadOnly()) return B_READ_ONLY_DEVICE; @@ -209,7 +209,7 @@ bfs_write_fs_stat(fs_volume *_volume, const struct fs_info *info, uint32 mask) status_t status = B_BAD_VALUE; if (mask & FS_WRITE_FSINFO_NAME) { - disk_super_block &superBlock = volume->SuperBlock(); + disk_super_block& superBlock = volume->SuperBlock(); strncpy(superBlock.name, info->volume_name, sizeof(superBlock.name) - 1); @@ -222,11 +222,11 @@ bfs_write_fs_stat(fs_volume *_volume, const struct fs_info *info, uint32 mask) static status_t -bfs_sync(fs_volume *_volume) +bfs_sync(fs_volume* _volume) { FUNCTION(); - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; return volume->Sync(); } @@ -237,11 +237,11 @@ bfs_sync(fs_volume *_volume) /*! Reads in the node from disk and creates an inode object from it. */ static status_t -bfs_get_vnode(fs_volume *_volume, ino_t id, fs_vnode *_node, int *_type, - uint32 *_flags, bool reenter) +bfs_get_vnode(fs_volume* _volume, ino_t id, fs_vnode* _node, int* _type, + uint32* _flags, bool reenter) { //FUNCTION_START(("ino_t = %Ld\n", id)); - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; // first inode may be after the log area, we don't go through // the hassle and try to load an earlier block from disk @@ -252,7 +252,7 @@ bfs_get_vnode(fs_volume *_volume, ino_t id, fs_vnode *_node, int *_type, } CachedBlock cached(volume, id); - bfs_inode *node = (bfs_inode *)cached.Block(); + bfs_inode* node = (bfs_inode*)cached.Block(); if (node == NULL) { FATAL(("could not read inode: %Ld\n", id)); return B_IO_ERROR; @@ -264,7 +264,7 @@ bfs_get_vnode(fs_volume *_volume, ino_t id, fs_vnode *_node, int *_type, return status; } - Inode *inode = new(std::nothrow) Inode(volume, id); + Inode* inode = new(std::nothrow) Inode(volume, id); if (inode == NULL) return B_NO_MEMORY; @@ -284,10 +284,10 @@ bfs_get_vnode(fs_volume *_volume, ino_t id, fs_vnode *_node, int *_type, static status_t -bfs_put_vnode(fs_volume *_volume, fs_vnode *_node, bool reenter) +bfs_put_vnode(fs_volume* _volume, fs_vnode* _node, bool reenter) { - Volume *volume = (Volume *)_volume->private_volume; - Inode *inode = (Inode *)_node->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* inode = (Inode*)_node->private_node; // since a directory's size can be changed without having it opened, // we need to take care about their preallocated blocks here @@ -308,12 +308,12 @@ bfs_put_vnode(fs_volume *_volume, fs_vnode *_node, bool reenter) static status_t -bfs_remove_vnode(fs_volume *_volume, fs_vnode *_node, bool reenter) +bfs_remove_vnode(fs_volume* _volume, fs_vnode* _node, bool reenter) { FUNCTION(); - Volume *volume = (Volume *)_volume->private_volume; - Inode *inode = (Inode *)_node->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* inode = (Inode*)_node->private_node; // The "chkbfs" functionality uses this flag to prevent the space used // up by the inode from being freed - this flag is set only in situations @@ -344,7 +344,7 @@ bfs_remove_vnode(fs_volume *_volume, fs_vnode *_node, bool reenter) static bool -bfs_can_page(fs_volume *_volume, fs_vnode *_v, void *_cookie) +bfs_can_page(fs_volume* _volume, fs_vnode* _v, void* _cookie) { // TODO: we're obviously not even asked... return false; @@ -352,11 +352,11 @@ bfs_can_page(fs_volume *_volume, fs_vnode *_v, void *_cookie) static status_t -bfs_read_pages(fs_volume *_volume, fs_vnode *_node, void *_cookie, - off_t pos, const iovec *vecs, size_t count, size_t *_numBytes) +bfs_read_pages(fs_volume* _volume, fs_vnode* _node, void* _cookie, + off_t pos, const iovec* vecs, size_t count, size_t* _numBytes) { - Volume *volume = (Volume *)_volume->private_volume; - Inode *inode = (Inode *)_node->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* inode = (Inode*)_node->private_node; if (inode->FileCache() == NULL) RETURN_ERROR(B_BAD_VALUE); @@ -394,11 +394,11 @@ bfs_read_pages(fs_volume *_volume, fs_vnode *_node, void *_cookie, static status_t -bfs_write_pages(fs_volume *_volume, fs_vnode *_node, void *_cookie, - off_t pos, const iovec *vecs, size_t count, size_t *_numBytes) +bfs_write_pages(fs_volume* _volume, fs_vnode* _node, void* _cookie, + off_t pos, const iovec* vecs, size_t count, size_t* _numBytes) { - Volume *volume = (Volume *)_volume->private_volume; - Inode *inode = (Inode *)_node->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* inode = (Inode*)_node->private_node; if (volume->IsReadOnly()) return B_READ_ONLY_DEVICE; @@ -439,10 +439,10 @@ bfs_write_pages(fs_volume *_volume, fs_vnode *_node, void *_cookie, static status_t -bfs_io(fs_volume *_volume, fs_vnode *_node, void *_cookie, io_request *request) +bfs_io(fs_volume* _volume, fs_vnode* _node, void* _cookie, io_request* request) { - Volume *volume = (Volume *)_volume->private_volume; - Inode *inode = (Inode *)_node->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* inode = (Inode*)_node->private_node; if (volume->IsReadOnly()) return B_READ_ONLY_DEVICE; @@ -459,11 +459,11 @@ bfs_io(fs_volume *_volume, fs_vnode *_node, void *_cookie, io_request *request) static status_t -bfs_get_file_map(fs_volume *_volume, fs_vnode *_node, off_t offset, size_t size, - struct file_io_vec *vecs, size_t *_count) +bfs_get_file_map(fs_volume* _volume, fs_vnode* _node, off_t offset, size_t size, + struct file_io_vec* vecs, size_t* _count) { - Volume *volume = (Volume *)_volume->private_volume; - Inode *inode = (Inode *)_node->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* inode = (Inode*)_node->private_node; int32 blockShift = volume->BlockShift(); uint32 index = 0, max = *_count; @@ -513,11 +513,11 @@ bfs_get_file_map(fs_volume *_volume, fs_vnode *_node, off_t offset, size_t size, static status_t -bfs_lookup(fs_volume *_volume, fs_vnode *_directory, const char *file, - ino_t *_vnodeID) +bfs_lookup(fs_volume* _volume, fs_vnode* _directory, const char* file, + ino_t* _vnodeID) { - Volume *volume = (Volume *)_volume->private_volume; - Inode *directory = (Inode *)_directory->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* directory = (Inode*)_directory->private_node; InodeReadLocker locker(directory); @@ -526,11 +526,11 @@ bfs_lookup(fs_volume *_volume, fs_vnode *_directory, const char *file, if (status < B_OK) RETURN_ERROR(status); - BPlusTree *tree; + BPlusTree* tree; if (directory->GetTree(&tree) != B_OK) RETURN_ERROR(B_BAD_VALUE); - status = tree->Find((uint8 *)file, (uint16)strlen(file), _vnodeID); + status = tree->Find((uint8*)file, (uint16)strlen(file), _vnodeID); if (status < B_OK) { //PRINT(("bfs_walk() could not find %Ld:\"%s\": %s\n", directory->BlockNumber(), file, strerror(status))); return status; @@ -538,8 +538,8 @@ bfs_lookup(fs_volume *_volume, fs_vnode *_directory, const char *file, locker.Unlock(); - Inode *inode; - status = get_vnode(volume->FSVolume(), *_vnodeID, (void **)&inode); + Inode* inode; + status = get_vnode(volume->FSVolume(), *_vnodeID, (void**)&inode); if (status != B_OK) { REPORT_ERROR(status); return B_ENTRY_NOT_FOUND; @@ -550,29 +550,29 @@ bfs_lookup(fs_volume *_volume, fs_vnode *_directory, const char *file, static status_t -bfs_get_vnode_name(fs_volume *_volume, fs_vnode *_node, char *buffer, +bfs_get_vnode_name(fs_volume* _volume, fs_vnode* _node, char* buffer, size_t bufferSize) { - Inode *inode = (Inode *)_node->private_node; + Inode* inode = (Inode*)_node->private_node; return inode->GetName(buffer, bufferSize); } static status_t -bfs_ioctl(fs_volume *_volume, fs_vnode *_node, void *_cookie, ulong cmd, - void *buffer, size_t bufferLength) +bfs_ioctl(fs_volume* _volume, fs_vnode* _node, void* _cookie, ulong cmd, + void* buffer, size_t bufferLength) { FUNCTION_START(("node = %p, cmd = %lu, buf = %p, len = %ld\n", _node, cmd, buffer, bufferLength)); - Volume *volume = (Volume *)_volume->private_volume; - Inode *inode = (Inode *)_node->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* inode = (Inode*)_node->private_node; switch (cmd) { case BFS_IOCTL_VERSION: { - uint32 *version = (uint32 *)buffer; + uint32 *version = (uint32*)buffer; *version = 0x10000; return B_OK; @@ -580,8 +580,8 @@ bfs_ioctl(fs_volume *_volume, fs_vnode *_node, void *_cookie, ulong cmd, case BFS_IOCTL_START_CHECKING: { // start checking - BlockAllocator &allocator = volume->Allocator(); - check_control *control = (check_control *)buffer; + BlockAllocator& allocator = volume->Allocator(); + check_control* control = (check_control*)buffer; status_t status = allocator.StartChecking(control); if (status == B_OK) @@ -592,8 +592,8 @@ bfs_ioctl(fs_volume *_volume, fs_vnode *_node, void *_cookie, ulong cmd, case BFS_IOCTL_STOP_CHECKING: { // stop checking - BlockAllocator &allocator = volume->Allocator(); - check_control *control = (check_control *)buffer; + BlockAllocator& allocator = volume->Allocator(); + check_control* control = (check_control*)buffer; status_t status = allocator.StopChecking(control); if (status == B_OK) @@ -604,8 +604,8 @@ bfs_ioctl(fs_volume *_volume, fs_vnode *_node, void *_cookie, ulong cmd, case BFS_IOCTL_CHECK_NEXT_NODE: { // check next - BlockAllocator &allocator = volume->Allocator(); - check_control *control = (check_control *)buffer; + BlockAllocator& allocator = volume->Allocator(); + check_control* control = (check_control*)buffer; return allocator.CheckNextNode(control); } @@ -614,7 +614,7 @@ bfs_ioctl(fs_volume *_volume, fs_vnode *_node, void *_cookie, ulong cmd, // let's makebootable (or anyone else) update the boot block // while BFS is mounted if (user_memcpy(&volume->SuperBlock().pad_to_block, - (uint8 *)buffer + offsetof(disk_super_block, pad_to_block), + (uint8*)buffer + offsetof(disk_super_block, pad_to_block), sizeof(volume->SuperBlock().pad_to_block)) < B_OK) return B_BAD_ADDRESS; @@ -625,7 +625,7 @@ bfs_ioctl(fs_volume *_volume, fs_vnode *_node, void *_cookie, ulong cmd, { // allocate all free blocks and zero them out // (a test for the BlockAllocator)! - BlockAllocator &allocator = volume->Allocator(); + BlockAllocator& allocator = volume->Allocator(); Transaction transaction(volume, 0); CachedBlock cached(volume); block_run run; @@ -634,7 +634,7 @@ bfs_ioctl(fs_volume *_volume, fs_vnode *_node, void *_cookie, ulong cmd, PRINT(("write block_run(%ld, %d, %d)\n", run.allocation_group, run.start, run.length)); for (int32 i = 0;i < run.length;i++) { - uint8 *block = cached.SetToWritable(transaction, run); + uint8* block = cached.SetToWritable(transaction, run); if (block != NULL) memset(block, 0, volume->BlockSize()); } @@ -652,11 +652,11 @@ bfs_ioctl(fs_volume *_volume, fs_vnode *_node, void *_cookie, ulong cmd, for a file system. */ static status_t -bfs_set_flags(fs_volume *_volume, fs_vnode *_node, void *_cookie, int flags) +bfs_set_flags(fs_volume* _volume, fs_vnode* _node, void* _cookie, int flags) { FUNCTION_START(("node = %p, flags = %d", _node, flags)); - file_cookie *cookie = (file_cookie *)_cookie; + file_cookie* cookie = (file_cookie*)_cookie; cookie->open_mode = (cookie->open_mode & ~O_APPEND) | (flags & O_APPEND); return B_OK; @@ -664,34 +664,34 @@ bfs_set_flags(fs_volume *_volume, fs_vnode *_node, void *_cookie, int flags) static status_t -bfs_fsync(fs_volume *_volume, fs_vnode *_node) +bfs_fsync(fs_volume* _volume, fs_vnode* _node) { FUNCTION(); - Inode *inode = (Inode *)_node->private_node; + Inode* inode = (Inode*)_node->private_node; return inode->Sync(); } static status_t -bfs_read_stat(fs_volume *_volume, fs_vnode *_node, struct stat *stat) +bfs_read_stat(fs_volume* _volume, fs_vnode* _node, struct stat* stat) { FUNCTION(); - Inode *inode = (Inode *)_node->private_node; + Inode* inode = (Inode*)_node->private_node; fill_stat_buffer(inode, *stat); return B_OK; } static status_t -bfs_write_stat(fs_volume *_volume, fs_vnode *_node, const struct stat *stat, +bfs_write_stat(fs_volume* _volume, fs_vnode* _node, const struct stat* stat, uint32 mask) { FUNCTION(); - Volume *volume = (Volume *)_volume->private_volume; - Inode *inode = (Inode *)_node->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* inode = (Inode*)_node->private_node; if (volume->IsReadOnly()) return B_READ_ONLY_DEVICE; @@ -706,7 +706,7 @@ bfs_write_stat(fs_volume *_volume, fs_vnode *_node, const struct stat *stat, Transaction transaction(volume, inode->BlockNumber()); inode->WriteLockInTransaction(transaction); - bfs_inode &node = inode->Node(); + bfs_inode& node = inode->Node(); if (mask & B_STAT_SIZE) { // Since WSTAT_SIZE is the only thing that can fail directly, we @@ -775,13 +775,13 @@ bfs_write_stat(fs_volume *_volume, fs_vnode *_node, const struct stat *stat, status_t -bfs_create(fs_volume *_volume, fs_vnode *_directory, const char *name, - int openMode, int mode, void **_cookie, ino_t *_vnodeID) +bfs_create(fs_volume* _volume, fs_vnode* _directory, const char* name, + int openMode, int mode, void** _cookie, ino_t* _vnodeID) { FUNCTION_START(("name = \"%s\", perms = %d, openMode = %d\n", name, mode, openMode)); - Volume *volume = (Volume *)_volume->private_volume; - Inode *directory = (Inode *)_directory->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* directory = (Inode*)_directory->private_node; if (volume->IsReadOnly()) return B_READ_ONLY_DEVICE; @@ -791,7 +791,7 @@ bfs_create(fs_volume *_volume, fs_vnode *_directory, const char *name, // We are creating the cookie at this point, so that we don't have // to remove the inode if we don't have enough free memory later... - file_cookie *cookie = new(std::nothrow) file_cookie; + file_cookie* cookie = new(std::nothrow) file_cookie; if (cookie == NULL) RETURN_ERROR(B_NO_MEMORY); @@ -824,13 +824,13 @@ bfs_create(fs_volume *_volume, fs_vnode *_directory, const char *name, static status_t -bfs_create_symlink(fs_volume *_volume, fs_vnode *_directory, const char *name, - const char *path, int mode) +bfs_create_symlink(fs_volume* _volume, fs_vnode* _directory, const char* name, + const char* path, int mode) { FUNCTION_START(("name = \"%s\", path = \"%s\"\n", name, path)); - Volume *volume = (Volume *)_volume->private_volume; - Inode *directory = (Inode *)_directory->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* directory = (Inode*)_directory->private_node; if (volume->IsReadOnly()) return B_READ_ONLY_DEVICE; @@ -844,7 +844,7 @@ bfs_create_symlink(fs_volume *_volume, fs_vnode *_directory, const char *name, Transaction transaction(volume, directory->BlockNumber()); - Inode *link; + Inode* link; off_t id; status = Inode::Create(transaction, directory, name, S_SYMLINK | 0777, 0, 0, NULL, &id, &link); @@ -864,7 +864,7 @@ bfs_create_symlink(fs_volume *_volume, fs_vnode *_directory, const char *name, // The following call will have to write the inode back, so // we don't have to do that here... - status = link->WriteAt(transaction, 0, (const uint8 *)path, &length); + status = link->WriteAt(transaction, 0, (const uint8*)path, &length); } if (status == B_OK) @@ -886,7 +886,7 @@ bfs_create_symlink(fs_volume *_volume, fs_vnode *_directory, const char *name, status_t -bfs_link(fs_volume *_volume, fs_vnode *dir, const char *name, fs_vnode *node) +bfs_link(fs_volume* _volume, fs_vnode* dir, const char* name, fs_vnode* node) { FUNCTION_START(("name = \"%s\"\n", name)); @@ -897,15 +897,15 @@ bfs_link(fs_volume *_volume, fs_vnode *dir, const char *name, fs_vnode *node) status_t -bfs_unlink(fs_volume *_volume, fs_vnode *_directory, const char *name) +bfs_unlink(fs_volume* _volume, fs_vnode* _directory, const char* name) { FUNCTION_START(("name = \"%s\"\n", name)); if (!strcmp(name, "..") || !strcmp(name, ".")) return B_NOT_ALLOWED; - Volume *volume = (Volume *)_volume->private_volume; - Inode *directory = (Inode *)_directory->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* directory = (Inode*)_directory->private_node; status_t status = directory->CheckPermissions(W_OK); if (status < B_OK) @@ -924,8 +924,8 @@ bfs_unlink(fs_volume *_volume, fs_vnode *_directory, const char *name) status_t -bfs_rename(fs_volume *_volume, fs_vnode *_oldDir, const char *oldName, - fs_vnode *_newDir, const char *newName) +bfs_rename(fs_volume* _volume, fs_vnode* _oldDir, const char* oldName, + fs_vnode* _newDir, const char* newName) { FUNCTION_START(("oldDir = %p, oldName = \"%s\", newDir = %p, newName = \"%s\"\n", _oldDir, oldName, _newDir, newName)); @@ -935,9 +935,9 @@ bfs_rename(fs_volume *_volume, fs_vnode *_oldDir, const char *oldName, || strchr(newName, '/') != NULL) RETURN_ERROR(B_BAD_VALUE); - Volume *volume = (Volume *)_volume->private_volume; - Inode *oldDirectory = (Inode *)_oldDir->private_node; - Inode *newDirectory = (Inode *)_newDir->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* oldDirectory = (Inode*)_oldDir->private_node; + Inode* newDirectory = (Inode*)_newDir->private_node; // are we already done? if (oldDirectory == newDirectory && !strcmp(oldName, newName)) @@ -958,18 +958,18 @@ bfs_rename(fs_volume *_volume, fs_vnode *_oldDir, const char *oldName, // Get the directory's tree, and a pointer to the inode which should be // changed - BPlusTree *tree; + BPlusTree* tree; status = oldDirectory->GetTree(&tree); if (status < B_OK) RETURN_ERROR(status); off_t id; - status = tree->Find((const uint8 *)oldName, strlen(oldName), &id); + status = tree->Find((const uint8*)oldName, strlen(oldName), &id); if (status < B_OK) RETURN_ERROR(status); Vnode vnode(volume, id); - Inode *inode; + Inode* inode; if (vnode.Get(&inode) < B_OK) return B_IO_ERROR; @@ -989,7 +989,7 @@ bfs_rename(fs_volume *_volume, fs_vnode *_oldDir, const char *oldName, break; Vnode vnode(volume, parent); - Inode *parentNode; + Inode* parentNode; if (vnode.Get(&parentNode) < B_OK) return B_ERROR; @@ -1002,27 +1002,27 @@ bfs_rename(fs_volume *_volume, fs_vnode *_oldDir, const char *oldName, // First, try to make sure there is nothing that will stop us in // the target directory - since this is the only non-critical // failure, we will test this case first - BPlusTree *newTree = tree; + BPlusTree* newTree = tree; if (newDirectory != oldDirectory) { status = newDirectory->GetTree(&newTree); if (status < B_OK) RETURN_ERROR(status); } - status = newTree->Insert(transaction, (const uint8 *)newName, + status = newTree->Insert(transaction, (const uint8*)newName, strlen(newName), id); if (status == B_NAME_IN_USE) { // If there is already a file with that name, we have to remove // it, as long it's not a directory with files in it off_t clobber; - if (newTree->Find((const uint8 *)newName, strlen(newName), &clobber) + if (newTree->Find((const uint8*)newName, strlen(newName), &clobber) < B_OK) return B_NAME_IN_USE; if (clobber == id) return B_BAD_VALUE; Vnode vnode(volume, clobber); - Inode *other; + Inode* other; if (vnode.Get(&other) < B_OK) return B_NAME_IN_USE; @@ -1038,7 +1038,7 @@ bfs_rename(fs_volume *_volume, fs_vnode *_oldDir, const char *oldName, notify_entry_removed(volume->ID(), newDirectory->ID(), newName, clobber); - status = newTree->Insert(transaction, (const uint8 *)newName, + status = newTree->Insert(transaction, (const uint8*)newName, strlen(newName), id); } if (status < B_OK) @@ -1058,18 +1058,18 @@ bfs_rename(fs_volume *_volume, fs_vnode *_oldDir, const char *oldName, } if (status == B_OK) { - status = tree->Remove(transaction, (const uint8 *)oldName, + status = tree->Remove(transaction, (const uint8*)oldName, strlen(oldName), id); if (status == B_OK) { inode->Parent() = newDirectory->BlockRun(); // if it's a directory, update the parent directory pointer // in its tree if necessary - BPlusTree *movedTree = NULL; + BPlusTree* movedTree = NULL; if (oldDirectory != newDirectory && inode->IsDirectory() && (status = inode->GetTree(&movedTree)) == B_OK) { - status = movedTree->Replace(transaction, (const uint8 *)"..", + status = movedTree->Replace(transaction, (const uint8*)"..", 2, newDirectory->ID()); } @@ -1091,12 +1091,12 @@ bfs_rename(fs_volume *_volume, fs_vnode *_oldDir, const char *oldName, static status_t -bfs_open(fs_volume *_volume, fs_vnode *_node, int openMode, void **_cookie) +bfs_open(fs_volume* _volume, fs_vnode* _node, int openMode, void** _cookie) { FUNCTION(); - Volume *volume = (Volume *)_volume->private_volume; - Inode *inode = (Inode *)_node->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* inode = (Inode*)_node->private_node; // opening a directory read-only is allowed, although you can't read // any data from it. @@ -1120,7 +1120,7 @@ bfs_open(fs_volume *_volume, fs_vnode *_node, int openMode, void **_cookie) // This could greatly speed up continuous reads of big files, especially // in the indirect block section. - file_cookie *cookie = new(std::nothrow) file_cookie; + file_cookie* cookie = new(std::nothrow) file_cookie; if (cookie == NULL) RETURN_ERROR(B_NO_MEMORY); @@ -1161,28 +1161,28 @@ bfs_open(fs_volume *_volume, fs_vnode *_node, int openMode, void **_cookie) static status_t -bfs_read(fs_volume *_volume, fs_vnode *_node, void *_cookie, off_t pos, - void *buffer, size_t *_length) +bfs_read(fs_volume* _volume, fs_vnode* _node, void* _cookie, off_t pos, + void* buffer, size_t* _length) { //FUNCTION(); - Inode *inode = (Inode *)_node->private_node; + Inode* inode = (Inode*)_node->private_node; if (!inode->HasUserAccessableStream()) { *_length = 0; return inode->IsDirectory() ? B_IS_A_DIRECTORY : B_BAD_VALUE; } - return inode->ReadAt(pos, (uint8 *)buffer, _length); + return inode->ReadAt(pos, (uint8*)buffer, _length); } static status_t -bfs_write(fs_volume *_volume, fs_vnode *_node, void *_cookie, off_t pos, - const void *buffer, size_t *_length) +bfs_write(fs_volume* _volume, fs_vnode* _node, void* _cookie, off_t pos, + const void* buffer, size_t* _length) { //FUNCTION(); - Volume *volume = (Volume *)_volume->private_volume; - Inode *inode = (Inode *)_node->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* inode = (Inode*)_node->private_node; if (volume->IsReadOnly()) return B_READ_ONLY_DEVICE; @@ -1192,7 +1192,7 @@ bfs_write(fs_volume *_volume, fs_vnode *_node, void *_cookie, off_t pos, return inode->IsDirectory() ? B_IS_A_DIRECTORY : B_BAD_VALUE; } - file_cookie *cookie = (file_cookie *)_cookie; + file_cookie* cookie = (file_cookie*)_cookie; if (cookie->open_mode & O_APPEND) pos = inode->Size(); @@ -1202,7 +1202,7 @@ bfs_write(fs_volume *_volume, fs_vnode *_node, void *_cookie, off_t pos, // it might not be needed at all (the contents of // regular files aren't logged) - status_t status = inode->WriteAt(transaction, pos, (const uint8 *)buffer, + status_t status = inode->WriteAt(transaction, pos, (const uint8*)buffer, _length); if (status == B_OK) { transaction.Done(); @@ -1226,7 +1226,7 @@ bfs_write(fs_volume *_volume, fs_vnode *_node, void *_cookie, off_t pos, static status_t -bfs_close(fs_volume *_volume, fs_vnode *_node, void *_cookie) +bfs_close(fs_volume* _volume, fs_vnode* _node, void* _cookie) { FUNCTION(); return B_OK; @@ -1234,13 +1234,13 @@ bfs_close(fs_volume *_volume, fs_vnode *_node, void *_cookie) static status_t -bfs_free_cookie(fs_volume *_volume, fs_vnode *_node, void *_cookie) +bfs_free_cookie(fs_volume* _volume, fs_vnode* _node, void* _cookie) { FUNCTION(); - file_cookie *cookie = (file_cookie *)_cookie; - Volume *volume = (Volume *)_volume->private_volume; - Inode *inode = (Inode *)_node->private_node; + file_cookie* cookie = (file_cookie*)_cookie; + Volume* volume = (Volume*)_volume->private_volume; + Inode* inode = (Inode*)_node->private_node; Transaction transaction; bool needsTrimming = false; @@ -1315,11 +1315,11 @@ bfs_free_cookie(fs_volume *_volume, fs_vnode *_node, void *_cookie) is not allowed. */ static status_t -bfs_access(fs_volume *_volume, fs_vnode *_node, int accessMode) +bfs_access(fs_volume* _volume, fs_vnode* _node, int accessMode) { //FUNCTION(); - Inode *inode = (Inode *)_node->private_node; + Inode* inode = (Inode*)_node->private_node; status_t status = inode->CheckPermissions(accessMode); if (status < B_OK) RETURN_ERROR(status); @@ -1329,12 +1329,12 @@ bfs_access(fs_volume *_volume, fs_vnode *_node, int accessMode) static status_t -bfs_read_link(fs_volume *_volume, fs_vnode *_node, char *buffer, - size_t *_bufferSize) +bfs_read_link(fs_volume* _volume, fs_vnode* _node, char* buffer, + size_t* _bufferSize) { FUNCTION(); - Inode *inode = (Inode *)_node->private_node; + Inode* inode = (Inode*)_node->private_node; if (!inode->IsSymLink()) RETURN_ERROR(B_BAD_VALUE); @@ -1343,7 +1343,7 @@ bfs_read_link(fs_volume *_volume, fs_vnode *_node, char *buffer, if (inode->Size() < *_bufferSize) *_bufferSize = inode->Size(); - status_t status = inode->ReadAt(0, (uint8 *)buffer, _bufferSize); + status_t status = inode->ReadAt(0, (uint8*)buffer, _bufferSize); if (status < B_OK) RETURN_ERROR(status); @@ -1354,9 +1354,7 @@ bfs_read_link(fs_volume *_volume, fs_vnode *_node, char *buffer, if (linkLen < *_bufferSize) *_bufferSize = linkLen; - memcpy(buffer, inode->Node().short_symlink, *_bufferSize); - - return B_OK; + return user_memcpy(buffer, inode->Node().short_symlink, *_bufferSize); } @@ -1364,13 +1362,13 @@ bfs_read_link(fs_volume *_volume, fs_vnode *_node, char *buffer, static status_t -bfs_create_dir(fs_volume *_volume, fs_vnode *_directory, const char *name, - int mode, ino_t *_newVnodeID) +bfs_create_dir(fs_volume* _volume, fs_vnode* _directory, const char* name, + int mode, ino_t* _newVnodeID) { FUNCTION_START(("name = \"%s\", perms = %d\n", name, mode)); - Volume *volume = (Volume *)_volume->private_volume; - Inode *directory = (Inode *)_directory->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* directory = (Inode*)_directory->private_node; if (volume->IsReadOnly()) return B_READ_ONLY_DEVICE; @@ -1402,12 +1400,12 @@ bfs_create_dir(fs_volume *_volume, fs_vnode *_directory, const char *name, static status_t -bfs_remove_dir(fs_volume *_volume, fs_vnode *_directory, const char *name) +bfs_remove_dir(fs_volume* _volume, fs_vnode* _directory, const char* name) { FUNCTION_START(("name = \"%s\"\n", name)); - Volume *volume = (Volume *)_volume->private_volume; - Inode *directory = (Inode *)_directory->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* directory = (Inode*)_directory->private_node; Transaction transaction(volume, directory->BlockNumber()); @@ -1427,11 +1425,11 @@ bfs_remove_dir(fs_volume *_volume, fs_vnode *_directory, const char *name) bfs_open_dir() is also used by bfs_open_index_dir(). */ static status_t -bfs_open_dir(fs_volume *_volume, fs_vnode *_node, void **_cookie) +bfs_open_dir(fs_volume* _volume, fs_vnode* _node, void** _cookie) { FUNCTION(); - Inode *inode = (Inode *)_node->private_node; + Inode* inode = (Inode*)_node->private_node; status_t status = inode->CheckPermissions(R_OK); if (status < B_OK) RETURN_ERROR(status); @@ -1441,11 +1439,11 @@ bfs_open_dir(fs_volume *_volume, fs_vnode *_node, void **_cookie) if (!inode->IsContainer()) RETURN_ERROR(B_BAD_VALUE); - BPlusTree *tree; + BPlusTree* tree; if (inode->GetTree(&tree) != B_OK) RETURN_ERROR(B_BAD_VALUE); - TreeIterator *iterator = new(std::nothrow) TreeIterator(tree); + TreeIterator* iterator = new(std::nothrow) TreeIterator(tree); if (iterator == NULL) RETURN_ERROR(B_NO_MEMORY); @@ -1455,12 +1453,12 @@ bfs_open_dir(fs_volume *_volume, fs_vnode *_node, void **_cookie) static status_t -bfs_read_dir(fs_volume *_volume, fs_vnode *_node, void *_cookie, - struct dirent *dirent, size_t bufferSize, uint32 *_num) +bfs_read_dir(fs_volume* _volume, fs_vnode* _node, void* _cookie, + struct dirent* dirent, size_t bufferSize, uint32* _num) { FUNCTION(); - TreeIterator *iterator = (TreeIterator *)_cookie; + TreeIterator* iterator = (TreeIterator*)_cookie; uint16 length; ino_t id; @@ -1472,7 +1470,7 @@ bfs_read_dir(fs_volume *_volume, fs_vnode *_node, void *_cookie, } else if (status != B_OK) RETURN_ERROR(status); - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; dirent->d_dev = volume->ID(); dirent->d_ino = id; @@ -1486,17 +1484,17 @@ bfs_read_dir(fs_volume *_volume, fs_vnode *_node, void *_cookie, /*! Sets the TreeIterator back to the beginning of the directory. */ static status_t -bfs_rewind_dir(fs_volume * /*_volume*/, fs_vnode * /*node*/, void *_cookie) +bfs_rewind_dir(fs_volume* /*_volume*/, fs_vnode* /*node*/, void* _cookie) { FUNCTION(); - TreeIterator *iterator = (TreeIterator *)_cookie; + TreeIterator* iterator = (TreeIterator*)_cookie; return iterator->Rewind(); } static status_t -bfs_close_dir(fs_volume * /*_volume*/, fs_vnode * /*node*/, void * /*_cookie*/) +bfs_close_dir(fs_volume* /*_volume*/, fs_vnode* /*node*/, void* /*_cookie*/) { FUNCTION(); return B_OK; @@ -1504,9 +1502,9 @@ bfs_close_dir(fs_volume * /*_volume*/, fs_vnode * /*node*/, void * /*_cookie*/) static status_t -bfs_free_dir_cookie(fs_volume *_volume, fs_vnode *node, void *_cookie) +bfs_free_dir_cookie(fs_volume* _volume, fs_vnode* node, void* _cookie) { - delete (TreeIterator *)_cookie; + delete (TreeIterator*)_cookie; return B_OK; } @@ -1515,13 +1513,13 @@ bfs_free_dir_cookie(fs_volume *_volume, fs_vnode *node, void *_cookie) static status_t -bfs_open_attr_dir(fs_volume *_volume, fs_vnode *_node, void **_cookie) +bfs_open_attr_dir(fs_volume* _volume, fs_vnode* _node, void** _cookie) { - Inode *inode = (Inode *)_node->private_node; + Inode* inode = (Inode*)_node->private_node; FUNCTION(); - AttributeIterator *iterator = new(std::nothrow) AttributeIterator(inode); + AttributeIterator* iterator = new(std::nothrow) AttributeIterator(inode); if (iterator == NULL) RETURN_ERROR(B_NO_MEMORY); @@ -1531,7 +1529,7 @@ bfs_open_attr_dir(fs_volume *_volume, fs_vnode *_node, void **_cookie) static status_t -bfs_close_attr_dir(fs_volume *_volume, fs_vnode *node, void *cookie) +bfs_close_attr_dir(fs_volume* _volume, fs_vnode* node, void* cookie) { FUNCTION(); return B_OK; @@ -1539,10 +1537,10 @@ bfs_close_attr_dir(fs_volume *_volume, fs_vnode *node, void *cookie) static status_t -bfs_free_attr_dir_cookie(fs_volume *_volume, fs_vnode *node, void *_cookie) +bfs_free_attr_dir_cookie(fs_volume* _volume, fs_vnode* node, void* _cookie) { FUNCTION(); - AttributeIterator *iterator = (AttributeIterator *)_cookie; + AttributeIterator* iterator = (AttributeIterator*)_cookie; delete iterator; return B_OK; @@ -1550,21 +1548,21 @@ bfs_free_attr_dir_cookie(fs_volume *_volume, fs_vnode *node, void *_cookie) static status_t -bfs_rewind_attr_dir(fs_volume *_volume, fs_vnode *_node, void *_cookie) +bfs_rewind_attr_dir(fs_volume* _volume, fs_vnode* _node, void* _cookie) { FUNCTION(); - AttributeIterator *iterator = (AttributeIterator *)_cookie; + AttributeIterator* iterator = (AttributeIterator*)_cookie; RETURN_ERROR(iterator->Rewind()); } static status_t -bfs_read_attr_dir(fs_volume *_volume, fs_vnode *node, void *_cookie, - struct dirent *dirent, size_t bufferSize, uint32 *_num) +bfs_read_attr_dir(fs_volume* _volume, fs_vnode* node, void* _cookie, + struct dirent* dirent, size_t bufferSize, uint32* _num) { FUNCTION(); - AttributeIterator *iterator = (AttributeIterator *)_cookie; + AttributeIterator* iterator = (AttributeIterator*)_cookie; uint32 type; size_t length; @@ -1577,7 +1575,7 @@ bfs_read_attr_dir(fs_volume *_volume, fs_vnode *node, void *_cookie, RETURN_ERROR(status); } - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; dirent->d_dev = volume->ID(); dirent->d_reclen = sizeof(struct dirent) + length; @@ -1588,44 +1586,44 @@ bfs_read_attr_dir(fs_volume *_volume, fs_vnode *node, void *_cookie, static status_t -bfs_create_attr(fs_volume *_volume, fs_vnode *_node, const char *name, - uint32 type, int openMode, void **_cookie) +bfs_create_attr(fs_volume* _volume, fs_vnode* _node, const char* name, + uint32 type, int openMode, void** _cookie) { FUNCTION(); - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; if (volume->IsReadOnly()) return B_READ_ONLY_DEVICE; - Inode *inode = (Inode *)_node->private_node; + Inode* inode = (Inode*)_node->private_node; Attribute attribute(inode); - return attribute.Create(name, type, openMode, (attr_cookie **)_cookie); + return attribute.Create(name, type, openMode, (attr_cookie**)_cookie); } static status_t -bfs_open_attr(fs_volume *_volume, fs_vnode *_node, const char *name, - int openMode, void **_cookie) +bfs_open_attr(fs_volume* _volume, fs_vnode* _node, const char* name, + int openMode, void** _cookie) { FUNCTION(); - Inode *inode = (Inode *)_node->private_node; + Inode* inode = (Inode*)_node->private_node; Attribute attribute(inode); - return attribute.Open(name, openMode, (attr_cookie **)_cookie); + return attribute.Open(name, openMode, (attr_cookie**)_cookie); } static status_t -bfs_close_attr(fs_volume *_volume, fs_vnode *_file, void *cookie) +bfs_close_attr(fs_volume* _volume, fs_vnode* _file, void* cookie) { return B_OK; } static status_t -bfs_free_attr_cookie(fs_volume *_volume, fs_vnode *_file, void *cookie) +bfs_free_attr_cookie(fs_volume* _volume, fs_vnode* _file, void* cookie) { delete (attr_cookie*)cookie; return B_OK; @@ -1633,35 +1631,35 @@ bfs_free_attr_cookie(fs_volume *_volume, fs_vnode *_file, void *cookie) static status_t -bfs_read_attr(fs_volume *_volume, fs_vnode *_file, void *_cookie, off_t pos, - void *buffer, size_t *_length) +bfs_read_attr(fs_volume* _volume, fs_vnode* _file, void* _cookie, off_t pos, + void* buffer, size_t* _length) { FUNCTION(); - attr_cookie *cookie = (attr_cookie *)_cookie; - Inode *inode = (Inode *)_file->private_node; + attr_cookie* cookie = (attr_cookie*)_cookie; + Inode* inode = (Inode*)_file->private_node; Attribute attribute(inode, cookie); - return attribute.Read(cookie, pos, (uint8 *)buffer, _length); + return attribute.Read(cookie, pos, (uint8*)buffer, _length); } static status_t -bfs_write_attr(fs_volume *_volume, fs_vnode *_file, void *_cookie, - off_t pos, const void *buffer, size_t *_length) +bfs_write_attr(fs_volume* _volume, fs_vnode* _file, void* _cookie, + off_t pos, const void* buffer, size_t* _length) { FUNCTION(); - attr_cookie *cookie = (attr_cookie *)_cookie; - Volume *volume = (Volume *)_volume->private_volume; - Inode *inode = (Inode *)_file->private_node; + attr_cookie* cookie = (attr_cookie*)_cookie; + Volume* volume = (Volume*)_volume->private_volume; + Inode* inode = (Inode*)_file->private_node; Transaction transaction(volume, inode->BlockNumber()); Attribute attribute(inode, cookie); status_t status = attribute.Write(transaction, cookie, pos, - (const uint8 *)buffer, _length); + (const uint8*)buffer, _length); if (status == B_OK) { transaction.Done(); @@ -1676,13 +1674,13 @@ bfs_write_attr(fs_volume *_volume, fs_vnode *_file, void *_cookie, static status_t -bfs_read_attr_stat(fs_volume *_volume, fs_vnode *_file, void *_cookie, - struct stat *stat) +bfs_read_attr_stat(fs_volume* _volume, fs_vnode* _file, void* _cookie, + struct stat* stat) { FUNCTION(); - attr_cookie *cookie = (attr_cookie *)_cookie; - Inode *inode = (Inode *)_file->private_node; + attr_cookie* cookie = (attr_cookie*)_cookie; + Inode* inode = (Inode*)_file->private_node; Attribute attribute(inode, cookie); @@ -1691,16 +1689,16 @@ bfs_read_attr_stat(fs_volume *_volume, fs_vnode *_file, void *_cookie, static status_t -bfs_write_attr_stat(fs_volume *_volume, fs_vnode *file, void *cookie, - const struct stat *stat, int statMask) +bfs_write_attr_stat(fs_volume* _volume, fs_vnode* file, void* cookie, + const struct stat* stat, int statMask) { return EOPNOTSUPP; } static status_t -bfs_rename_attr(fs_volume *_volume, fs_vnode *fromFile, const char *fromName, - fs_vnode *toFile, const char *toName) +bfs_rename_attr(fs_volume* _volume, fs_vnode* fromFile, const char* fromName, + fs_vnode* toFile, const char* toName) { FUNCTION_START(("name = \"%s\", to = \"%s\"\n", fromName, toName)); @@ -1713,12 +1711,12 @@ bfs_rename_attr(fs_volume *_volume, fs_vnode *fromFile, const char *fromName, static status_t -bfs_remove_attr(fs_volume *_volume, fs_vnode *_node, const char *name) +bfs_remove_attr(fs_volume* _volume, fs_vnode* _node, const char* name) { FUNCTION_START(("name = \"%s\"\n", name)); - Volume *volume = (Volume *)_volume->private_volume; - Inode *inode = (Inode *)_node->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* inode = (Inode*)_node->private_node; status_t status = inode->CheckPermissions(W_OK); if (status < B_OK) @@ -1742,9 +1740,9 @@ bfs_remove_attr(fs_volume *_volume, fs_vnode *_node, const char *name) status_t -bfs_create_special_node(fs_volume *_volume, fs_vnode *_directory, - const char *name, fs_vnode *subVnode, mode_t mode, uint32 flags, - fs_vnode *_superVnode, ino_t *_nodeID) +bfs_create_special_node(fs_volume* _volume, fs_vnode* _directory, + const char* name, fs_vnode* subVnode, mode_t mode, uint32 flags, + fs_vnode* _superVnode, ino_t* _nodeID) { // no need to support entry-less nodes if (name == NULL) @@ -1753,8 +1751,8 @@ bfs_create_special_node(fs_volume *_volume, fs_vnode *_directory, FUNCTION_START(("name = \"%s\", mode = %d, flags = 0x%lx, subVnode: %p\n", name, mode, flags, subVnode)); - Volume *volume = (Volume *)_volume->private_volume; - Inode *directory = (Inode *)_directory->private_node; + Volume* volume = (Volume*)_volume->private_volume; + Inode* directory = (Inode*)_directory->private_node; if (volume->IsReadOnly()) return B_READ_ONLY_DEVICE; @@ -1769,7 +1767,7 @@ bfs_create_special_node(fs_volume *_volume, fs_vnode *_directory, Transaction transaction(volume, directory->BlockNumber()); off_t id; - Inode *inode; + Inode* inode; status = Inode::Create(transaction, directory, name, mode, O_EXCL, 0, NULL, &id, &inode, subVnode ? subVnode->ops : NULL, flags); if (status == B_OK) { @@ -1789,11 +1787,11 @@ bfs_create_special_node(fs_volume *_volume, fs_vnode *_directory, static status_t -bfs_open_index_dir(fs_volume *_volume, void **_cookie) +bfs_open_index_dir(fs_volume* _volume, void** _cookie) { FUNCTION(); - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; if (volume->IndicesNode() == NULL) { // This volume does not have any indices @@ -1813,11 +1811,11 @@ bfs_open_index_dir(fs_volume *_volume, void **_cookie) static status_t -bfs_close_index_dir(fs_volume *_volume, void *_cookie) +bfs_close_index_dir(fs_volume* _volume, void* _cookie) { FUNCTION(); - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; fs_vnode indicesNode; indicesNode.private_node = volume->IndicesNode(); @@ -1827,11 +1825,11 @@ bfs_close_index_dir(fs_volume *_volume, void *_cookie) static status_t -bfs_free_index_dir_cookie(fs_volume *_volume, void *_cookie) +bfs_free_index_dir_cookie(fs_volume* _volume, void* _cookie) { FUNCTION(); - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; fs_vnode indicesNode; indicesNode.private_node = volume->IndicesNode(); @@ -1841,11 +1839,11 @@ bfs_free_index_dir_cookie(fs_volume *_volume, void *_cookie) static status_t -bfs_rewind_index_dir(fs_volume *_volume, void *_cookie) +bfs_rewind_index_dir(fs_volume* _volume, void* _cookie) { FUNCTION(); - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; fs_vnode indicesNode; indicesNode.private_node = volume->IndicesNode(); @@ -1855,12 +1853,12 @@ bfs_rewind_index_dir(fs_volume *_volume, void *_cookie) static status_t -bfs_read_index_dir(fs_volume *_volume, void *_cookie, struct dirent *dirent, - size_t bufferSize, uint32 *_num) +bfs_read_index_dir(fs_volume* _volume, void* _cookie, struct dirent* dirent, + size_t bufferSize, uint32* _num) { FUNCTION(); - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; fs_vnode indicesNode; indicesNode.private_node = volume->IndicesNode(); @@ -1871,12 +1869,12 @@ bfs_read_index_dir(fs_volume *_volume, void *_cookie, struct dirent *dirent, static status_t -bfs_create_index(fs_volume *_volume, const char *name, uint32 type, +bfs_create_index(fs_volume* _volume, const char* name, uint32 type, uint32 flags) { FUNCTION_START(("name = \"%s\", type = %ld, flags = %ld\n", name, type, flags)); - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; if (volume->IsReadOnly()) return B_READ_ONLY_DEVICE; @@ -1898,11 +1896,11 @@ bfs_create_index(fs_volume *_volume, const char *name, uint32 type, static status_t -bfs_remove_index(fs_volume *_volume, const char *name) +bfs_remove_index(fs_volume* _volume, const char* name) { FUNCTION(); - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; if (volume->IsReadOnly()) return B_READ_ONLY_DEVICE; @@ -1911,7 +1909,7 @@ bfs_remove_index(fs_volume *_volume, const char *name) if (geteuid() != 0) return B_NOT_ALLOWED; - Inode *indices = volume->IndicesNode(); + Inode* indices = volume->IndicesNode(); if (indices == NULL) return B_ENTRY_NOT_FOUND; @@ -1926,18 +1924,18 @@ bfs_remove_index(fs_volume *_volume, const char *name) static status_t -bfs_stat_index(fs_volume *_volume, const char *name, struct stat *stat) +bfs_stat_index(fs_volume* _volume, const char* name, struct stat* stat) { FUNCTION_START(("name = %s\n", name)); - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; Index index(volume); status_t status = index.SetTo(name); if (status < B_OK) RETURN_ERROR(status); - bfs_inode &node = index.Node()->Node(); + bfs_inode& node = index.Node()->Node(); stat->st_type = index.Type(); stat->st_size = node.data.Size(); @@ -1962,15 +1960,15 @@ bfs_stat_index(fs_volume *_volume, const char *name, struct stat *stat) static status_t -bfs_open_query(fs_volume *_volume, const char *queryString, uint32 flags, - port_id port, uint32 token, void **_cookie) +bfs_open_query(fs_volume* _volume, const char* queryString, uint32 flags, + port_id port, uint32 token, void** _cookie) { FUNCTION_START(("bfs_open_query(\"%s\", flags = %lu, port_id = %ld, token = %ld)\n", queryString, flags, port, token)); - Volume *volume = (Volume *)_volume->private_volume; + Volume* volume = (Volume*)_volume->private_volume; - Expression *expression = new(std::nothrow) Expression((char *)queryString); + Expression* expression = new(std::nothrow) Expression((char*)queryString); if (expression == NULL) RETURN_ERROR(B_NO_MEMORY); @@ -1982,7 +1980,7 @@ bfs_open_query(fs_volume *_volume, const char *queryString, uint32 flags, RETURN_ERROR(B_BAD_VALUE); } - Query *query = new(std::nothrow) Query(volume, expression, flags); + Query* query = new(std::nothrow) Query(volume, expression, flags); if (query == NULL) { delete expression; RETURN_ERROR(B_NO_MEMORY); @@ -1991,14 +1989,14 @@ bfs_open_query(fs_volume *_volume, const char *queryString, uint32 flags, if (flags & B_LIVE_QUERY) query->SetLiveMode(port, token); - *_cookie = (void *)query; + *_cookie = (void*)query; return B_OK; } static status_t -bfs_close_query(fs_volume *_volume, void *cookie) +bfs_close_query(fs_volume* _volume, void* cookie) { FUNCTION(); return B_OK; @@ -2006,12 +2004,12 @@ bfs_close_query(fs_volume *_volume, void *cookie) static status_t -bfs_free_query_cookie(fs_volume *_volume, void *cookie) +bfs_free_query_cookie(fs_volume* _volume, void* cookie) { FUNCTION(); - Query *query = (Query *)cookie; - Expression *expression = query->GetExpression(); + Query* query = (Query*)cookie; + Expression* expression = query->GetExpression(); delete query; delete expression; @@ -2020,11 +2018,11 @@ bfs_free_query_cookie(fs_volume *_volume, void *cookie) static status_t -bfs_read_query(fs_volume * /*_volume*/, void *cookie, struct dirent *dirent, - size_t bufferSize, uint32 *_num) +bfs_read_query(fs_volume* /*_volume*/, void* cookie, struct dirent* dirent, + size_t bufferSize, uint32* _num) { FUNCTION(); - Query *query = (Query *)cookie; + Query* query = (Query*)cookie; status_t status = query->GetNextEntry(dirent, bufferSize); if (status == B_OK) *_num = 1; @@ -2038,11 +2036,11 @@ bfs_read_query(fs_volume * /*_volume*/, void *cookie, struct dirent *dirent, static status_t -bfs_rewind_query(fs_volume * /*_volume*/, void *cookie) +bfs_rewind_query(fs_volume* /*_volume*/, void* cookie) { FUNCTION(); - Query *query = (Query *)cookie; + Query* query = (Query*)cookie; return query->Rewind(); } @@ -2060,8 +2058,8 @@ bfs_get_supported_operations(partition_data* partition, uint32 mask) static status_t -bfs_initialize(int fd, partition_id partitionID, const char *name, - const char *parameterString, off_t /*partitionSize*/, disk_job_id job) +bfs_initialize(int fd, partition_id partitionID, const char* name, + const char* parameterString, off_t /*partitionSize*/, disk_job_id job) { // check name status_t status = check_volume_name(name); @@ -2296,7 +2294,7 @@ static file_system_module_info sBeFileSystem = { bfs_initialize, }; -module_info *modules[] = { - (module_info *)&sBeFileSystem, +module_info* modules[] = { + (module_info*)&sBeFileSystem, NULL, };