2 * Copyright (c) 1996-2004 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@
26 #ifndef _BTREESCANNER_H_
27 #define _BTREESCANNER_H_
29 #include <sys/appleapiopts.h>
32 #ifdef __APPLE_API_PRIVATE
35 #include "FileMgrInternal.h"
36 #include "BTreesPrivate.h"
38 // amount of time we are allowed to process a catalog search (in ยต secs)
39 // NOTE - code assumes kMaxMicroSecsInKernel is less than 1,000,000
40 enum { kMaxMicroSecsInKernel
= (1000 * 100) }; // 1 tenth of a second
42 // btree node scanner buffer size. at 32K we get 8 nodes. this is the size used
44 enum { kCatSearchBufferSize
= (32 * 1024) };
48 * ============ W A R N I N G ! ============
49 * DO NOT INCREASE THE SIZE OF THIS STRUCT!
50 * It must be less than or equal to the size of
51 * the opaque searchstate struct (in sys/attr.h).
53 /* Private description used in hfs_search */
56 u_int32_t writeCount
; /* The BTree's write count (to see if the catalog writeCount */
57 /* changed since the last search). If 0, the rest */
58 /* of the record is invalid, start from beginning. */
59 u_int32_t nextNode
; /* node number to resume search */
60 u_int32_t nextRecord
; /* record number to resume search */
61 u_int32_t recordsFound
; /* number of leaf records seen so far */
63 typedef struct CatPosition CatPosition
;
67 BTScanState - This structure is used to keep track of the current state
68 of a BTree scan. It contains both the dynamic state information (like
69 the current node number and record number) and information that is static
70 for the duration of a scan (such as buffer pointers).
72 NOTE: recordNum may equal or exceed the number of records in the node
73 number nodeNum. If so, then the next attempt to get a record will move
78 // The following fields are set up once at initialization time.
79 // They are not changed during a scan.
81 struct buf
* bufferPtr
;
82 BTreeControlBlock
* btcb
;
84 // The following fields are the dynamic state of the current scan.
85 u_int32_t nodeNum
; // zero is first node
86 u_int32_t recordNum
; // zero is first record
87 BTNodeDescriptor
* currentNodePtr
; // points to current node within buffer
88 u_int32_t nodesLeftInBuffer
; // number of valid nodes still in the buffer
89 u_int32_t recordsFound
; // number of leaf records seen so far
90 struct timeval startTime
; // time we started catalog search
92 typedef struct BTScanState BTScanState
;
95 /* *********************** PROTOTYPES *********************** */
97 int BTScanInitialize( const FCB
* btreeFile
,
98 u_int32_t startingNode
,
99 u_int32_t startingRecord
,
100 u_int32_t recordsFound
,
101 u_int32_t bufferSize
,
102 BTScanState
* scanState
);
104 int BTScanNextRecord( BTScanState
* scanState
,
108 u_int32_t
* dataSize
);
110 int BTScanTerminate( BTScanState
* scanState
,
111 u_int32_t
* startingNode
,
112 u_int32_t
* startingRecord
,
113 u_int32_t
* recordsFound
);
115 #endif /* __APPLE_API_PRIVATE */
117 #endif /* !_BTREESCANNER_H_ */