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