2 * Copyright (c) 1996-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
33 #ifndef _BTREESCANNER_H_
34 #define _BTREESCANNER_H_
36 #include <sys/appleapiopts.h>
39 #ifdef __APPLE_API_PRIVATE
42 #include "FileMgrInternal.h"
43 #include "BTreesPrivate.h"
45 // amount of time we are allowed to process a catalog search (in ยต secs)
46 // NOTE - code assumes kMaxMicroSecsInKernel is less than 1,000,000
47 enum { kMaxMicroSecsInKernel
= (1000 * 100) }; // 1 tenth of a second
49 // btree node scanner buffer size. at 32K we get 8 nodes. this is the size used
51 enum { kCatSearchBufferSize
= (32 * 1024) };
55 * ============ W A R N I N G ! ============
56 * DO NOT INCREASE THE SIZE OF THIS STRUCT!
57 * It must be less than or equal to the size of
58 * the opaque searchstate struct (in sys/attr.h).
60 /* Private description used in hfs_search */
63 u_int32_t writeCount
; /* The BTree's write count (to see if the catalog writeCount */
64 /* changed since the last search). If 0, the rest */
65 /* of the record is invalid, start from beginning. */
66 u_int32_t nextNode
; /* node number to resume search */
67 u_int32_t nextRecord
; /* record number to resume search */
68 u_int32_t recordsFound
; /* number of leaf records seen so far */
70 typedef struct CatPosition CatPosition
;
74 BTScanState - This structure is used to keep track of the current state
75 of a BTree scan. It contains both the dynamic state information (like
76 the current node number and record number) and information that is static
77 for the duration of a scan (such as buffer pointers).
79 NOTE: recordNum may equal or exceed the number of records in the node
80 number nodeNum. If so, then the next attempt to get a record will move
85 // The following fields are set up once at initialization time.
86 // They are not changed during a scan.
88 struct buf
* bufferPtr
;
89 BTreeControlBlock
* btcb
;
91 // The following fields are the dynamic state of the current scan.
92 u_int32_t nodeNum
; // zero is first node
93 u_int32_t recordNum
; // zero is first record
94 BTNodeDescriptor
* currentNodePtr
; // points to current node within buffer
95 u_int32_t nodesLeftInBuffer
; // number of valid nodes still in the buffer
96 u_int32_t recordsFound
; // number of leaf records seen so far
97 struct timeval startTime
; // time we started catalog search
99 typedef struct BTScanState BTScanState
;
102 /* *********************** PROTOTYPES *********************** */
104 int BTScanInitialize( const FCB
* btreeFile
,
105 u_int32_t startingNode
,
106 u_int32_t startingRecord
,
107 u_int32_t recordsFound
,
108 u_int32_t bufferSize
,
109 BTScanState
* scanState
);
111 int BTScanNextRecord( BTScanState
* scanState
,
115 u_int32_t
* dataSize
);
117 int BTScanTerminate( BTScanState
* scanState
,
118 u_int32_t
* startingNode
,
119 u_int32_t
* startingRecord
,
120 u_int32_t
* recordsFound
);
122 #endif /* __APPLE_API_PRIVATE */
124 #endif /* !_BTREESCANNER_H_ */