#ifndef __BTREESINTERNAL__
#define __BTREESINTERNAL__
#include <sys/appleapiopts.h>
#ifdef KERNEL
#ifdef __APPLE_API_PRIVATE
#ifndef __FILEMGRINTERNAL__
#include "FileMgrInternal.h"
#endif
enum {
fsBTInvalidHeaderErr = btBadHdr,
fsBTBadRotateErr = dsBadRotate,
fsBTInvalidNodeErr = btBadNode,
fsBTRecordTooLargeErr = btNoFit,
fsBTRecordNotFoundErr = btNotFound,
fsBTDuplicateRecordErr = btExists,
fsBTFullErr = btNoSpaceAvail,
fsBTInvalidFileErr = ERR_BASE + 0x0302,
fsBTrFileAlreadyOpenErr = ERR_BASE + 0x0303,
fsBTInvalidIteratorErr = ERR_BASE + 0x0308,
fsBTEmptyErr = ERR_BASE + 0x030A,
fsBTNoMoreMapNodesErr = ERR_BASE + 0x030B,
fsBTBadNodeSize = ERR_BASE + 0x030C,
fsBTBadNodeType = ERR_BASE + 0x030D,
fsBTInvalidKeyLengthErr = ERR_BASE + 0x030E,
fsBTStartOfIterationErr = ERR_BASE + 0x0353,
fsBTEndOfIterationErr = ERR_BASE + 0x0354,
fsBTUnknownVersionErr = ERR_BASE + 0x0355,
fsBTTreeTooDeepErr = ERR_BASE + 0x0357,
fsIteratorExitedScopeErr = ERR_BASE + 0x0A02,
fsIteratorScopeExceptionErr = ERR_BASE + 0x0A03,
fsUnknownIteratorMovementErr = ERR_BASE + 0x0A04,
fsInvalidIterationMovmentErr = ERR_BASE + 0x0A05,
fsClientIDMismatchErr = ERR_BASE + 0x0A06,
fsEndOfIterationErr = ERR_BASE + 0x0A07,
fsBTTimeOutErr = ERR_BASE + 0x0A08
};
struct BlockDescriptor{
void *buffer;
void *blockHeader;
daddr64_t blockNum;
ByteCount blockSize;
Boolean blockReadFromDisk;
Byte isModified; Byte reserved[2];
};
typedef struct BlockDescriptor BlockDescriptor;
typedef BlockDescriptor *BlockDescPtr;
struct FSBufferDescriptor {
void * bufferAddress;
ByteCount itemSize;
ItemCount itemCount;
};
typedef struct FSBufferDescriptor FSBufferDescriptor;
typedef FSBufferDescriptor *FSBufferDescriptorPtr;
enum {
kGetBlock = 0x00000000,
kGetBlockHint = 0x00000001, kForceReadBlock = 0x00000002, kGetEmptyBlock = 0x00000008
};
typedef OptionBits GetBlockOptions;
enum {
kReleaseBlock = 0x00000000,
kForceWriteBlock = 0x00000001,
kMarkBlockDirty = 0x00000002,
kTrashBlock = 0x00000004,
kLockTransaction = 0x00000100
};
typedef OptionBits ReleaseBlockOptions;
typedef u_int64_t FSSize;
typedef u_int32_t ForkBlockNumber;
typedef OSStatus (* GetBlockProcPtr) (FileReference fileRefNum,
u_int32_t blockNum,
GetBlockOptions options,
BlockDescriptor *block );
typedef OSStatus (* ReleaseBlockProcPtr) (FileReference fileRefNum,
BlockDescPtr blockPtr,
ReleaseBlockOptions options );
typedef OSStatus (* SetEndOfForkProcPtr) (FileReference fileRefNum,
FSSize minEOF,
FSSize maxEOF );
typedef OSStatus (* SetBlockSizeProcPtr) (FileReference fileRefNum,
ByteCount blockSize,
ItemCount minBlockCount );
OSStatus SetEndOfForkProc ( FileReference fileRefNum, FSSize minEOF, FSSize maxEOF );
enum BTreeInformationVersion{
kBTreeInfoVersion = 0
};
enum BTreeIterationOperations{
kBTreeFirstRecord,
kBTreeNextRecord,
kBTreePrevRecord,
kBTreeLastRecord,
kBTreeCurrentRecord
};
typedef u_int16_t BTreeIterationOperation;
enum BTreeTypes{
kHFSBTreeType = 0, kUserBTreeType = 128, kReservedBTreeType = 255 };
#define kBTreeHeaderUserBytes 128
typedef BTreeKey *BTreeKeyPtr;
struct BTreeInfoRec{
u_int16_t version;
u_int16_t nodeSize;
u_int16_t maxKeyLength;
u_int16_t treeDepth;
u_int32_t lastfsync;
ItemCount numRecords;
ItemCount numNodes;
ItemCount numFreeNodes;
u_int8_t keyCompareType;
u_int8_t reserved[3];
};
typedef struct BTreeInfoRec BTreeInfoRec;
typedef BTreeInfoRec *BTreeInfoPtr;
struct BTreeHint{
ItemCount writeCount;
u_int32_t nodeNum; u_int16_t index; u_int16_t reserved1;
u_int32_t reserved2;
};
typedef struct BTreeHint BTreeHint;
typedef BTreeHint *BTreeHintPtr;
struct BTreeIterator{
BTreeHint hint;
u_int16_t version;
u_int16_t reserved;
u_int32_t hitCount; u_int32_t maxLeafRecs; BTreeKey key;
};
typedef struct BTreeIterator BTreeIterator;
typedef BTreeIterator *BTreeIteratorPtr;
typedef int32_t (* IterateCallBackProcPtr)(BTreeKeyPtr key, void * record, void * state);
extern OSStatus BTOpenPath(FCB *filePtr, KeyCompareProcPtr keyCompareProc);
extern OSStatus BTClosePath (FCB *filePtr );
extern OSStatus BTSearchRecord (FCB *filePtr,
BTreeIterator *searchIterator,
FSBufferDescriptor *btRecord,
u_int16_t *recordLen,
BTreeIterator *resultIterator );
extern OSStatus BTIterateRecord (FCB *filePtr,
BTreeIterationOperation operation,
BTreeIterator *iterator,
FSBufferDescriptor *btRecord,
u_int16_t *recordLen );
extern OSStatus BTIterateRecords(FCB *filePtr, BTreeIterationOperation operation, BTreeIterator *iterator,
IterateCallBackProcPtr callBackProc, void * callBackState);
extern OSStatus BTInsertRecord (FCB *filePtr,
BTreeIterator *iterator,
FSBufferDescriptor *btrecord,
u_int16_t recordLen );
extern OSStatus BTReplaceRecord (FCB *filePtr,
BTreeIterator *iterator,
FSBufferDescriptor *btRecord,
u_int16_t recordLen );
extern OSStatus BTUpdateRecord (FCB *filePtr,
BTreeIterator *iterator,
IterateCallBackProcPtr callBackProc,
void *callBackState );
extern OSStatus BTDeleteRecord (FCB *filePtr,
BTreeIterator *iterator );
extern OSStatus BTGetInformation (FCB *filePtr,
u_int16_t vers,
BTreeInfoRec *info );
extern OSStatus BTIsDirty(FCB *filePtr);
extern OSStatus BTFlushPath (FCB *filePtr );
extern OSStatus BTReloadData (FCB *filePtr);
extern OSStatus BTInvalidateHint (BTreeIterator *iterator );
extern OSStatus BTGetLastSync (FCB *filePtr,
u_int32_t *lastfsync );
extern OSStatus BTSetLastSync (FCB *filePtr,
u_int32_t lastfsync );
extern OSStatus BTHasContiguousNodes(FCB *filePtr);
extern OSStatus BTGetUserData(FCB *filePtr, void * dataPtr, int dataSize);
extern OSStatus BTSetUserData(FCB *filePtr, void * dataPtr, int dataSize);
extern void BTReserveSetup(void);
extern int BTReserveSpace(FCB *file, int operations, void * data);
extern int BTReleaseReserve(FCB *file, void * data);
extern int BTZeroUnusedNodes(FCB *file);
#endif
#endif
#endif // __BTREESINTERNAL__