]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfscommon/headers/BTreeScanner.h
b537bccfd73fd8f9baf7c857a49b2f8066f9434c
[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 * 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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 *
22 * @(#)BTreeScanner.h
23 */
24
25 #ifndef _BTREESCANNER_H_
26 #define _BTREESCANNER_H_
27
28 #include <sys/time.h>
29
30 #include "FileMgrInternal.h"
31 #include "BTreesPrivate.h"
32
33 // amount of time we are allowed to process a catalog search (in ยต secs)
34 // NOTE - code assumes kMaxMicroSecsInKernel is less than 1,000,000
35 // jertodo - what should we set this to?
36 enum { kMaxMicroSecsInKernel = (1000 * 100) }; // 1 tenth of a second
37
38 // btree node scanner buffer size. at 32K we get 8 nodes. this is the size used
39 // in Mac OS 9
40 enum { kCatSearchBufferSize = (32 * 1024) };
41
42
43 /*
44 * ============ W A R N I N G ! ============
45 * DO NOT INCREASE THE SIZE OF THIS STRUCT!
46 * It must be less than or equal to the size of
47 * the opaque searchstate struct (in sys/attr.h).
48 */
49 /* Private description used in hfs_search */
50 struct CatPosition
51 {
52 u_int32_t writeCount; /* The BTree's write count (to see if the catalog writeCount */
53 /* changed since the last search). If 0, the rest */
54 /* of the record is invalid, start from beginning. */
55 u_int32_t nextNode; /* node number to resume search */
56 u_int32_t nextRecord; /* record number to resume search */
57 u_int32_t recordsFound; /* number of leaf records seen so far */
58 };
59 typedef struct CatPosition CatPosition;
60
61
62 /*
63 BTScanState - This structure is used to keep track of the current state
64 of a BTree scan. It contains both the dynamic state information (like
65 the current node number and record number) and information that is static
66 for the duration of a scan (such as buffer pointers).
67
68 NOTE: recordNum may equal or exceed the number of records in the node
69 number nodeNum. If so, then the next attempt to get a record will move
70 to a new node number.
71 */
72 struct BTScanState
73 {
74 // The following fields are set up once at initialization time.
75 // They are not changed during a scan.
76 u_int32_t bufferSize;
77 struct buf * bufferPtr;
78 BTreeControlBlock * btcb;
79
80 // The following fields are the dynamic state of the current scan.
81 u_int32_t nodeNum; // zero is first node
82 u_int32_t recordNum; // zero is first record
83 BTNodeDescriptor * currentNodePtr; // points to current node within buffer
84 u_int32_t nodesLeftInBuffer; // number of valid nodes still in the buffer
85 u_int32_t recordsFound; // number of leaf records seen so far
86 struct timeval startTime; // time we started catalog search
87 };
88 typedef struct BTScanState BTScanState;
89
90
91 /* *********************** PROTOTYPES *********************** */
92
93 int BTScanInitialize( const FCB * btreeFile,
94 u_int32_t startingNode,
95 u_int32_t startingRecord,
96 u_int32_t recordsFound,
97 u_int32_t bufferSize,
98 BTScanState * scanState );
99
100 int BTScanNextRecord( BTScanState * scanState,
101 Boolean avoidIO,
102 void * * key,
103 void * * data,
104 u_int32_t * dataSize );
105
106 int BTScanTerminate( BTScanState * scanState,
107 u_int32_t * startingNode,
108 u_int32_t * startingRecord,
109 u_int32_t * recordsFound );
110
111 #endif /* !_BTREESCANNER_H_ */