diff --git a/src/add-ons/kernel/file_systems/bfs/Utility.h b/src/add-ons/kernel/file_systems/bfs/Utility.h index 4eec90e05d..3839a2e861 100644 --- a/src/add-ons/kernel/file_systems/bfs/Utility.h +++ b/src/add-ons/kernel/file_systems/bfs/Utility.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2001-2009, Axel Dörfler, axeld@pinc-software.de. * This file may be used under the terms of the MIT License. */ #ifndef UTILITY_H @@ -66,6 +66,41 @@ round_down(const IntType& value, const RoundType& to) } +inline int32 +divide_roundup(int32 num, int32 divisor) +{ + return (num + divisor - 1) / divisor; +} + + +inline int64 +divide_roundup(int64 num, int32 divisor) +{ + return (num + divisor - 1) / divisor; +} + + +inline int +get_shift(uint64 i) +{ + int c; + c = 0; + while (i > 1) { + i >>= 1; + c++; + } + return c; +} + + +inline uint32 +key_align(uint32 data) +{ + // rounds up to the next off_t boundary + return (data + sizeof(off_t) - 1) & ~(sizeof(off_t) - 1); +} + + inline bool is_index(int mode) { diff --git a/src/add-ons/kernel/file_systems/bfs/bfs.h b/src/add-ons/kernel/file_systems/bfs/bfs.h index 54991e1de3..97e02877a2 100644 --- a/src/add-ons/kernel/file_systems/bfs/bfs.h +++ b/src/add-ons/kernel/file_systems/bfs/bfs.h @@ -271,8 +271,6 @@ struct file_cookie { // notify every second if the file size has changed #define INODE_NOTIFICATION_INTERVAL 1000000LL -//************************************** - /*! Converts the nano seconds given to the internal 16 bit resolution that BFS uses. If \a time is zero, 12 bits will get a monotonically increasing @@ -292,40 +290,7 @@ unique_from_nsec(uint32 time) } -inline int32 -divide_roundup(int32 num,int32 divisor) -{ - return (num + divisor - 1) / divisor; -} - -inline int64 -divide_roundup(int64 num,int32 divisor) -{ - return (num + divisor - 1) / divisor; -} - -inline int -get_shift(uint64 i) -{ - int c; - c = 0; - while (i > 1) { - i >>= 1; - c++; - } - return c; -} - -inline uint32 -key_align(uint32 data) -{ - // rounds up to the next off_t boundary - return (data + sizeof(off_t) - 1) & ~(sizeof(off_t) - 1); -} - - -/************************ block_run inline functions ************************/ -// #pragma mark - +// #pragma mark - block_run inline functions inline bool @@ -383,21 +348,20 @@ block_run::Run(int32 group, uint16 start, uint16 length) } -/************************ small_data inline functions ************************/ -// #pragma mark - +// #pragma mark - small_data inline functions -inline char * +inline char* small_data::Name() const { - return const_cast(name); + return const_cast(name); } -inline uint8 * +inline uint8* small_data::Data() const { - return (uint8 *)Name() + NameSize() + 3; + return (uint8*)Name() + NameSize() + 3; } @@ -408,20 +372,21 @@ small_data::Size() const } -inline small_data * +inline small_data* small_data::Next() const { - return (small_data *)((uint8 *)this + Size()); + return (small_data*)((uint8*)this + Size()); } inline bool -small_data::IsLast(const bfs_inode *inode) const +small_data::IsLast(const bfs_inode* inode) const { // we need to check the location first, because if name_size is already beyond // the block, we would touch invalid memory (although that can't cause wrong // results) - return (addr_t)this > (addr_t)inode + inode->InodeSize() - sizeof(small_data) || name_size == 0; + return (addr_t)this > (addr_t)inode + + inode->InodeSize() - sizeof(small_data) || name_size == 0; } #ifdef _BOOT_MODE diff --git a/src/system/boot/loader/file_systems/bfs/BPlusTree.h b/src/system/boot/loader/file_systems/bfs/BPlusTree.h index 6273ed3835..28b58d5c03 100644 --- a/src/system/boot/loader/file_systems/bfs/BPlusTree.h +++ b/src/system/boot/loader/file_systems/bfs/BPlusTree.h @@ -1,19 +1,16 @@ +/* + * Copyright 2001-2009, Axel Dörfler, axeld@pinc-software.de. + * This file may be used under the terms of the MIT License. + */ #ifndef B_PLUS_TREE_H #define B_PLUS_TREE_H -/* BPlusTree - BFS B+Tree implementation -** -** Initial version by Axel Dörfler, axeld@pinc-software.de -** Roughly based on 'btlib' written by Marcus J. Ranum -** -** Copyright (c) 2001-2002 pinc Software. All Rights Reserved. -** This file may be used under the terms of the OpenBeOS License. -*/ -#include "Stream.h" - #include +#include "Stream.h" +#include "Utility.h" + template class Stack; diff --git a/src/system/boot/loader/file_systems/bfs/bfs.cpp b/src/system/boot/loader/file_systems/bfs/bfs.cpp index 9b50897ede..26da30fe8c 100644 --- a/src/system/boot/loader/file_systems/bfs/bfs.cpp +++ b/src/system/boot/loader/file_systems/bfs/bfs.cpp @@ -1,21 +1,22 @@ /* -** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2003-2009, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ -#include "Volume.h" -#include "Directory.h" +#include +#include +#include +#include #include #include #include #include -#include -#include -#include -#include +#include "Volume.h" +#include "Directory.h" +#include "Utility.h" #define TRACE_BFS 0 @@ -45,7 +46,7 @@ Volume::Volume(boot::Partition *partition) // try block 0 again (can only happen on the big endian BFS) if (read_pos(fDevice, 0, &fSuperBlock, sizeof(disk_super_block)) < B_OK) return; - + if (!IsValidSuperBlock()) return; #else @@ -74,7 +75,7 @@ Volume::~Volume() } -status_t +status_t Volume::InitCheck() { if (fDevice < B_OK) @@ -118,7 +119,7 @@ Volume::ValidateBlockRun(block_run run) } -block_run +block_run Volume::ToBlockRun(off_t block) const { block_run run;