* 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:
@@ -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.
|
* This file may be used under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef UTILITY_H
|
#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
|
inline bool
|
||||||
is_index(int mode)
|
is_index(int mode)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -271,8 +271,6 @@ struct file_cookie {
|
|||||||
// notify every second if the file size has changed
|
// notify every second if the file size has changed
|
||||||
#define INODE_NOTIFICATION_INTERVAL 1000000LL
|
#define INODE_NOTIFICATION_INTERVAL 1000000LL
|
||||||
|
|
||||||
//**************************************
|
|
||||||
|
|
||||||
|
|
||||||
/*! Converts the nano seconds given to the internal 16 bit resolution that
|
/*! 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
|
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
|
// #pragma mark - block_run inline functions
|
||||||
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 -
|
|
||||||
|
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
@@ -383,21 +348,20 @@ block_run::Run(int32 group, uint16 start, uint16 length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/************************ small_data inline functions ************************/
|
// #pragma mark - small_data inline functions
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
|
|
||||||
inline char *
|
inline char*
|
||||||
small_data::Name() const
|
small_data::Name() const
|
||||||
{
|
{
|
||||||
return const_cast<char *>(name);
|
return const_cast<char*>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline uint8 *
|
inline uint8*
|
||||||
small_data::Data() const
|
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
|
small_data::Next() const
|
||||||
{
|
{
|
||||||
return (small_data *)((uint8 *)this + Size());
|
return (small_data*)((uint8*)this + Size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool
|
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
|
// 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
|
// the block, we would touch invalid memory (although that can't cause wrong
|
||||||
// results)
|
// 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
|
#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
|
#ifndef B_PLUS_TREE_H
|
||||||
#define 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include "Stream.h"
|
||||||
|
#include "Utility.h"
|
||||||
|
|
||||||
|
|
||||||
template<class T> class Stack;
|
template<class T> class Stack;
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,22 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2003, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2003-2009, Axel Dörfler, [email protected].
|
||||||
** Distributed under the terms of the OpenBeOS License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "Volume.h"
|
#include <fcntl.h>
|
||||||
#include "Directory.h"
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <boot/partitions.h>
|
#include <boot/partitions.h>
|
||||||
#include <boot/platform.h>
|
#include <boot/platform.h>
|
||||||
#include <boot/vfs.h>
|
#include <boot/vfs.h>
|
||||||
#include <util/kernel_cpp.h>
|
#include <util/kernel_cpp.h>
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include "Volume.h"
|
||||||
#include <unistd.h>
|
#include "Directory.h"
|
||||||
#include <string.h>
|
#include "Utility.h"
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define TRACE_BFS 0
|
#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)
|
// try block 0 again (can only happen on the big endian BFS)
|
||||||
if (read_pos(fDevice, 0, &fSuperBlock, sizeof(disk_super_block)) < B_OK)
|
if (read_pos(fDevice, 0, &fSuperBlock, sizeof(disk_super_block)) < B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!IsValidSuperBlock())
|
if (!IsValidSuperBlock())
|
||||||
return;
|
return;
|
||||||
#else
|
#else
|
||||||
@@ -74,7 +75,7 @@ Volume::~Volume()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Volume::InitCheck()
|
Volume::InitCheck()
|
||||||
{
|
{
|
||||||
if (fDevice < B_OK)
|
if (fDevice < B_OK)
|
||||||
@@ -118,7 +119,7 @@ Volume::ValidateBlockRun(block_run run)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
block_run
|
block_run
|
||||||
Volume::ToBlockRun(off_t block) const
|
Volume::ToBlockRun(off_t block) const
|
||||||
{
|
{
|
||||||
block_run run;
|
block_run run;
|
||||||
|
|||||||
Reference in New Issue
Block a user