]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfscommon/headers/BTreesInternal.h
xnu-344.49.tar.gz
[apple/xnu.git] / bsd / hfs / hfscommon / headers / BTreesInternal.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 File: BTreesInternal.h
27
28 Contains: IPI to File Manager B-tree
29
30 Version: HFS Plus 1.0
31
32 Copyright: © 1996-1998 by Apple Computer, Inc., all rights reserved.
33
34 File Ownership:
35
36 DRI: Don Brady
37
38 Other Contact: Mark Day
39
40 Technology: File Systems
41
42 Writers:
43
44 (msd) Mark Day
45 (DSH) Deric Horn
46 (djb) Don Brady
47
48 Change History (most recent first):
49
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).
52
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
58 collision
59 <CS3> 6/2/97 DSH Added SetEndOfForkProc() prototype, so Attributes.c can call it
60 directly.
61 <CS2> 5/19/97 djb kMaxKeyLength is now 520.
62 <CS1> 4/28/97 djb first checked in
63
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
71
72 */
73
74 #ifndef __BTREESINTERNAL__
75 #define __BTREESINTERNAL__
76
77 #include <sys/appleapiopts.h>
78
79 #ifdef KERNEL
80 #ifdef __APPLE_API_PRIVATE
81
82 #ifndef __FILEMGRINTERNAL__
83 #include "FileMgrInternal.h"
84 #endif
85
86 enum {
87 fsBTInvalidHeaderErr = btBadHdr,
88 fsBTBadRotateErr = dsBadRotate,
89 fsBTInvalidNodeErr = btBadNode,
90 fsBTRecordTooLargeErr = btNoFit,
91 fsBTRecordNotFoundErr = btNotFound,
92 fsBTDuplicateRecordErr = btExists,
93 fsBTFullErr = btNoSpaceAvail,
94
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 */
114 };
115
116 struct BlockDescriptor{
117 void *buffer;
118 void *blockHeader;
119 ByteCount blockSize;
120 Boolean blockReadFromDisk;
121 Byte isModified; // XXXdbg - for journaling
122 Byte reserved[2];
123 };
124 typedef struct BlockDescriptor BlockDescriptor;
125 typedef BlockDescriptor *BlockDescPtr;
126
127
128 struct FSBufferDescriptor {
129 void * bufferAddress;
130 ByteCount itemSize;
131 ItemCount itemCount;
132 };
133 typedef struct FSBufferDescriptor FSBufferDescriptor;
134
135 typedef FSBufferDescriptor *FSBufferDescriptorPtr;
136
137
138 /*
139 Fork Level Access Method Block get options
140 */
141 enum {
142 kGetBlock = 0x00000000,
143 kForceReadBlock = 0x00000002, //\80\80 how does this relate to Read/Verify? Do we need this?
144 kGetEmptyBlock = 0x00000008
145 };
146 typedef OptionBits GetBlockOptions;
147
148 /*
149 Fork Level Access Method Block release options
150 */
151 enum {
152 kReleaseBlock = 0x00000000,
153 kForceWriteBlock = 0x00000001,
154 kMarkBlockDirty = 0x00000002,
155 kTrashBlock = 0x00000004,
156 kLockTransaction = 0x00000100
157 };
158 typedef OptionBits ReleaseBlockOptions;
159
160 typedef UInt64 FSSize;
161 typedef UInt32 ForkBlockNumber;
162
163 /*============================================================================
164 Fork Level Buffered I/O Access Method
165 ============================================================================*/
166
167 typedef OSStatus (* GetBlockProcPtr) (FileReference fileRefNum,
168 UInt32 blockNum,
169 GetBlockOptions options,
170 BlockDescriptor *block );
171
172
173 typedef OSStatus (* ReleaseBlockProcPtr) (FileReference fileRefNum,
174 BlockDescPtr blockPtr,
175 ReleaseBlockOptions options );
176
177 typedef OSStatus (* SetEndOfForkProcPtr) (FileReference fileRefNum,
178 FSSize minEOF,
179 FSSize maxEOF );
180
181 typedef OSStatus (* SetBlockSizeProcPtr) (FileReference fileRefNum,
182 ByteCount blockSize,
183 ItemCount minBlockCount );
184
185 OSStatus SetEndOfForkProc ( FileReference fileRefNum, FSSize minEOF, FSSize maxEOF );
186
187
188 /*
189 B*Tree Information Version
190 */
191
192 enum BTreeInformationVersion{
193 kBTreeInfoVersion = 0
194 };
195
196 /*
197 B*Tree Iteration Operation Constants
198 */
199
200 enum BTreeIterationOperations{
201 kBTreeFirstRecord,
202 kBTreeNextRecord,
203 kBTreePrevRecord,
204 kBTreeLastRecord,
205 kBTreeCurrentRecord
206 };
207 typedef UInt16 BTreeIterationOperation;
208
209
210 /*
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
215 */
216
217 enum BTreeTypes{
218 kHFSBTreeType = 0, // control file
219 kUserBTreeType = 128, // user btree type starts from 128
220 kReservedBTreeType = 255 //
221 };
222
223
224 typedef BTreeKey *BTreeKeyPtr;
225
226
227 /*
228 BTreeInfoRec Structure - for BTGetInformation
229 */
230 struct BTreeInfoRec{
231 UInt16 version;
232 UInt16 nodeSize;
233 UInt16 maxKeyLength;
234 UInt16 treeDepth;
235 UInt32 lastfsync; /* Last time that this was fsynced */
236 ItemCount numRecords;
237 ItemCount numNodes;
238 ItemCount numFreeNodes;
239 UInt32 reserved;
240 };
241 typedef struct BTreeInfoRec BTreeInfoRec;
242 typedef BTreeInfoRec *BTreeInfoPtr;
243
244 /*
245 BTreeHint can never be exported to the outside. Use UInt32 BTreeHint[4],
246 UInt8 BTreeHint[16], etc.
247 */
248 struct BTreeHint{
249 ItemCount writeCount;
250 UInt32 nodeNum; // node the key was last seen in
251 UInt16 index; // index then key was last seen at
252 UInt16 reserved1;
253 UInt32 reserved2;
254 };
255 typedef struct BTreeHint BTreeHint;
256 typedef BTreeHint *BTreeHintPtr;
257
258 /*
259 BTree Iterator
260 */
261 struct BTreeIterator{
262 BTreeHint hint;
263 UInt16 version;
264 UInt16 reserved;
265 UInt32 hitCount; // Total number of leaf records hit
266 UInt32 maxLeafRecs; // Max leaf records over iteration
267 BTreeKey key;
268 };
269 typedef struct BTreeIterator BTreeIterator;
270 typedef BTreeIterator *BTreeIteratorPtr;
271
272
273 /*============================================================================
274 B*Tree SPI
275 ============================================================================*/
276
277 /*
278 Key Comparison Function ProcPtr Type - for BTOpenPath
279 */
280 //typedef SInt32 (* KeyCompareProcPtr)(BTreeKeyPtr a, BTreeKeyPtr b);
281
282
283 typedef SInt32 (* IterateCallBackProcPtr)(BTreeKeyPtr key, void * record, UInt16 recordLen, void * state);
284
285 extern OSStatus BTOpenPath (FCB *filePtr,
286 KeyCompareProcPtr keyCompareProc,
287 GetBlockProcPtr getBlockProc,
288 ReleaseBlockProcPtr releaseBlockProc,
289 SetEndOfForkProcPtr setEndOfForkProc,
290 SetBlockSizeProcPtr setBlockSizeProc );
291
292 extern OSStatus BTClosePath (FCB *filePtr );
293
294
295 extern OSStatus BTSearchRecord (FCB *filePtr,
296 BTreeIterator *searchIterator,
297 FSBufferDescriptor *btRecord,
298 UInt16 *recordLen,
299 BTreeIterator *resultIterator );
300
301 extern OSStatus BTIterateRecord (FCB *filePtr,
302 BTreeIterationOperation operation,
303 BTreeIterator *iterator,
304 FSBufferDescriptor *btRecord,
305 UInt16 *recordLen );
306
307
308 extern OSStatus BTIterateRecords(FCB *filePtr, BTreeIterationOperation operation, BTreeIterator *iterator,
309 IterateCallBackProcPtr callBackProc, void * callBackState);
310
311 extern OSStatus BTInsertRecord (FCB *filePtr,
312 BTreeIterator *iterator,
313 FSBufferDescriptor *btrecord,
314 UInt16 recordLen );
315
316 extern OSStatus BTReplaceRecord (FCB *filePtr,
317 BTreeIterator *iterator,
318 FSBufferDescriptor *btRecord,
319 UInt16 recordLen );
320
321 extern OSStatus BTUpdateRecord (FCB *filePtr,
322 BTreeIterator *iterator,
323 IterateCallBackProcPtr callBackProc,
324 void *callBackState );
325
326 extern OSStatus BTDeleteRecord (FCB *filePtr,
327 BTreeIterator *iterator );
328
329 extern OSStatus BTGetInformation (FCB *filePtr,
330 UInt16 version,
331 BTreeInfoRec *info );
332
333 extern OSStatus BTFlushPath (FCB *filePtr );
334
335 extern OSStatus BTReloadData (FCB *filePtr);
336
337 extern OSStatus BTInvalidateHint (BTreeIterator *iterator );
338
339 extern OSStatus BTGetLastSync (FCB *filePtr,
340 UInt32 *lastfsync );
341
342 extern OSStatus BTSetLastSync (FCB *filePtr,
343 UInt32 lastfsync );
344
345 extern OSStatus BTCheckFreeSpace (FCB *filePtr);
346
347 extern OSStatus BTHasContiguousNodes(FCB *filePtr);
348
349 #endif /* __APPLE_API_PRIVATE */
350 #endif /* KERNEL */
351 #endif // __BTREESINTERNAL__