#ifndef __BTREESINTERNAL__
#define __BTREESINTERNAL__
#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;
ByteCount blockSize;
Boolean blockReadFromDisk;
Byte reserved[3];
};
typedef struct BlockDescriptor BlockDescriptor;
typedef BlockDescriptor *BlockDescPtr;
struct FSBufferDescriptor {
LogicalAddress bufferAddress;
ByteCount itemSize;
ItemCount itemCount;
};
typedef struct FSBufferDescriptor FSBufferDescriptor;
typedef FSBufferDescriptor *FSBufferDescriptorPtr;
enum {
kGetBlock = 0x00000000,
kForceReadBlock = 0x00000002, kGetEmptyBlock = 0x00000008
};
typedef OptionBits GetBlockOptions;
enum {
kReleaseBlock = 0x00000000,
kForceWriteBlock = 0x00000001,
kMarkBlockDirty = 0x00000002,
kTrashBlock = 0x00000004,
kLockTransaction = 0x00000100
};
typedef OptionBits ReleaseBlockOptions;
typedef UInt32 FSSize;
typedef UInt32 ForkBlockNumber;
typedef OSStatus (* GetBlockProcPtr) (FileReference fileRefNum,
UInt32 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 UInt16 BTreeIterationOperation;
enum BTreeTypes{
kHFSBTreeType = 0, kUserBTreeType = 128, kReservedBTreeType = 255 };
typedef BTreeKey *BTreeKeyPtr;
struct BTreeInfoRec{
UInt16 version;
UInt16 nodeSize;
UInt16 maxKeyLength;
UInt16 treeDepth;
UInt32 lastfsync;
ItemCount numRecords;
ItemCount numNodes;
ItemCount numFreeNodes;
UInt32 reserved;
};
typedef struct BTreeInfoRec BTreeInfoRec;
typedef BTreeInfoRec *BTreeInfoPtr;
struct BTreeHint{
ItemCount writeCount;
UInt32 nodeNum; UInt16 index; UInt16 reserved1;
UInt32 reserved2;
};
typedef struct BTreeHint BTreeHint;
typedef BTreeHint *BTreeHintPtr;
struct BTreeIterator{
BTreeHint hint;
UInt16 version;
UInt16 reserved;
UInt32 hitCount; UInt32 maxLeafRecs; BTreeKey key;
};
typedef struct BTreeIterator BTreeIterator;
typedef BTreeIterator *BTreeIteratorPtr;
typedef SInt32 (* IterateCallBackProcPtr)(BTreeKeyPtr key, void * record, UInt16 recordLen, void * state);
extern OSStatus BTOpenPath (FCB *filePtr,
KeyCompareProcPtr keyCompareProc,
GetBlockProcPtr getBlockProc,
ReleaseBlockProcPtr releaseBlockProc,
SetEndOfForkProcPtr setEndOfForkProc,
SetBlockSizeProcPtr setBlockSizeProc );
extern OSStatus BTClosePath (FCB *filePtr );
extern OSStatus BTSearchRecord (FCB *filePtr,
BTreeIterator *searchIterator,
UInt32 heuristicHint,
FSBufferDescriptor *btRecord,
UInt16 *recordLen,
BTreeIterator *resultIterator );
extern OSStatus BTIterateRecord (FCB *filePtr,
BTreeIterationOperation operation,
BTreeIterator *iterator,
FSBufferDescriptor *btRecord,
UInt16 *recordLen );
extern OSStatus BTIterateRecords(FCB *filePtr, BTreeIterationOperation operation, BTreeIterator *iterator,
IterateCallBackProcPtr callBackProc, void * callBackState);
extern OSStatus BTInsertRecord (FCB *filePtr,
BTreeIterator *iterator,
FSBufferDescriptor *btrecord,
UInt16 recordLen );
extern OSStatus BTReplaceRecord (FCB *filePtr,
BTreeIterator *iterator,
FSBufferDescriptor *btRecord,
UInt16 recordLen );
extern OSStatus BTDeleteRecord (FCB *filePtr,
BTreeIterator *iterator );
extern OSStatus BTGetInformation (FCB *filePtr,
UInt16 version,
BTreeInfoRec *info );
extern OSStatus BTFlushPath (FCB *filePtr );
extern OSStatus BTReloadData (FCB *filePtr);
extern OSStatus BTInvalidateHint (BTreeIterator *iterator );
extern OSStatus BTGetLastSync (FCB *filePtr,
UInt32 *lastfsync );
extern OSStatus BTSetLastSync (FCB *filePtr,
UInt32 lastfsync );
#endif // __BTREESINTERNAL__