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