2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 File: BTreesInternal.h
25 Contains: IPI to File Manager B-tree
29 Copyright: © 1996-1998 by Apple Computer, Inc., all rights reserved.
35 Other Contact: Mark Day
37 Technology: File Systems
45 Change History (most recent first):
47 <RHAP> 9/22/99 ser Added prototypes for BTGetLastSync and BTSetLastSync
48 <RHAP> 6/22/98 djb Add ERR_BASE to btree error codes to make them negative (for MacOS X only).
50 <CS7> 7/28/97 msd Add enum for fsBTTimeOutErr.
51 <CS6> 7/25/97 DSH Added heuristicHint as parameter to BTSearchRecord.
52 <CS5> 7/24/97 djb Add blockReadFromDisk flag to BlockDescriptor. Callbacks now use
53 a file refNum instead of an FCB.
54 <CS4> 7/16/97 DSH FilesInternal.i renamed FileMgrInternal.i to avoid name
56 <CS3> 6/2/97 DSH Added SetEndOfForkProc() prototype, so Attributes.c can call it
58 <CS2> 5/19/97 djb kMaxKeyLength is now 520.
59 <CS1> 4/28/97 djb first checked in
61 <HFS6> 3/17/97 DSH Remove Key Comparison prototype, already in FilesInternal.h.
62 <HFS5> 2/19/97 djb Add SetBlockSizeProcPtr. Add blockSize field to BlockDescriptor.
63 Remove E_ type error enums.
64 <HFS4> 1/27/97 djb Include Types.h and FilesInternal.h.
65 <HFS3> 1/13/97 djb Added kBTreeCurrentRecord for BTIterateRecord.
66 <HFS2> 1/3/97 djb Added support for large keys.
67 <HFS1> 12/19/96 djb first checked in
71 #ifndef __BTREESINTERNAL__
72 #define __BTREESINTERNAL__
74 #ifndef __FILEMGRINTERNAL__
75 #include "FileMgrInternal.h"
79 fsBTInvalidHeaderErr
= btBadHdr
,
80 fsBTBadRotateErr
= dsBadRotate
,
81 fsBTInvalidNodeErr
= btBadNode
,
82 fsBTRecordTooLargeErr
= btNoFit
,
83 fsBTRecordNotFoundErr
= btNotFound
,
84 fsBTDuplicateRecordErr
= btExists
,
85 fsBTFullErr
= btNoSpaceAvail
,
87 fsBTInvalidFileErr
= ERR_BASE
+ 0x0302, /* no BTreeCB has been allocated for fork*/
88 fsBTrFileAlreadyOpenErr
= ERR_BASE
+ 0x0303,
89 fsBTInvalidIteratorErr
= ERR_BASE
+ 0x0308,
90 fsBTEmptyErr
= ERR_BASE
+ 0x030A,
91 fsBTNoMoreMapNodesErr
= ERR_BASE
+ 0x030B,
92 fsBTBadNodeSize
= ERR_BASE
+ 0x030C,
93 fsBTBadNodeType
= ERR_BASE
+ 0x030D,
94 fsBTInvalidKeyLengthErr
= ERR_BASE
+ 0x030E,
95 fsBTStartOfIterationErr
= ERR_BASE
+ 0x0353,
96 fsBTEndOfIterationErr
= ERR_BASE
+ 0x0354,
97 fsBTUnknownVersionErr
= ERR_BASE
+ 0x0355,
98 fsBTTreeTooDeepErr
= ERR_BASE
+ 0x0357,
99 fsIteratorExitedScopeErr
= ERR_BASE
+ 0x0A02, /* iterator exited the scope*/
100 fsIteratorScopeExceptionErr
= ERR_BASE
+ 0x0A03, /* iterator is undefined due to error or movement of scope locality*/
101 fsUnknownIteratorMovementErr
= ERR_BASE
+ 0x0A04, /* iterator movement is not defined*/
102 fsInvalidIterationMovmentErr
= ERR_BASE
+ 0x0A05, /* iterator movement is invalid in current context*/
103 fsClientIDMismatchErr
= ERR_BASE
+ 0x0A06, /* wrong client process ID*/
104 fsEndOfIterationErr
= ERR_BASE
+ 0x0A07, /* there were no objects left to return on iteration*/
105 fsBTTimeOutErr
= ERR_BASE
+ 0x0A08 /* BTree scan interrupted -- no time left for physical I/O */
108 struct BlockDescriptor
{
112 Boolean blockReadFromDisk
;
115 typedef struct BlockDescriptor BlockDescriptor
;
116 typedef BlockDescriptor
*BlockDescPtr
;
119 struct FSBufferDescriptor
{
120 LogicalAddress bufferAddress
;
124 typedef struct FSBufferDescriptor FSBufferDescriptor
;
126 typedef FSBufferDescriptor
*FSBufferDescriptorPtr
;
130 Fork Level Access Method Block get options
133 kGetBlock
= 0x00000000,
134 kForceReadBlock
= 0x00000002, //\80\80 how does this relate to Read/Verify? Do we need this?
135 kGetEmptyBlock
= 0x00000008
137 typedef OptionBits GetBlockOptions
;
140 Fork Level Access Method Block release options
143 kReleaseBlock
= 0x00000000,
144 kForceWriteBlock
= 0x00000001,
145 kMarkBlockDirty
= 0x00000002,
146 kTrashBlock
= 0x00000004,
147 kLockTransaction
= 0x00000100
149 typedef OptionBits ReleaseBlockOptions
;
151 typedef UInt32 FSSize
;
152 typedef UInt32 ForkBlockNumber
;
154 /*============================================================================
155 Fork Level Buffered I/O Access Method
156 ============================================================================*/
158 typedef OSStatus (* GetBlockProcPtr
) (FileReference fileRefNum
,
160 GetBlockOptions options
,
161 BlockDescriptor
*block
);
164 typedef OSStatus (* ReleaseBlockProcPtr
) (FileReference fileRefNum
,
165 BlockDescPtr blockPtr
,
166 ReleaseBlockOptions options
);
168 typedef OSStatus (* SetEndOfForkProcPtr
) (FileReference fileRefNum
,
172 typedef OSStatus (* SetBlockSizeProcPtr
) (FileReference fileRefNum
,
174 ItemCount minBlockCount
);
176 OSStatus
SetEndOfForkProc ( FileReference fileRefNum
, FSSize minEOF
, FSSize maxEOF
);
180 B*Tree Information Version
183 enum BTreeInformationVersion
{
184 kBTreeInfoVersion
= 0
188 B*Tree Iteration Operation Constants
191 enum BTreeIterationOperations
{
198 typedef UInt16 BTreeIterationOperation
;
202 Btree types: 0 is HFS CAT/EXT file, 1~127 are AppleShare B*Tree files, 128~254 unused
203 hfsBtreeType EQU 0 ; control file
204 validBTType EQU $80 ; user btree type starts from 128
205 userBT1Type EQU $FF ; 255 is our Btree type. Used by BTInit and BTPatch
209 kHFSBTreeType
= 0, // control file
210 kUserBTreeType
= 128, // user btree type starts from 128
211 kReservedBTreeType
= 255 //
215 typedef BTreeKey
*BTreeKeyPtr
;
219 BTreeInfoRec Structure - for BTGetInformation
226 UInt32 lastfsync
; /* Last time that this was fsynced */
227 ItemCount numRecords
;
229 ItemCount numFreeNodes
;
232 typedef struct BTreeInfoRec BTreeInfoRec
;
233 typedef BTreeInfoRec
*BTreeInfoPtr
;
236 BTreeHint can never be exported to the outside. Use UInt32 BTreeHint[4],
237 UInt8 BTreeHint[16], etc.
240 ItemCount writeCount
;
241 UInt32 nodeNum
; // node the key was last seen in
242 UInt16 index
; // index then key was last seen at
246 typedef struct BTreeHint BTreeHint
;
247 typedef BTreeHint
*BTreeHintPtr
;
252 struct BTreeIterator
{
256 UInt32 hitCount
; // Total number of leaf records hit
257 UInt32 maxLeafRecs
; // Max leaf records over iteration
260 typedef struct BTreeIterator BTreeIterator
;
261 typedef BTreeIterator
*BTreeIteratorPtr
;
264 /*============================================================================
266 ============================================================================*/
269 Key Comparison Function ProcPtr Type - for BTOpenPath
271 //typedef SInt32 (* KeyCompareProcPtr)(BTreeKeyPtr a, BTreeKeyPtr b);
274 typedef SInt32 (* IterateCallBackProcPtr
)(BTreeKeyPtr key
, void * record
, UInt16 recordLen
, void * state
);
276 extern OSStatus
BTOpenPath (FCB
*filePtr
,
277 KeyCompareProcPtr keyCompareProc
,
278 GetBlockProcPtr getBlockProc
,
279 ReleaseBlockProcPtr releaseBlockProc
,
280 SetEndOfForkProcPtr setEndOfForkProc
,
281 SetBlockSizeProcPtr setBlockSizeProc
);
283 extern OSStatus
BTClosePath (FCB
*filePtr
);
286 extern OSStatus
BTSearchRecord (FCB
*filePtr
,
287 BTreeIterator
*searchIterator
,
288 UInt32 heuristicHint
,
289 FSBufferDescriptor
*btRecord
,
291 BTreeIterator
*resultIterator
);
293 extern OSStatus
BTIterateRecord (FCB
*filePtr
,
294 BTreeIterationOperation operation
,
295 BTreeIterator
*iterator
,
296 FSBufferDescriptor
*btRecord
,
300 extern OSStatus
BTIterateRecords(FCB
*filePtr
, BTreeIterationOperation operation
, BTreeIterator
*iterator
,
301 IterateCallBackProcPtr callBackProc
, void * callBackState
);
303 extern OSStatus
BTInsertRecord (FCB
*filePtr
,
304 BTreeIterator
*iterator
,
305 FSBufferDescriptor
*btrecord
,
308 extern OSStatus
BTReplaceRecord (FCB
*filePtr
,
309 BTreeIterator
*iterator
,
310 FSBufferDescriptor
*btRecord
,
314 extern OSStatus
BTDeleteRecord (FCB
*filePtr
,
315 BTreeIterator
*iterator
);
317 extern OSStatus
BTGetInformation (FCB
*filePtr
,
319 BTreeInfoRec
*info
);
321 extern OSStatus
BTFlushPath (FCB
*filePtr
);
323 extern OSStatus
BTReloadData (FCB
*filePtr
);
325 extern OSStatus
BTInvalidateHint (BTreeIterator
*iterator
);
327 extern OSStatus
BTGetLastSync (FCB
*filePtr
,
330 extern OSStatus
BTSetLastSync (FCB
*filePtr
,
333 #endif // __BTREESINTERNAL__