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