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