]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
04b8595b | 2 | * Copyright (c) 2000-2015 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | File: FilesInternal.h | |
30 | ||
31 | Contains: IPI for File Manager (HFS Plus) | |
32 | ||
33 | Version: HFS Plus 1.0 | |
34 | ||
6d2010ae | 35 | Copyright: � 1996-2001 by Apple Computer, Inc., all rights reserved. |
1c79356b A |
36 | |
37 | */ | |
38 | #ifndef __FILEMGRINTERNAL__ | |
39 | #define __FILEMGRINTERNAL__ | |
40 | ||
9bccf70c A |
41 | #include <sys/appleapiopts.h> |
42 | ||
43 | #ifdef KERNEL | |
44 | #ifdef __APPLE_API_PRIVATE | |
45 | ||
1c79356b A |
46 | #include <sys/param.h> |
47 | #include <sys/vnode.h> | |
48 | ||
04b8595b A |
49 | #if !HFS_ALLOC_TEST |
50 | ||
1c79356b A |
51 | #include "../../hfs.h" |
52 | #include "../../hfs_macos_defs.h" | |
53 | #include "../../hfs_format.h" | |
9bccf70c | 54 | #include "../../hfs_cnode.h" |
1c79356b | 55 | |
04b8595b | 56 | #endif |
1c79356b | 57 | |
1c79356b A |
58 | #ifdef __cplusplus |
59 | extern "C" { | |
60 | #endif | |
61 | ||
1c79356b | 62 | /* CatalogNodeID is used to track catalog objects */ |
2d21ac55 | 63 | typedef u_int32_t HFSCatalogNodeID; |
1c79356b A |
64 | |
65 | /* internal error codes*/ | |
66 | ||
67 | #if TARGET_API_MACOS_X | |
68 | #define ERR_BASE -32767 | |
69 | #else | |
70 | #define ERR_BASE 0 | |
71 | #endif | |
72 | ||
73 | enum { | |
74 | /* FXM errors*/ | |
75 | fxRangeErr = ERR_BASE + 16, /* file position beyond mapped range*/ | |
76 | fxOvFlErr = ERR_BASE + 17, /* extents file overflow*/ | |
77 | /* Unicode errors*/ | |
78 | uniTooLongErr = ERR_BASE + 24, /* Unicode string too long to convert to Str31*/ | |
79 | uniBufferTooSmallErr = ERR_BASE + 25, /* Unicode output buffer too small*/ | |
80 | uniNotMappableErr = ERR_BASE + 26, /* Unicode string can't be mapped to given script*/ | |
81 | /* BTree Manager errors*/ | |
82 | btNotFound = ERR_BASE + 32, /* record not found*/ | |
83 | btExists = ERR_BASE + 33, /* record already exists*/ | |
84 | btNoSpaceAvail = ERR_BASE + 34, /* no available space*/ | |
85 | btNoFit = ERR_BASE + 35, /* record doesn't fit in node */ | |
86 | btBadNode = ERR_BASE + 36, /* bad node detected*/ | |
87 | btBadHdr = ERR_BASE + 37, /* bad BTree header record detected*/ | |
88 | dsBadRotate = ERR_BASE + 64, /* bad BTree rotate*/ | |
89 | /* Catalog Manager errors*/ | |
90 | cmNotFound = ERR_BASE + 48, /* CNode not found*/ | |
91 | cmExists = ERR_BASE + 49, /* CNode already exists*/ | |
92 | cmNotEmpty = ERR_BASE + 50, /* directory CNode not empty (valence = 0)*/ | |
93 | cmRootCN = ERR_BASE + 51, /* invalid reference to root CNode*/ | |
94 | cmBadNews = ERR_BASE + 52, /* detected bad catalog structure*/ | |
95 | cmFThdDirErr = ERR_BASE + 53, /* thread belongs to a directory not a file*/ | |
96 | cmFThdGone = ERR_BASE + 54, /* file thread doesn't exist*/ | |
97 | cmParentNotFound = ERR_BASE + 55, /* CNode for parent ID does not exist*/ | |
98 | /* TFS internal errors*/ | |
99 | fsDSIntErr = -127 /* Internal file system error*/ | |
100 | }; | |
101 | ||
102 | ||
103 | /* internal flags*/ | |
104 | ||
1c79356b | 105 | enum { |
9bccf70c A |
106 | kEFAllMask = 0x01, /* allocate all requested bytes or none */ |
107 | kEFContigMask = 0x02, /* force contiguous allocation */ | |
108 | kEFReserveMask = 0x04, /* keep block reserve */ | |
109 | kEFDeferMask = 0x08, /* defer file block allocations */ | |
110 | kEFNoClumpMask = 0x10, /* don't round up to clump size */ | |
55e303ae | 111 | kEFMetadataMask = 0x20, /* metadata allocation */ |
9bccf70c | 112 | |
1c79356b A |
113 | kTFTrunExtBit = 0, /* truncate to the extent containing new PEOF*/ |
114 | kTFTrunExtMask = 1 | |
115 | }; | |
116 | ||
117 | enum { | |
0b4e3aa0 A |
118 | kUndefinedStrLen = 0, /* Unknown string length */ |
119 | kNoHint = 0, | |
1c79356b | 120 | |
1c79356b A |
121 | /* FileIDs variables*/ |
122 | kNumExtentsToCache = 4 /* just guessing for ExchangeFiles*/ | |
123 | }; | |
124 | ||
125 | ||
1c79356b A |
126 | /* Universal Extent Key */ |
127 | ||
128 | union ExtentKey { | |
129 | HFSExtentKey hfs; | |
130 | HFSPlusExtentKey hfsPlus; | |
131 | }; | |
132 | typedef union ExtentKey ExtentKey; | |
133 | /* Universal extent descriptor */ | |
134 | ||
135 | union ExtentDescriptor { | |
136 | HFSExtentDescriptor hfs; | |
137 | HFSPlusExtentDescriptor hfsPlus; | |
138 | }; | |
139 | typedef union ExtentDescriptor ExtentDescriptor; | |
140 | /* Universal extent record */ | |
141 | ||
142 | union ExtentRecord { | |
143 | HFSExtentRecord hfs; | |
144 | HFSPlusExtentRecord hfsPlus; | |
145 | }; | |
146 | typedef union ExtentRecord ExtentRecord; | |
1c79356b A |
147 | |
148 | ||
149 | enum { | |
150 | CMMaxCName = kHFSMaxFileNameChars | |
151 | }; | |
152 | ||
153 | ||
1c79356b | 154 | |
1c79356b A |
155 | /* Universal catalog name*/ |
156 | ||
157 | union CatalogName { | |
158 | Str31 pstr; | |
159 | HFSUniStr255 ustr; | |
160 | }; | |
161 | typedef union CatalogName CatalogName; | |
162 | ||
1c79356b A |
163 | |
164 | /* | |
165 | * MacOS accessor routines | |
166 | */ | |
9bccf70c A |
167 | #define GetFileControlBlock(fref) VTOF((fref)) |
168 | #define GetFileRefNumFromFCB(fcb) FTOV((fcb)) | |
1c79356b | 169 | |
1c79356b A |
170 | /* Test for error and return if error occurred*/ |
171 | EXTERN_API_C( void ) | |
172 | ReturnIfError (OSErr result); | |
173 | ||
2d21ac55 | 174 | #define ReturnIfError(result) do { if ( (result) != noErr ) return (result); } while(0) |
1c79356b | 175 | |
1c79356b A |
176 | /* Exit function on error*/ |
177 | EXTERN_API_C( void ) | |
178 | ExitOnError (OSErr result); | |
179 | ||
2d21ac55 | 180 | #define ExitOnError( result ) do { if ( ( result ) != noErr ) goto ErrorExit; } while(0) |
1c79356b | 181 | |
1c79356b A |
182 | |
183 | ||
184 | /* Catalog Manager Routines (IPI)*/ | |
185 | ||
1c79356b A |
186 | EXTERN_API_C( OSErr ) |
187 | ExchangeFileIDs (ExtendedVCB * volume, | |
188 | ConstUTF8Param srcName, | |
189 | ConstUTF8Param destName, | |
190 | HFSCatalogNodeID srcID, | |
191 | HFSCatalogNodeID destID, | |
2d21ac55 A |
192 | u_int32_t srcHint, |
193 | u_int32_t destHint ); | |
1c79356b | 194 | |
6d2010ae A |
195 | EXTERN_API_C( OSErr ) |
196 | MoveData( ExtendedVCB *vcb, HFSCatalogNodeID srcID, HFSCatalogNodeID destID, int rsrc); | |
1c79356b A |
197 | |
198 | /* BTree Manager Routines*/ | |
199 | ||
2d21ac55 | 200 | typedef CALLBACK_API_C( int32_t , KeyCompareProcPtr )(void *a, void *b); |
1c79356b A |
201 | |
202 | ||
1c79356b A |
203 | EXTERN_API_C( OSErr ) |
204 | ReplaceBTreeRecord (FileReference refNum, | |
205 | const void * key, | |
2d21ac55 | 206 | u_int32_t hint, |
1c79356b | 207 | void * newData, |
2d21ac55 A |
208 | u_int16_t dataSize, |
209 | u_int32_t * newHint); | |
1c79356b | 210 | |
1c79356b | 211 | |
1c79356b | 212 | /* Prototypes for exported routines in VolumeAllocation.c*/ |
0b4c1975 A |
213 | |
214 | /* | |
215 | * Flags for BlockAllocate() and BlockDeallocate() | |
216 | */ | |
39236c6e A |
217 | #define HFS_ALLOC_FORCECONTIG 0x1 //force contiguous block allocation; minblocks must be allocated |
218 | #define HFS_ALLOC_METAZONE 0x2 //can use metazone blocks | |
219 | #define HFS_ALLOC_SKIPFREEBLKS 0x4 //skip checking/updating freeblocks during alloc/dealloc | |
220 | #define HFS_ALLOC_FLUSHTXN 0x8 //pick best fit for allocation, even if a jnl flush is req'd | |
0b4c1975 | 221 | |
1c79356b A |
222 | EXTERN_API_C( OSErr ) |
223 | BlockAllocate (ExtendedVCB * vcb, | |
2d21ac55 A |
224 | u_int32_t startingBlock, |
225 | u_int32_t minBlocks, | |
226 | u_int32_t maxBlocks, | |
0b4c1975 | 227 | u_int32_t flags, |
2d21ac55 A |
228 | u_int32_t * startBlock, |
229 | u_int32_t * actualBlocks); | |
1c79356b A |
230 | |
231 | EXTERN_API_C( OSErr ) | |
232 | BlockDeallocate (ExtendedVCB * vcb, | |
2d21ac55 | 233 | u_int32_t firstBlock, |
0b4c1975 A |
234 | u_int32_t numBlocks, |
235 | u_int32_t flags); | |
1c79356b | 236 | |
d1ecb069 | 237 | EXTERN_API_C ( void ) |
6d2010ae | 238 | ResetVCBFreeExtCache(struct hfsmount *hfsmp); |
d1ecb069 | 239 | |
55e303ae | 240 | EXTERN_API_C( OSErr ) |
2d21ac55 | 241 | BlockMarkAllocated(ExtendedVCB *vcb, u_int32_t startingBlock, u_int32_t numBlocks); |
55e303ae A |
242 | |
243 | EXTERN_API_C( OSErr ) | |
2d21ac55 | 244 | BlockMarkFree( ExtendedVCB *vcb, u_int32_t startingBlock, u_int32_t numBlocks); |
55e303ae | 245 | |
6d2010ae A |
246 | EXTERN_API_C( OSErr ) |
247 | BlockMarkFreeUnused( ExtendedVCB *vcb, u_int32_t startingBlock, u_int32_t numBlocks); | |
248 | ||
2d21ac55 | 249 | EXTERN_API_C( u_int32_t ) |
55e303ae | 250 | MetaZoneFreeBlocks(ExtendedVCB *vcb); |
6d2010ae A |
251 | |
252 | EXTERN_API_C( u_int32_t ) | |
253 | UpdateAllocLimit (struct hfsmount *hfsmp, u_int32_t new_end_block); | |
316670eb A |
254 | |
255 | EXTERN_API_C( u_int32_t ) | |
39236c6e | 256 | ScanUnmapBlocks(struct hfsmount *hfsmp); |
316670eb | 257 | |
39236c6e A |
258 | EXTERN_API_C( int ) |
259 | hfs_init_summary (struct hfsmount *hfsmp); | |
55e303ae | 260 | |
04b8595b A |
261 | errno_t hfs_find_free_extents(struct hfsmount *hfsmp, |
262 | void (*callback)(void *data, off_t), void *callback_arg); | |
263 | ||
1c79356b A |
264 | /* File Extent Mapping routines*/ |
265 | EXTERN_API_C( OSErr ) | |
266 | FlushExtentFile (ExtendedVCB * vcb); | |
267 | ||
39236c6e | 268 | #if CONFIG_HFS_STD |
2d21ac55 | 269 | EXTERN_API_C( int32_t ) |
1c79356b A |
270 | CompareExtentKeys (const HFSExtentKey * searchKey, |
271 | const HFSExtentKey * trialKey); | |
39236c6e | 272 | #endif |
1c79356b | 273 | |
2d21ac55 | 274 | EXTERN_API_C( int32_t ) |
1c79356b A |
275 | CompareExtentKeysPlus (const HFSPlusExtentKey *searchKey, |
276 | const HFSPlusExtentKey *trialKey); | |
277 | ||
1c79356b | 278 | EXTERN_API_C( OSErr ) |
6d2010ae A |
279 | TruncateFileC (ExtendedVCB *vcb, FCB *fcb, int64_t peof, int deleted, |
280 | int rsrc, uint32_t fileid, Boolean truncateToExtent); | |
281 | ||
1c79356b A |
282 | EXTERN_API_C( OSErr ) |
283 | ExtendFileC (ExtendedVCB * vcb, | |
284 | FCB * fcb, | |
2d21ac55 A |
285 | int64_t bytesToAdd, |
286 | u_int32_t blockHint, | |
287 | u_int32_t flags, | |
288 | int64_t * actualBytesAdded); | |
1c79356b A |
289 | |
290 | EXTERN_API_C( OSErr ) | |
291 | MapFileBlockC (ExtendedVCB * vcb, | |
292 | FCB * fcb, | |
293 | size_t numberOfBytes, | |
294 | off_t offset, | |
91447636 | 295 | daddr64_t * startBlock, |
1c79356b A |
296 | size_t * availableBytes); |
297 | ||
2d21ac55 | 298 | OSErr HeadTruncateFile(ExtendedVCB *vcb, FCB *fcb, u_int32_t headblks); |
91447636 | 299 | |
55e303ae | 300 | EXTERN_API_C( int ) |
2d21ac55 | 301 | AddFileExtent (ExtendedVCB *vcb, FCB *fcb, u_int32_t startBlock, u_int32_t blockCount); |
55e303ae | 302 | |
1c79356b A |
303 | #if TARGET_API_MACOS_X |
304 | EXTERN_API_C( Boolean ) | |
305 | NodesAreContiguous (ExtendedVCB * vcb, | |
306 | FCB * fcb, | |
2d21ac55 | 307 | u_int32_t nodeSize); |
1c79356b | 308 | #endif |
1c79356b | 309 | |
1c79356b A |
310 | |
311 | ||
312 | /* Get the current time in UTC (GMT)*/ | |
2d21ac55 | 313 | EXTERN_API_C( u_int32_t ) |
1c79356b A |
314 | GetTimeUTC (void); |
315 | ||
2d21ac55 A |
316 | EXTERN_API_C( u_int32_t ) |
317 | LocalToUTC (u_int32_t localTime); | |
1c79356b | 318 | |
2d21ac55 A |
319 | EXTERN_API_C( u_int32_t ) |
320 | UTCToLocal (u_int32_t utcTime); | |
1c79356b A |
321 | |
322 | ||
1c79356b A |
323 | #ifdef __cplusplus |
324 | } | |
325 | #endif | |
326 | ||
9bccf70c A |
327 | #endif /* __APPLE_API_PRIVATE */ |
328 | #endif /* KERNEL */ | |
1c79356b A |
329 | #endif /* __FILEMGRINTERNAL__ */ |
330 |