2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 File: BTreesInternal.h
28 Contains: IPI to File Manager B-tree
32 Copyright: © 1996-1998 by Apple Computer, Inc., all rights reserved.
38 Other Contact: Mark Day
40 Technology: File Systems
48 Change History (most recent first):
50 <RHAP> 9/22/99 ser Added prototypes for BTGetLastSync and BTSetLastSync
51 <RHAP> 6/22/98 djb Add ERR_BASE to btree error codes to make them negative (for MacOS X only).
53 <CS7> 7/28/97 msd Add enum for fsBTTimeOutErr.
54 <CS6> 7/25/97 DSH Added heuristicHint as parameter to BTSearchRecord.
55 <CS5> 7/24/97 djb Add blockReadFromDisk flag to BlockDescriptor. Callbacks now use
56 a file refNum instead of an FCB.
57 <CS4> 7/16/97 DSH FilesInternal.i renamed FileMgrInternal.i to avoid name
59 <CS3> 6/2/97 DSH Added SetEndOfForkProc() prototype, so Attributes.c can call it
61 <CS2> 5/19/97 djb kMaxKeyLength is now 520.
62 <CS1> 4/28/97 djb first checked in
64 <HFS6> 3/17/97 DSH Remove Key Comparison prototype, already in FilesInternal.h.
65 <HFS5> 2/19/97 djb Add SetBlockSizeProcPtr. Add blockSize field to BlockDescriptor.
66 Remove E_ type error enums.
67 <HFS4> 1/27/97 djb Include Types.h and FilesInternal.h.
68 <HFS3> 1/13/97 djb Added kBTreeCurrentRecord for BTIterateRecord.
69 <HFS2> 1/3/97 djb Added support for large keys.
70 <HFS1> 12/19/96 djb first checked in
74 #ifndef __BTREESINTERNAL__
75 #define __BTREESINTERNAL__
77 #include <sys/appleapiopts.h>
80 #ifdef __APPLE_API_PRIVATE
82 #ifndef __FILEMGRINTERNAL__
83 #include "FileMgrInternal.h"
87 fsBTInvalidHeaderErr
= btBadHdr
,
88 fsBTBadRotateErr
= dsBadRotate
,
89 fsBTInvalidNodeErr
= btBadNode
,
90 fsBTRecordTooLargeErr
= btNoFit
,
91 fsBTRecordNotFoundErr
= btNotFound
,
92 fsBTDuplicateRecordErr
= btExists
,
93 fsBTFullErr
= btNoSpaceAvail
,
95 fsBTInvalidFileErr
= ERR_BASE
+ 0x0302, /* no BTreeCB has been allocated for fork*/
96 fsBTrFileAlreadyOpenErr
= ERR_BASE
+ 0x0303,
97 fsBTInvalidIteratorErr
= ERR_BASE
+ 0x0308,
98 fsBTEmptyErr
= ERR_BASE
+ 0x030A,
99 fsBTNoMoreMapNodesErr
= ERR_BASE
+ 0x030B,
100 fsBTBadNodeSize
= ERR_BASE
+ 0x030C,
101 fsBTBadNodeType
= ERR_BASE
+ 0x030D,
102 fsBTInvalidKeyLengthErr
= ERR_BASE
+ 0x030E,
103 fsBTStartOfIterationErr
= ERR_BASE
+ 0x0353,
104 fsBTEndOfIterationErr
= ERR_BASE
+ 0x0354,
105 fsBTUnknownVersionErr
= ERR_BASE
+ 0x0355,
106 fsBTTreeTooDeepErr
= ERR_BASE
+ 0x0357,
107 fsIteratorExitedScopeErr
= ERR_BASE
+ 0x0A02, /* iterator exited the scope*/
108 fsIteratorScopeExceptionErr
= ERR_BASE
+ 0x0A03, /* iterator is undefined due to error or movement of scope locality*/
109 fsUnknownIteratorMovementErr
= ERR_BASE
+ 0x0A04, /* iterator movement is not defined*/
110 fsInvalidIterationMovmentErr
= ERR_BASE
+ 0x0A05, /* iterator movement is invalid in current context*/
111 fsClientIDMismatchErr
= ERR_BASE
+ 0x0A06, /* wrong client process ID*/
112 fsEndOfIterationErr
= ERR_BASE
+ 0x0A07, /* there were no objects left to return on iteration*/
113 fsBTTimeOutErr
= ERR_BASE
+ 0x0A08 /* BTree scan interrupted -- no time left for physical I/O */
116 struct BlockDescriptor
{
120 Boolean blockReadFromDisk
;
121 Byte isModified
; // XXXdbg - for journaling
124 typedef struct BlockDescriptor BlockDescriptor
;
125 typedef BlockDescriptor
*BlockDescPtr
;
128 struct FSBufferDescriptor
{
129 void * bufferAddress
;
133 typedef struct FSBufferDescriptor FSBufferDescriptor
;
135 typedef FSBufferDescriptor
*FSBufferDescriptorPtr
;
139 Fork Level Access Method Block get options
142 kGetBlock
= 0x00000000,
143 kForceReadBlock
= 0x00000002, //\80\80 how does this relate to Read/Verify? Do we need this?
144 kGetEmptyBlock
= 0x00000008
146 typedef OptionBits GetBlockOptions
;
149 Fork Level Access Method Block release options
152 kReleaseBlock
= 0x00000000,
153 kForceWriteBlock
= 0x00000001,
154 kMarkBlockDirty
= 0x00000002,
155 kTrashBlock
= 0x00000004,
156 kLockTransaction
= 0x00000100
158 typedef OptionBits ReleaseBlockOptions
;
160 typedef UInt64 FSSize
;
161 typedef UInt32 ForkBlockNumber
;
163 /*============================================================================
164 Fork Level Buffered I/O Access Method
165 ============================================================================*/
167 typedef OSStatus (* GetBlockProcPtr
) (FileReference fileRefNum
,
169 GetBlockOptions options
,
170 BlockDescriptor
*block
);
173 typedef OSStatus (* ReleaseBlockProcPtr
) (FileReference fileRefNum
,
174 BlockDescPtr blockPtr
,
175 ReleaseBlockOptions options
);
177 typedef OSStatus (* SetEndOfForkProcPtr
) (FileReference fileRefNum
,
181 typedef OSStatus (* SetBlockSizeProcPtr
) (FileReference fileRefNum
,
183 ItemCount minBlockCount
);
185 OSStatus
SetEndOfForkProc ( FileReference fileRefNum
, FSSize minEOF
, FSSize maxEOF
);
189 B*Tree Information Version
192 enum BTreeInformationVersion
{
193 kBTreeInfoVersion
= 0
197 B*Tree Iteration Operation Constants
200 enum BTreeIterationOperations
{
207 typedef UInt16 BTreeIterationOperation
;
211 Btree types: 0 is HFS CAT/EXT file, 1~127 are AppleShare B*Tree files, 128~254 unused
212 hfsBtreeType EQU 0 ; control file
213 validBTType EQU $80 ; user btree type starts from 128
214 userBT1Type EQU $FF ; 255 is our Btree type. Used by BTInit and BTPatch
218 kHFSBTreeType
= 0, // control file
219 kUserBTreeType
= 128, // user btree type starts from 128
220 kReservedBTreeType
= 255 //
224 typedef BTreeKey
*BTreeKeyPtr
;
228 BTreeInfoRec Structure - for BTGetInformation
235 UInt32 lastfsync
; /* Last time that this was fsynced */
236 ItemCount numRecords
;
238 ItemCount numFreeNodes
;
241 typedef struct BTreeInfoRec BTreeInfoRec
;
242 typedef BTreeInfoRec
*BTreeInfoPtr
;
245 BTreeHint can never be exported to the outside. Use UInt32 BTreeHint[4],
246 UInt8 BTreeHint[16], etc.
249 ItemCount writeCount
;
250 UInt32 nodeNum
; // node the key was last seen in
251 UInt16 index
; // index then key was last seen at
255 typedef struct BTreeHint BTreeHint
;
256 typedef BTreeHint
*BTreeHintPtr
;
261 struct BTreeIterator
{
265 UInt32 hitCount
; // Total number of leaf records hit
266 UInt32 maxLeafRecs
; // Max leaf records over iteration
269 typedef struct BTreeIterator BTreeIterator
;
270 typedef BTreeIterator
*BTreeIteratorPtr
;
273 /*============================================================================
275 ============================================================================*/
278 Key Comparison Function ProcPtr Type - for BTOpenPath
280 //typedef SInt32 (* KeyCompareProcPtr)(BTreeKeyPtr a, BTreeKeyPtr b);
283 typedef SInt32 (* IterateCallBackProcPtr
)(BTreeKeyPtr key
, void * record
, UInt16 recordLen
, void * state
);
285 extern OSStatus
BTOpenPath (FCB
*filePtr
,
286 KeyCompareProcPtr keyCompareProc
,
287 GetBlockProcPtr getBlockProc
,
288 ReleaseBlockProcPtr releaseBlockProc
,
289 SetEndOfForkProcPtr setEndOfForkProc
,
290 SetBlockSizeProcPtr setBlockSizeProc
);
292 extern OSStatus
BTClosePath (FCB
*filePtr
);
295 extern OSStatus
BTSearchRecord (FCB
*filePtr
,
296 BTreeIterator
*searchIterator
,
297 FSBufferDescriptor
*btRecord
,
299 BTreeIterator
*resultIterator
);
301 extern OSStatus
BTIterateRecord (FCB
*filePtr
,
302 BTreeIterationOperation operation
,
303 BTreeIterator
*iterator
,
304 FSBufferDescriptor
*btRecord
,
308 extern OSStatus
BTIterateRecords(FCB
*filePtr
, BTreeIterationOperation operation
, BTreeIterator
*iterator
,
309 IterateCallBackProcPtr callBackProc
, void * callBackState
);
311 extern OSStatus
BTInsertRecord (FCB
*filePtr
,
312 BTreeIterator
*iterator
,
313 FSBufferDescriptor
*btrecord
,
316 extern OSStatus
BTReplaceRecord (FCB
*filePtr
,
317 BTreeIterator
*iterator
,
318 FSBufferDescriptor
*btRecord
,
321 extern OSStatus
BTUpdateRecord (FCB
*filePtr
,
322 BTreeIterator
*iterator
,
323 IterateCallBackProcPtr callBackProc
,
324 void *callBackState
);
326 extern OSStatus
BTDeleteRecord (FCB
*filePtr
,
327 BTreeIterator
*iterator
);
329 extern OSStatus
BTGetInformation (FCB
*filePtr
,
331 BTreeInfoRec
*info
);
333 extern OSStatus
BTFlushPath (FCB
*filePtr
);
335 extern OSStatus
BTReloadData (FCB
*filePtr
);
337 extern OSStatus
BTInvalidateHint (BTreeIterator
*iterator
);
339 extern OSStatus
BTGetLastSync (FCB
*filePtr
,
342 extern OSStatus
BTSetLastSync (FCB
*filePtr
,
345 extern OSStatus
BTCheckFreeSpace (FCB
*filePtr
);
347 extern OSStatus
BTHasContiguousNodes(FCB
*filePtr
);
349 #endif /* __APPLE_API_PRIVATE */
351 #endif // __BTREESINTERNAL__