#ifndef __BTREESINTERNAL__
#define __BTREESINTERNAL__
#include "SRuntime.h"
enum {
fxRangeErr = 16, fxOvFlErr = 17,
uniTooLongErr = 24, uniBufferTooSmallErr = 25, uniNotMappableErr = 26,
btNotFound = 32, btExists = 33, btNoSpaceAvail = 34, btNoFit = 35, btBadNode = 36, btBadHdr = 37, dsBadRotate = 64,
cmNotFound = 48, cmExists = 49, cmNotEmpty = 50, cmRootCN = 51, cmBadNews = 52, cmFThdDirErr = 53, cmFThdGone = 54, cmParentNotFound = 55, cmNotAFolder = 56, cmUnknownNodeType = 57,
vcInvalidExtentErr = 60 };
enum {
fsBTInvalidHeaderErr = btBadHdr,
fsBTBadRotateErr = dsBadRotate,
fsBTInvalidNodeErr = btBadNode,
fsBTRecordTooLargeErr = btNoFit,
fsBTRecordNotFoundErr = btNotFound,
fsBTDuplicateRecordErr = btExists,
fsBTFullErr = btNoSpaceAvail,
fsBTInvalidFileErr = 0x0302,
fsBTrFileAlreadyOpenErr = 0x0303,
fsBTInvalidIteratorErr = 0x0308,
fsBTEmptyErr = 0x030A,
fsBTNoMoreMapNodesErr = 0x030B,
fsBTBadNodeSize = 0x030C,
fsBTBadNodeType = 0x030D,
fsBTInvalidKeyLengthErr = 0x030E,
fsBTInvalidKeyDescriptor = 0x030F,
fsBTStartOfIterationErr = 0x0353,
fsBTEndOfIterationErr = 0x0354,
fsBTUnknownVersionErr = 0x0355,
fsBTTreeTooDeepErr = 0x0357,
fsBTInvalidKeyDescriptorErr = 0x0358,
fsBTInvalidKeyFieldErr = 0x035E,
fsBTInvalidKeyAttributeErr = 0x035F,
fsIteratorExitedScopeErr = 0x0A02,
fsIteratorScopeExceptionErr = 0x0A03,
fsUnknownIteratorMovementErr = 0x0A04,
fsInvalidIterationMovmentErr = 0x0A05,
fsClientIDMismatchErr = 0x0A06,
fsEndOfIterationErr = 0x0A07,
fsBTTimeOutErr = 0x0A08
};
struct FSBufferDescriptor {
LogicalAddress bufferAddress;
ByteCount itemSize;
ItemCount itemCount;
};
typedef struct FSBufferDescriptor FSBufferDescriptor;
typedef FSBufferDescriptor *FSBufferDescriptorPtr;
typedef UInt64 FSSize;
typedef UInt32 ForkBlockNumber;
typedef UInt32 BTreeObjID;
enum BTreeInformationVersion{
kBTreeInfoVersion = 0
};
enum BTreeIterationOperations{
kBTreeFirstRecord,
kBTreeNextRecord,
kBTreePrevRecord,
kBTreeLastRecord,
kBTreeCurrentRecord
};
typedef UInt16 BTreeIterationOperation;
enum {
kMaxKeyDescriptorLength = 23,
};
enum {
kBTreeSkip = 0,
kBTreeByte = 1,
kBTreeSignedByte = 2,
kBTreeWord = 4,
kBTreeSignedWord = 5,
kBTreeLong = 6,
kBTreeSignedLong = 7,
kBTreeString = 3, kBTreeFixLenString = 8, kBTreeReserved = 9, kBTreeUseKeyCmpProc = 10,
kBTreeCString = 11,
kBTreeFixLenCString = 12,
kBTreeUniCodeString = 13,
kBTreeFixUniCodeString = 14
};
typedef UInt8 BTreeKeyType;
enum {
kBTreeCaseSens = 0x10, kBTreeNotDiacSens = 0x20 };
typedef UInt8 BTreeStringAttributes;
enum BTreeTypes{
kHFSBTreeType = 0, kUserBTreeType = 128, kReservedBTreeType = 255 };
enum {
kInvalidMRUCacheKey = -1L
};
typedef char BTreeKeyDescriptor[26];
typedef char *BTreeKeyDescriptorPtr;
struct BTreeInformation{
UInt16 NodeSize;
UInt16 MaxKeyLength;
UInt16 Depth;
UInt16 Reserved;
ItemCount NumRecords;
ItemCount NumNodes;
ItemCount NumFreeNodes;
ByteCount ClumpSize;
BTreeKeyDescriptor KeyDescriptor;
};
typedef struct BTreeInformation BTreeInformation;
typedef BTreeInformation *BTreeInformationPtr;
typedef BTreeKey *BTreeKeyPtr;
struct KeyDescriptor{
UInt8 length;
UInt8 fieldDesc [kMaxKeyDescriptorLength];
};
typedef struct KeyDescriptor KeyDescriptor;
typedef KeyDescriptor *KeyDescriptorPtr;
struct NumberFieldDescriptor{
UInt8 fieldType;
UInt8 occurrence; };
typedef struct NumberFieldDescriptor NumberFieldDescriptor;
struct StringFieldDescriptor{
UInt8 fieldType; UInt8 occurrence; UInt8 stringAttribute;
UInt8 filler;
};
typedef struct StringFieldDescriptor StringFieldDescriptor;
struct FixedLengthStringFieldDescriptor{
UInt8 fieldType; UInt8 stringLength;
UInt8 occurrence;
UInt8 stringAttribute;
};
typedef struct FixedLengthStringFieldDescriptor FixedLengthStringFieldDescriptor;
struct BTreeInfoRec{
UInt16 version;
UInt16 nodeSize;
UInt16 maxKeyLength;
UInt16 treeDepth;
ItemCount numRecords;
ItemCount numNodes;
ItemCount numFreeNodes;
KeyDescriptorPtr keyDescriptor;
ByteCount keyDescLength;
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;
BTreeKey key;
};
typedef struct BTreeIterator BTreeIterator;
typedef BTreeIterator *BTreeIteratorPtr;
typedef SInt32 (* KeyCompareProcPtr) (BTreeKeyPtr a, BTreeKeyPtr b);
typedef OSStatus (* GetBlockProcPtr) (SFCB *filePtr,
UInt32 blockNum,
GetBlockOptions options,
BlockDescriptor *block );
typedef OSStatus (* ReleaseBlockProcPtr) (SFCB *filePtr,
BlockDescPtr blockPtr,
ReleaseBlockOptions options );
typedef OSStatus (* SetEndOfForkProcPtr) (SFCB *filePtr,
FSSize minEOF,
FSSize maxEOF );
typedef OSStatus (* SetBlockSizeProcPtr) (SFCB *filePtr,
ByteCount blockSize );
OSStatus SetEndOfForkProc ( SFCB *filePtr, FSSize minEOF, FSSize maxEOF );
extern OSStatus InitBTreeModule (void);
extern OSStatus BTInitialize (SFCB *filePtrPtr,
UInt16 maxKeyLength,
UInt16 nodeSize,
UInt8 btreeType,
KeyDescriptorPtr keyDescPtr );
extern OSStatus BTOpenPath (SFCB *filePtr,
KeyCompareProcPtr keyCompareProc,
GetBlockProcPtr getBlockProc,
ReleaseBlockProcPtr releaseBlockProc,
SetEndOfForkProcPtr setEndOfForkProc,
SetBlockSizeProcPtr setBlockSizeProc );
extern OSStatus BTClosePath (SFCB *filePtr );
extern OSStatus BTSearchRecord (SFCB *filePtr,
BTreeIterator *searchIterator,
UInt32 heuristicHint,
FSBufferDescriptor *btRecord,
UInt16 *recordLen,
BTreeIterator *resultIterator );
extern OSStatus BTIterateRecord (SFCB *filePtr,
BTreeIterationOperation operation,
BTreeIterator *iterator,
FSBufferDescriptor *btRecord,
UInt16 *recordLen );
extern OSStatus BTInsertRecord (SFCB *filePtr,
BTreeIterator *iterator,
FSBufferDescriptor *btrecord,
UInt16 recordLen );
extern OSStatus BTReplaceRecord (SFCB *filePtr,
BTreeIterator *iterator,
FSBufferDescriptor *btRecord,
UInt16 recordLen );
extern OSStatus BTSetRecord (SFCB *filePtr,
BTreeIterator *iterator,
FSBufferDescriptor *btRecord,
UInt16 recordLen );
extern OSStatus BTDeleteRecord (SFCB *filePtr,
BTreeIterator *iterator );
extern OSStatus BTGetInformation (SFCB *filePtr,
UInt16 version,
BTreeInfoRec *info );
extern OSStatus BTFlushPath (SFCB *filePtr );
extern OSStatus BTInvalidateHint (BTreeIterator *iterator );
#endif // __BTREESINTERNAL__