]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfscommon/headers/BTreeScanner.h
xnu-792.6.56.tar.gz
[apple/xnu.git] / bsd / hfs / hfscommon / headers / BTreeScanner.h
1 /*
2 * Copyright (c) 1996-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 *
23 * @(#)BTreeScanner.h
24 */
25
26 #ifndef _BTREESCANNER_H_
27 #define _BTREESCANNER_H_
28
29 #include <sys/appleapiopts.h>
30
31 #ifdef KERNEL
32 #ifdef __APPLE_API_PRIVATE
33 #include <sys/time.h>
34
35 #include "FileMgrInternal.h"
36 #include "BTreesPrivate.h"
37
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
41
42 // btree node scanner buffer size. at 32K we get 8 nodes. this is the size used
43 // in Mac OS 9
44 enum { kCatSearchBufferSize = (32 * 1024) };
45
46
47 /*
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).
52 */
53 /* Private description used in hfs_search */
54 struct CatPosition
55 {
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 */
62 };
63 typedef struct CatPosition CatPosition;
64
65
66 /*
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).
71
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
74 to a new node number.
75 */
76 struct BTScanState
77 {
78 // The following fields are set up once at initialization time.
79 // They are not changed during a scan.
80 u_int32_t bufferSize;
81 struct buf * bufferPtr;
82 BTreeControlBlock * btcb;
83
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
91 };
92 typedef struct BTScanState BTScanState;
93
94
95 /* *********************** PROTOTYPES *********************** */
96
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 );
103
104 int BTScanNextRecord( BTScanState * scanState,
105 Boolean avoidIO,
106 void * * key,
107 void * * data,
108 u_int32_t * dataSize );
109
110 int BTScanTerminate( BTScanState * scanState,
111 u_int32_t * startingNode,
112 u_int32_t * startingRecord,
113 u_int32_t * recordsFound );
114
115 #endif /* __APPLE_API_PRIVATE */
116 #endif /* KERNEL */
117 #endif /* !_BTREESCANNER_H_ */