2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 File: BTreesInternal.h
26 Contains: IPI to File Manager B-tree
30 Copyright: © 1996-1998 by Apple Computer, Inc., all rights reserved.
33 #ifndef __BTREESINTERNAL__
34 #define __BTREESINTERNAL__
39 // internal error codes
44 fxRangeErr
= 16, // file position beyond mapped range
45 fxOvFlErr
= 17, // extents file overflow
49 uniTooLongErr
= 24, // Unicode string too long to convert to Str31
50 uniBufferTooSmallErr
= 25, // Unicode output buffer too small
51 uniNotMappableErr
= 26, // Unicode string can't be mapped to given script
53 // BTree Manager errors
55 btNotFound
= 32, // record not found
56 btExists
= 33, // record already exists
57 btNoSpaceAvail
= 34, // no available space
58 btNoFit
= 35, // record doesn't fit in node
59 btBadNode
= 36, // bad node detected
60 btBadHdr
= 37, // bad BTree header record detected
61 dsBadRotate
= 64, // bad BTree rotate
63 // Catalog Manager errors
65 cmNotFound
= 48, // CNode not found
66 cmExists
= 49, // CNode already exists
67 cmNotEmpty
= 50, // directory CNode not empty (valence = 0)
68 cmRootCN
= 51, // invalid reference to root CNode
69 cmBadNews
= 52, // detected bad catalog structure
70 cmFThdDirErr
= 53, // thread belongs to a directory not a file
71 cmFThdGone
= 54, // file thread doesn't exist
72 cmParentNotFound
= 55, // CNode for parent ID does not exist
73 cmNotAFolder
= 56, // Destination of move is a file, not a folder
74 cmUnknownNodeType
= 57, // Node type isn't recognized
76 // Volume Check errors
78 vcInvalidExtentErr
= 60 // Extent record is out of bounds
82 fsBTInvalidHeaderErr
= btBadHdr
,
83 fsBTBadRotateErr
= dsBadRotate
,
84 fsBTInvalidNodeErr
= btBadNode
,
85 fsBTRecordTooLargeErr
= btNoFit
,
86 fsBTRecordNotFoundErr
= btNotFound
,
87 fsBTDuplicateRecordErr
= btExists
,
88 fsBTFullErr
= btNoSpaceAvail
,
90 fsBTInvalidFileErr
= 0x0302, /* no BTreeCB has been allocated for fork*/
91 fsBTrFileAlreadyOpenErr
= 0x0303,
92 fsBTInvalidIteratorErr
= 0x0308,
93 fsBTEmptyErr
= 0x030A,
94 fsBTNoMoreMapNodesErr
= 0x030B,
95 fsBTBadNodeSize
= 0x030C,
96 fsBTBadNodeType
= 0x030D,
97 fsBTInvalidKeyLengthErr
= 0x030E,
98 fsBTInvalidKeyDescriptor
= 0x030F,
99 fsBTStartOfIterationErr
= 0x0353,
100 fsBTEndOfIterationErr
= 0x0354,
101 fsBTUnknownVersionErr
= 0x0355,
102 fsBTTreeTooDeepErr
= 0x0357,
103 fsBTInvalidKeyDescriptorErr
= 0x0358,
104 fsBTInvalidKeyFieldErr
= 0x035E,
105 fsBTInvalidKeyAttributeErr
= 0x035F,
106 fsIteratorExitedScopeErr
= 0x0A02, /* iterator exited the scope*/
107 fsIteratorScopeExceptionErr
= 0x0A03, /* iterator is undefined due to error or movement of scope locality*/
108 fsUnknownIteratorMovementErr
= 0x0A04, /* iterator movement is not defined*/
109 fsInvalidIterationMovmentErr
= 0x0A05, /* iterator movement is invalid in current context*/
110 fsClientIDMismatchErr
= 0x0A06, /* wrong client process ID*/
111 fsEndOfIterationErr
= 0x0A07, /* there were no objects left to return on iteration*/
112 fsBTTimeOutErr
= 0x0A08 /* BTree scan interrupted -- no time left for physical I/O */
116 struct FSBufferDescriptor
{
117 LogicalAddress bufferAddress
;
121 typedef struct FSBufferDescriptor FSBufferDescriptor
;
123 typedef FSBufferDescriptor
*FSBufferDescriptorPtr
;
127 typedef UInt64 FSSize
;
128 typedef UInt32 ForkBlockNumber
;
132 BTreeObjID is used to indicate an access path using the
133 BTree access method to a specific fork of a file. This value
134 is session relative and not persistent between invocations of
135 an application. It is in fact an object ID to which requests
136 for the given path should be sent.
138 typedef UInt32 BTreeObjID
;
141 B*Tree Information Version
144 enum BTreeInformationVersion
{
145 kBTreeInfoVersion
= 0
149 B*Tree Iteration Operation Constants
152 enum BTreeIterationOperations
{
159 typedef UInt16 BTreeIterationOperation
;
162 B*Tree Key Descriptor Limits
166 kMaxKeyDescriptorLength
= 23,
170 B*Tree Key Descriptor Field Types
176 kBTreeSignedByte
= 2,
178 kBTreeSignedWord
= 5,
180 kBTreeSignedLong
= 7,
181 kBTreeString
= 3, // Pascal string
182 kBTreeFixLenString
= 8, // Pascal string w/ fixed length buffer
183 kBTreeReserved
= 9, // reserved for Desktop Manager (?)
184 kBTreeUseKeyCmpProc
= 10,
185 //¥¥ not implemented yet...
187 kBTreeFixLenCString
= 12,
188 kBTreeUniCodeString
= 13,
189 kBTreeFixUniCodeString
= 14
191 typedef UInt8 BTreeKeyType
;
195 B*Tree Key Descriptor String Field Attributes
199 kBTreeCaseSens
= 0x10, // case sensitive
200 kBTreeNotDiacSens
= 0x20 // not diacritical sensitive
202 typedef UInt8 BTreeStringAttributes
;
205 Btree types: 0 is HFS CAT/EXT file, 1~127 are AppleShare B*Tree files, 128~254 unused
206 hfsBtreeType EQU 0 ; control file
207 validBTType EQU $80 ; user btree type starts from 128
208 userBT1Type EQU $FF ; 255 is our Btree type. Used by BTInit and BTPatch
212 kHFSBTreeType
= 0, // control file
213 kUserBTreeType
= 128, // user btree type starts from 128
214 kReservedBTreeType
= 255 //
218 kInvalidMRUCacheKey
= -1L /* flag to denote current MRU cache key is invalid*/
222 /*============================================================================
223 B*Tree Key Structures
224 ============================================================================*/
227 BTreeKeyDescriptor is used to indicate how keys for a particular B*Tree
230 typedef char BTreeKeyDescriptor
[26];
231 typedef char *BTreeKeyDescriptorPtr
;
234 BTreeInformation is used to describe the public information about a BTree
236 struct BTreeInformation
{
241 ItemCount NumRecords
;
243 ItemCount NumFreeNodes
;
245 BTreeKeyDescriptor KeyDescriptor
;
247 typedef struct BTreeInformation BTreeInformation
;
248 typedef BTreeInformation
*BTreeInformationPtr
;
250 typedef BTreeKey
*BTreeKeyPtr
;
253 struct KeyDescriptor
{
255 UInt8 fieldDesc
[kMaxKeyDescriptorLength
];
257 typedef struct KeyDescriptor KeyDescriptor
;
258 typedef KeyDescriptor
*KeyDescriptorPtr
;
260 struct NumberFieldDescriptor
{
262 UInt8 occurrence
; // number of consecutive fields of this type
264 typedef struct NumberFieldDescriptor NumberFieldDescriptor
;
266 struct StringFieldDescriptor
{
267 UInt8 fieldType
; // kBTString
268 UInt8 occurrence
; // number of consecutive fields of this type
269 UInt8 stringAttribute
;
272 typedef struct StringFieldDescriptor StringFieldDescriptor
;
274 struct FixedLengthStringFieldDescriptor
{
275 UInt8 fieldType
; // kBTFixLenString
278 UInt8 stringAttribute
;
280 typedef struct FixedLengthStringFieldDescriptor FixedLengthStringFieldDescriptor
;
283 BTreeInfoRec Structure - for BTGetInformation
290 ItemCount numRecords
;
292 ItemCount numFreeNodes
;
293 KeyDescriptorPtr keyDescriptor
;
294 ByteCount keyDescLength
;
297 typedef struct BTreeInfoRec BTreeInfoRec
;
298 typedef BTreeInfoRec
*BTreeInfoPtr
;
301 BTreeHint can never be exported to the outside. Use UInt32 BTreeHint[4],
302 UInt8 BTreeHint[16], etc.
305 ItemCount writeCount
;
306 UInt32 nodeNum
; // node the key was last seen in
307 UInt16 index
; // index then key was last seen at
311 typedef struct BTreeHint BTreeHint
;
312 typedef BTreeHint
*BTreeHintPtr
;
317 struct BTreeIterator
{
323 typedef struct BTreeIterator BTreeIterator
;
324 typedef BTreeIterator
*BTreeIteratorPtr
;
327 /*============================================================================
329 ============================================================================*/
331 typedef SInt32 (* KeyCompareProcPtr
) (BTreeKeyPtr a
, BTreeKeyPtr b
);
333 typedef OSStatus (* GetBlockProcPtr
) (SFCB
*filePtr
,
335 GetBlockOptions options
,
336 BlockDescriptor
*block
);
339 typedef OSStatus (* ReleaseBlockProcPtr
) (SFCB
*filePtr
,
340 BlockDescPtr blockPtr
,
341 ReleaseBlockOptions options
);
343 typedef OSStatus (* SetEndOfForkProcPtr
) (SFCB
*filePtr
,
347 typedef OSStatus (* SetBlockSizeProcPtr
) (SFCB
*filePtr
,
348 ByteCount blockSize
);
350 OSStatus
SetEndOfForkProc ( SFCB
*filePtr
, FSSize minEOF
, FSSize maxEOF
);
354 extern OSStatus
InitBTreeModule (void);
357 extern OSStatus
BTInitialize (SFCB
*filePtrPtr
,
361 KeyDescriptorPtr keyDescPtr
);
363 extern OSStatus
BTOpenPath (SFCB
*filePtr
,
364 KeyCompareProcPtr keyCompareProc
,
365 GetBlockProcPtr getBlockProc
,
366 ReleaseBlockProcPtr releaseBlockProc
,
367 SetEndOfForkProcPtr setEndOfForkProc
,
368 SetBlockSizeProcPtr setBlockSizeProc
);
370 extern OSStatus
BTClosePath (SFCB
*filePtr
);
373 extern OSStatus
BTSearchRecord (SFCB
*filePtr
,
374 BTreeIterator
*searchIterator
,
375 UInt32 heuristicHint
,
376 FSBufferDescriptor
*btRecord
,
378 BTreeIterator
*resultIterator
);
380 extern OSStatus
BTIterateRecord (SFCB
*filePtr
,
381 BTreeIterationOperation operation
,
382 BTreeIterator
*iterator
,
383 FSBufferDescriptor
*btRecord
,
386 extern OSStatus
BTInsertRecord (SFCB
*filePtr
,
387 BTreeIterator
*iterator
,
388 FSBufferDescriptor
*btrecord
,
391 extern OSStatus
BTReplaceRecord (SFCB
*filePtr
,
392 BTreeIterator
*iterator
,
393 FSBufferDescriptor
*btRecord
,
396 extern OSStatus
BTSetRecord (SFCB
*filePtr
,
397 BTreeIterator
*iterator
,
398 FSBufferDescriptor
*btRecord
,
401 extern OSStatus
BTDeleteRecord (SFCB
*filePtr
,
402 BTreeIterator
*iterator
);
404 extern OSStatus
BTGetInformation (SFCB
*filePtr
,
406 BTreeInfoRec
*info
);
408 extern OSStatus
BTFlushPath (SFCB
*filePtr
);
410 extern OSStatus
BTInvalidateHint (BTreeIterator
*iterator
);
412 #endif // __BTREESINTERNAL__