* Moved most utility functions from bfs.h to Utility.h.

* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31770 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-07-26 13:44:31 +00:00
parent 0043d232d3
commit 71e439ea3e
4 changed files with 67 additions and 69 deletions
+36 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2001-2008, Axel Dörfler, [email protected].
* Copyright 2001-2009, Axel Dörfler, [email protected].
* 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)
{
+11 -46
View File
@@ -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<char *>(name);
return const_cast<char*>(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
@@ -1,19 +1,16 @@
/*
* Copyright 2001-2009, Axel Dörfler, [email protected].
* 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, [email protected]
** 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 <stdlib.h>
#include "Stream.h"
#include "Utility.h"
template<class T> class Stack;
+13 -12
View File
@@ -1,21 +1,22 @@
/*
** Copyright 2003, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
* Copyright 2003-2009, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*/
#include "Volume.h"
#include "Directory.h"
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <boot/partitions.h>
#include <boot/platform.h>
#include <boot/vfs.h>
#include <util/kernel_cpp.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#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;