2 * Copyright (c) 1996-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
25 #ifndef _BTREESCANNER_H_
26 #define _BTREESCANNER_H_
28 #include <sys/appleapiopts.h>
31 #ifdef __APPLE_API_PRIVATE
34 #include "FileMgrInternal.h"
35 #include "BTreesPrivate.h"
37 // amount of time we are allowed to process a catalog search (in ยต secs)
38 // NOTE - code assumes kMaxMicroSecsInKernel is less than 1,000,000
39 enum { kMaxMicroSecsInKernel
= (1000 * 100) }; // 1 tenth of a second
41 // btree node scanner buffer size. at 32K we get 8 nodes. this is the size used
43 enum { kCatSearchBufferSize
= (32 * 1024) };
47 * ============ W A R N I N G ! ============
48 * DO NOT INCREASE THE SIZE OF THIS STRUCT!
49 * It must be less than or equal to the size of
50 * the opaque searchstate struct (in sys/attr.h).
52 /* Private description used in hfs_search */
55 u_int32_t writeCount
; /* The BTree's write count (to see if the catalog writeCount */
56 /* changed since the last search). If 0, the rest */
57 /* of the record is invalid, start from beginning. */
58 u_int32_t nextNode
; /* node number to resume search */
59 u_int32_t nextRecord
; /* record number to resume search */
60 u_int32_t recordsFound
; /* number of leaf records seen so far */
62 typedef struct CatPosition CatPosition
;
66 BTScanState - This structure is used to keep track of the current state
67 of a BTree scan. It contains both the dynamic state information (like
68 the current node number and record number) and information that is static
69 for the duration of a scan (such as buffer pointers).
71 NOTE: recordNum may equal or exceed the number of records in the node
72 number nodeNum. If so, then the next attempt to get a record will move
77 // The following fields are set up once at initialization time.
78 // They are not changed during a scan.
80 struct buf
* bufferPtr
;
81 BTreeControlBlock
* btcb
;
83 // The following fields are the dynamic state of the current scan.
84 u_int32_t nodeNum
; // zero is first node
85 u_int32_t recordNum
; // zero is first record
86 BTNodeDescriptor
* currentNodePtr
; // points to current node within buffer
87 u_int32_t nodesLeftInBuffer
; // number of valid nodes still in the buffer
88 u_int32_t recordsFound
; // number of leaf records seen so far
89 struct timeval startTime
; // time we started catalog search
91 typedef struct BTScanState BTScanState
;
94 /* *********************** PROTOTYPES *********************** */
96 int BTScanInitialize( const FCB
* btreeFile
,
97 u_int32_t startingNode
,
98 u_int32_t startingRecord
,
99 u_int32_t recordsFound
,
100 u_int32_t bufferSize
,
101 BTScanState
* scanState
);
103 int BTScanNextRecord( BTScanState
* scanState
,
107 u_int32_t
* dataSize
);
109 int BTScanTerminate( BTScanState
* scanState
,
110 u_int32_t
* startingNode
,
111 u_int32_t
* startingRecord
,
112 u_int32_t
* recordsFound
);
114 #endif /* __APPLE_API_PRIVATE */
116 #endif /* !_BTREESCANNER_H_ */