]> git.saurik.com Git - apple/hfs.git/blob - core/hfs_fsctl.h
hfs-366.70.1.tar.gz
[apple/hfs.git] / core / hfs_fsctl.h
1 /*
2 * Copyright (c) 2004-2015 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 #ifndef _HFS_FSCTL_H_
30 #define _HFS_FSCTL_H_
31
32 #include <sys/appleapiopts.h>
33
34 #include <sys/param.h>
35 #include <sys/ioccom.h>
36 #include <sys/time.h>
37 #include <stdint.h>
38
39 #ifdef __APPLE_API_UNSTABLE
40
41 struct hfs_backingstoreinfo {
42 int signature; /* == 3419115 */
43 int version; /* version of this struct (1) */
44 int backingfd; /* disk image file (on backing fs) */
45 int bandsize; /* sparse disk image band size */
46 };
47
48
49 typedef char pathname_t[MAXPATHLEN];
50
51 struct hfs_journal_info {
52 off_t jstart;
53 off_t jsize;
54 };
55
56
57 // Will be deprecated and replaced by hfs_fsinfo
58 struct hfsinfo_metadata {
59 uint32_t total;
60 uint32_t extents;
61 uint32_t catalog;
62 uint32_t allocation;
63 uint32_t attribute;
64 uint32_t journal;
65 uint32_t reserved[4];
66 };
67
68 /*
69 * Flags for hfs_fsinfo_data structure
70 */
71 #define HFS_FSINFO_CLASS_A 0x0001 /* Information for class A files requested */
72 #define HFS_FSINFO_CLASS_B 0x0002 /* Information for class B files requested */
73 #define HFS_FSINFO_CLASS_C 0x0004 /* Information for class C files requested */
74 #define HFS_FSINFO_CLASS_D 0x0008 /* Information for class D files requested */
75
76 /*
77 * Maximum number of buckets to represent range from 0 to 1TB (2^40) in
78 * increments of power of 2, and one catch-all bucket for anything that
79 * is greater than 1TB
80 */
81 #define HFS_FSINFO_DATA_MAX_BUCKETS 42
82
83 /*
84 * Maximum number of buckets to represents percentage range from 0 to 100
85 * in increments of 10.
86 */
87 #define HFS_FSINFO_PERCENT_MAX_BUCKETS 10
88
89 /*
90 * Maximum number of buckets to represent number of file/directory name characters
91 * (range 1 to 255) in increments of 5.
92 */
93 #define HFS_FSINFO_NAME_MAX_BUCKETS 51
94
95 /*
96 * Version number to ensure that the caller and the kernel have same understanding
97 * of the hfs_fsinfo_data structure. This version needs to be bumped whenever the
98 * number of buckets is changed.
99 */
100 #define HFS_FSINFO_VERSION 1
101
102 /*
103 * hfs_fsinfo_data is generic data structure to aggregate information like sizes
104 * or counts in buckets of power of 2. Each bucket represents a range of values
105 * that is determined based on its index in the array. Specifically, buckets[i]
106 * represents values that are greater than or equal to 2^(i-1) and less than 2^i,
107 * except the last bucket which represents range greater than or equal to 2^(i-1)
108 *
109 * The current maximum number of buckets is 41, so we can represent range from
110 * 0 up to 1TB in increments of power of 2, and then a catch-all bucket of
111 * anything that is greater than or equal to 1TB.
112 *
113 * For example,
114 * bucket[0] -> greater than or equal to 0 and less than 1
115 * bucket[1] -> greater than or equal to 1 and less than 2
116 * bucket[10] -> greater than or equal to 2^(10-1) = 512 and less than 2^10 = 1024
117 * bucket[20] -> greater than or equal to 2^(20-1) = 512KB and less than 2^20 = 1MB
118 * bucket[41] -> greater than or equal to 2^(41-1) = 1TB
119 *
120 * Note that fsctls that populate this data structure can take long time to
121 * execute as this operation can be I/O intensive (traversing btrees) and compute
122 * intensive.
123 *
124 * WARNING: Any changes to this structure should also update version number to
125 * ensure that the clients and kernel are reading/writing correctly.
126 */
127
128 /*
129 * The header includes the user input fields.
130 */
131 typedef struct hfs_fsinfo_header {
132 uint32_t request_type;
133 uint16_t version;
134 uint16_t flags;
135 } hfs_fsinfo_header_t;
136
137 struct hfs_fsinfo_data {
138 hfs_fsinfo_header_t header;
139 uint32_t bucket[HFS_FSINFO_DATA_MAX_BUCKETS];
140 };
141
142 /*
143 * Structure to represent information about metadata files
144 *
145 * WARNING: Any changes to this structure should also update version number to
146 * ensure that the clients and kernel are reading/writing correctly.
147 */
148 struct hfs_fsinfo_metadata {
149 hfs_fsinfo_header_t header;
150 uint32_t extents;
151 uint32_t catalog;
152 uint32_t allocation;
153 uint32_t attribute;
154 uint32_t journal;
155 };
156
157 /*
158 * Structure to represent distribution of number of file name characters
159 * in increments of 5s. Each bucket represents a range of values that is
160 * determined based on its index in the array. So bucket[i] represents values
161 * that are greater than or equal to (i*5) and less than ((i+1)*10).
162 *
163 * Since this structure represents range of file name characters and the
164 * maximum number of unicode characters in HFS+ is 255, the maximum number
165 * of buckets will be 52 [0..51].
166 *
167 * For example,
168 * bucket[4] -> greater than or equal to 20 and less than 25 characters
169 * bucket[51] -> equal to 255 characters
170 *
171 * WARNING: Any changes to this structure should also update version number to
172 * ensure that the clients and kernel are reading/writing correctly.
173 */
174 struct hfs_fsinfo_name {
175 hfs_fsinfo_header_t header;
176 uint32_t bucket[HFS_FSINFO_NAME_MAX_BUCKETS];
177 };
178
179 /*
180 * Structure to represent information about content protection classes
181 *
182 * WARNING: Any changes to this structure should also update version number to
183 * ensure that the clients and kernel are reading/writing correctly.
184 */
185 struct hfs_fsinfo_cprotect {
186 hfs_fsinfo_header_t header;
187 uint32_t class_A;
188 uint32_t class_B;
189 uint32_t class_C;
190 uint32_t class_D;
191 uint32_t class_E;
192 uint32_t class_F;
193 };
194
195 /*
196 * Union of all the different values returned by HFSIOC_FSINFO fsctl
197 */
198 union hfs_fsinfo {
199 hfs_fsinfo_header_t header;
200 struct hfs_fsinfo_data data;
201 struct hfs_fsinfo_metadata metadata;
202 struct hfs_fsinfo_name name;
203 struct hfs_fsinfo_cprotect cprotect;
204 };
205 typedef union hfs_fsinfo hfs_fsinfo;
206
207 /*
208 * Type of FSINFO requested, specified by the caller in request_type field
209 */
210 enum {
211 /* Information about number of allocation blocks for each metadata file, returns struct hfs_fsinfo_metadata */
212 HFS_FSINFO_METADATA_BLOCKS_INFO = 1,
213
214 /* Information about number of extents for each metadata file, returns struct hfs_fsinfo_metadata */
215 HFS_FSINFO_METADATA_EXTENTS = 2,
216
217 /* Information about percentage of free nodes vs used nodes in metadata btrees, returns struct hfs_fsinfo_metadata */
218 HFS_FSINFO_METADATA_PERCENTFREE = 3,
219
220 /* Distribution of number of extents for data files (data fork, no rsrc fork, no xattr), returns struct hfs_fsinfo_data */
221 HFS_FSINFO_FILE_EXTENT_COUNT = 4,
222
223 /* Distribution of extent sizes for data files (data fork, no rsrc fork, no xattr), returns struct hfs_fsinfo_data */
224 HFS_FSINFO_FILE_EXTENT_SIZE = 5,
225
226 /* Distribution of file sizes for data files (data fork, no rsrc fork, no xattr), returns struct hfs_fsinfo_data */
227 HFS_FSINFO_FILE_SIZE = 6,
228
229 /* Distribution of valence for all directories, returns struct hfs_fsinfo_data */
230 HFS_FSINFO_DIR_VALENCE = 7,
231
232 /* Distribution of file/directory name size in unicode characters, returns struct hfs_fsinfo_name */
233 HFS_FSINFO_NAME_SIZE = 8,
234
235 /* Distribution of extended attribute sizes, returns hfs_fsinfo_data */
236 HFS_FSINFO_XATTR_SIZE = 9,
237
238 /* Distribution of free space for the entire file system, returns struct hfs_fsinfo_data */
239 HFS_FSINFO_FREE_EXTENTS = 10,
240
241 /* Information about number of files belonging to each class, returns hfs_fsinfo_cprotect */
242 HFS_FSINFO_FILE_CPROTECT_COUNT = 11,
243
244 /*
245 * Distribution of symbolic link sizes for data files (data fork, no rsrc fork, no xattr),
246 * returns struct hfs_fsinfo_data
247 */
248 HFS_FSINFO_SYMLINK_SIZE = 12,
249 };
250
251
252 /* HFS FS CONTROL COMMANDS */
253
254 #define HFSIOC_RESIZE_PROGRESS _IOR('h', 1, u_int32_t)
255 #define HFS_RESIZE_PROGRESS IOCBASECMD(HFSIOC_RESIZE_PROGRESS)
256
257 #define HFSIOC_RESIZE_VOLUME _IOW('h', 2, u_int64_t)
258 #define HFS_RESIZE_VOLUME IOCBASECMD(HFSIOC_RESIZE_VOLUME)
259
260 #define HFSIOC_CHANGE_NEXT_ALLOCATION _IOWR('h', 3, u_int32_t)
261 #define HFS_CHANGE_NEXT_ALLOCATION IOCBASECMD(HFSIOC_CHANGE_NEXT_ALLOCATION)
262 /* Magic value for next allocation to use with fcntl to set next allocation
263 * to zero and never update it again on new block allocation.
264 */
265 #define HFS_NO_UPDATE_NEXT_ALLOCATION 0xffffFFFF
266
267 #define HFSIOC_GETCREATETIME _IOR('h', 4, time_t)
268 #define HFS_GETCREATETIME IOCBASECMD(HFSIOC_GETCREATETIME)
269
270 #define HFSIOC_SETBACKINGSTOREINFO _IOW('h', 7, struct hfs_backingstoreinfo)
271 #define HFS_SETBACKINGSTOREINFO IOCBASECMD(HFSIOC_SETBACKINGSTOREINFO)
272
273 #define HFSIOC_CLRBACKINGSTOREINFO _IO('h', 8)
274 #define HFS_CLRBACKINGSTOREINFO IOCBASECMD(HFSIOC_CLRBACKINGSTOREINFO)
275
276 // 'h', 9 used to be HFSIOC_BULKACCESS which is now deprecated
277
278 /* Unsupported - Previously used to enable/disable ACLs */
279 #define HFSIOC_UNSUPPORTED _IOW('h', 10, int32_t)
280
281 #define HFSIOC_PREV_LINK _IOWR('h', 11, u_int32_t)
282 #define HFS_PREV_LINK IOCBASECMD(HFSIOC_PREV_LINK)
283
284 #define HFSIOC_NEXT_LINK _IOWR('h', 12, u_int32_t)
285 #define HFS_NEXT_LINK IOCBASECMD(HFSIOC_NEXT_LINK)
286
287 #define HFSIOC_GETPATH _IOWR('h', 13, pathname_t)
288 #define HFS_GETPATH IOCBASECMD(HFSIOC_GETPATH)
289 /* By default, the path returned by HFS_GETPATH is an absolute path,
290 * i.e. it also contains the mount point of the volume on which the
291 * fileID exists. If the following bit is set, the path returned is
292 * relative to the root of the volume.
293 */
294 #define HFS_GETPATH_VOLUME_RELATIVE 0x1
295
296 /* Enable/disable extent-based extended attributes */
297 #define HFSIOC_SET_XATTREXTENTS_STATE _IOW('h', 14, u_int32_t)
298 #define HFS_SET_XATTREXTENTS_STATE IOCBASECMD(HFSIOC_SET_XATTREXTENTS_STATE)
299
300 #define HFSIOC_EXT_BULKACCESS _IOW('h', 15, struct user32_ext_access_t)
301 #define HFS_EXT_BULKACCESS_FSCTL IOCBASECMD(HFSIOC_EXT_BULKACCESS)
302
303 #define HFSIOC_MARK_BOOT_CORRUPT _IO('h', 16)
304 #define HFS_MARK_BOOT_CORRUPT IOCBASECMD(HFSIOC_MARK_BOOT_CORRUPT)
305
306 #define HFSIOC_GET_JOURNAL_INFO _IOR('h', 17, struct hfs_journal_info)
307 #define HFS_FSCTL_GET_JOURNAL_INFO IOCBASECMD(HFSIOC_GET_JOURNAL_INFO)
308
309 #define HFSIOC_SET_VERY_LOW_DISK _IOW('h', 20, u_int32_t)
310 #define HFS_FSCTL_SET_VERY_LOW_DISK IOCBASECMD(HFSIOC_SET_VERY_LOW_DISK)
311
312 #define HFSIOC_SET_LOW_DISK _IOW('h', 21, u_int32_t)
313 #define HFS_FSCTL_SET_LOW_DISK IOCBASECMD(HFSIOC_SET_LOW_DISK)
314
315 #define HFSIOC_SET_DESIRED_DISK _IOW('h', 22, u_int32_t)
316 #define HFS_FSCTL_SET_DESIRED_DISK IOCBASECMD(HFSIOC_SET_DESIRED_DISK)
317
318 #define HFSIOC_SET_ALWAYS_ZEROFILL _IOW('h', 23, int32_t)
319 #define HFS_SET_ALWAYS_ZEROFILL IOCBASECMD(HFSIOC_SET_ALWAYS_ZEROFILL)
320
321 #define HFSIOC_VOLUME_STATUS _IOR('h', 24, u_int32_t)
322 #define HFS_VOLUME_STATUS IOCBASECMD(HFSIOC_VOLUME_STATUS)
323
324 /* Disable metadata zone for given volume */
325 #define HFSIOC_DISABLE_METAZONE _IO('h', 25)
326 #define HFS_DISABLE_METAZONE IOCBASECMD(HFSIOC_DISABLE_METAZONE)
327
328 /* Change the next CNID value */
329 #define HFSIOC_CHANGE_NEXTCNID _IOWR('h', 26, u_int32_t)
330 #define HFS_CHANGE_NEXTCNID IOCBASECMD(HFSIOC_CHANGE_NEXTCNID)
331
332 /* Get the low disk space values */
333 #define HFSIOC_GET_VERY_LOW_DISK _IOR('h', 27, u_int32_t)
334 #define HFS_FSCTL_GET_VERY_LOW_DISK IOCBASECMD(HFSIOC_GET_VERY_LOW_DISK)
335
336 #define HFSIOC_GET_LOW_DISK _IOR('h', 28, u_int32_t)
337 #define HFS_FSCTL_GET_LOW_DISK IOCBASECMD(HFSIOC_GET_LOW_DISK)
338
339 #define HFSIOC_GET_DESIRED_DISK _IOR('h', 29, u_int32_t)
340 #define HFS_FSCTL_GET_DESIRED_DISK IOCBASECMD(HFSIOC_GET_DESIRED_DISK)
341
342 /* 30 was HFSIOC_GET_WRITE_GEN_COUNTER and is now deprecated */
343
344 /* 31 was HFSIOC_GET_DOCUMENT_ID and is now deprecated */
345
346 /* revisiond only uses this when something transforms in a way the kernel can't track such as "foo.rtf" -> "foo.rtfd" */
347 #define HFSIOC_TRANSFER_DOCUMENT_ID _IOW('h', 32, u_int32_t)
348 #define HFS_TRANSFER_DOCUMENT_ID IOCBASECMD(HFSIOC_TRANSFER_DOCUMENT_ID)
349
350
351 /*
352 * XXX: Will be deprecated and replaced by HFSIOC_GET_FSINFO
353 *
354 * Get information about number of file system allocation blocks used by metadata
355 * files on the volume, including individual btrees and journal file. The caller
356 * can determine the size of file system allocation block using value returned as
357 * f_bsize by statfs(2).
358 */
359 #define HFSIOC_FSINFO_METADATA_BLOCKS _IOWR('h', 38, struct hfsinfo_metadata)
360 #define HFS_FSINFO_METADATA_BLOCKS IOCBASECMD(HFSIOC_FSINFO_METADATA_BLOCKS)
361
362 /* Send TRIMs for all free blocks to the underlying device */
363 #define HFSIOC_CS_FREESPACE_TRIM _IOWR('h', 39, u_int32_t)
364 #define HFS_CS_FREESPACE_TRIM IOCBASECMD(HFSIOC_CS_FREESPACE_TRIM)
365
366
367 /* Get file system information for the given volume */
368 #define HFSIOC_GET_FSINFO _IOWR('h', 45, hfs_fsinfo)
369 #define HFS_GET_FSINFO IOCBASECMD(HFSIOC_GET_FSINFO)
370
371 /* Re-pin hotfile data; argument controls what state gets repinned */
372 #define HFSIOC_REPIN_HOTFILE_STATE _IOWR('h', 46, u_int32_t)
373 #define HFS_REPIN_HOTFILE_STATE IOCBASECMD(HFSIOC_REPIN_HOTFILE_STATE)
374
375 #define HFS_REPIN_METADATA 0x0001
376 #define HFS_REPIN_USERDATA 0x0002
377
378 /* Mark a directory or file as worth caching on any underlying "fast" device */
379 #define HFSIOC_SET_HOTFILE_STATE _IOWR('h', 47, u_int32_t)
380 #define HFS_SET_HOTFILE_STATE IOCBASECMD(HFSIOC_SET_HOTFILE_STATE)
381
382 /* flags to pass to SET_HOTFILE_STATE */
383 #define HFS_MARK_FASTDEVCANDIDATE 0x0001
384 #define HFS_UNMARK_FASTDEVCANDIDATE 0x0002
385 #define HFS_NEVER_FASTDEVCANDIDATE 0x0004
386
387 #define HFSIOC_SET_MAX_DEFRAG_SIZE _IOWR('h', 48, u_int32_t)
388 #define HFS_SET_MAX_DEFRAG_SIZE IOCBASECMD(HFSIOC_SET_MAX_DEFRAG_SIZE)
389
390 #define HFSIOC_FORCE_ENABLE_DEFRAG _IOWR('h', 49, u_int32_t)
391 #define HFS_FORCE_ENABLE_DEFRAG IOCBASECMD(HFSIOC_FORCE_ENABLE_DEFRAG)
392
393
394 #endif /* __APPLE_API_UNSTABLE */
395
396 #endif /* ! _HFS_FSCTL_H_ */