1 | /* |
2 | * Copyright (c) 1998-2014 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 | #ifndef _SYS_DISK_H_ |
30 | #define _SYS_DISK_H_ |
31 | |
32 | #include <stdint.h> |
33 | #include <sys/ioctl.h> |
34 | |
35 | #ifdef XNU_KERNEL_PRIVATE |
36 | #include <mach/boolean.h> |
37 | #endif /* XNU_KERNEL_PRIVATE */ |
38 | |
39 | /* |
40 | * Definitions |
41 | * |
42 | * ioctl description |
43 | * ------------------------------------- --------------------------------------- |
44 | * DKIOCEJECT eject media |
45 | * DKIOCSYNCHRONIZE flush media |
46 | * |
47 | * DKIOCFORMAT format media |
48 | * DKIOCGETFORMATCAPACITIES get media's formattable capacities |
49 | * |
50 | * DKIOCGETBLOCKSIZE get media's block size |
51 | * DKIOCGETBLOCKCOUNT get media's block count |
52 | * DKIOCGETFIRMWAREPATH get media's firmware path |
53 | * |
54 | * DKIOCISFORMATTED is media formatted? |
55 | * DKIOCISWRITABLE is media writable? |
56 | * |
57 | * DKIOCREQUESTIDLE idle media |
58 | * DKIOCUNMAP delete unused data |
59 | * |
60 | * DKIOCGETMAXBLOCKCOUNTREAD get maximum block count for reads |
61 | * DKIOCGETMAXBLOCKCOUNTWRITE get maximum block count for writes |
62 | * DKIOCGETMAXBYTECOUNTREAD get maximum byte count for reads |
63 | * DKIOCGETMAXBYTECOUNTWRITE get maximum byte count for writes |
64 | * |
65 | * DKIOCGETMAXSEGMENTCOUNTREAD get maximum segment count for reads |
66 | * DKIOCGETMAXSEGMENTCOUNTWRITE get maximum segment count for writes |
67 | * DKIOCGETMAXSEGMENTBYTECOUNTREAD get maximum segment byte count for reads |
68 | * DKIOCGETMAXSEGMENTBYTECOUNTWRITE get maximum segment byte count for writes |
69 | * |
70 | * DKIOCGETMINSEGMENTALIGNMENTBYTECOUNT get minimum segment alignment in bytes |
71 | * DKIOCGETMAXSEGMENTADDRESSABLEBITCOUNT get maximum segment width in bits |
72 | * |
73 | * DKIOCGETFEATURES get device's feature set |
74 | * DKIOCGETPHYSICALBLOCKSIZE get device's block size |
75 | * DKIOCGETCOMMANDPOOLSIZE get device's queue depth |
76 | * |
77 | * DKIOCGETPROVISIONSTATUS get device's block provision status |
78 | * DKIOCGETIOMINSATURATIONBYTECOUNT get minimum byte count to saturate storage bandwidth |
79 | * |
80 | * DKIOCGETERRORDESCRIPTION get description of any drive error |
81 | * |
82 | * DKIOCGETMAXSWAPWRITE get maximum swap file write per day in bytes |
83 | */ |
84 | |
85 | #define DK_FEATURE_BARRIER 0x00000002 |
86 | #define DK_FEATURE_PRIORITY 0x00000004 |
87 | #define DK_FEATURE_UNMAP 0x00000010 |
88 | |
89 | #define DK_SYNCHRONIZE_OPTION_BARRIER 0x00000002 |
90 | |
91 | typedef struct |
92 | { |
93 | uint64_t offset; |
94 | uint64_t length; |
95 | } dk_extent_t; |
96 | |
97 | typedef struct |
98 | { |
99 | char path[128]; |
100 | } dk_firmware_path_t; |
101 | |
102 | typedef struct |
103 | { |
104 | uint64_t blockCount; |
105 | uint32_t blockSize; |
106 | |
107 | uint8_t reserved0096[4]; /* reserved, clear to zero */ |
108 | } dk_format_capacity_t; |
109 | |
110 | typedef struct |
111 | { |
112 | dk_format_capacity_t * capacities; |
113 | uint32_t capacitiesCount; /* use zero to probe count */ |
114 | |
115 | #ifdef __LP64__ |
116 | uint8_t reserved0096[4]; /* reserved, clear to zero */ |
117 | #else /* !__LP64__ */ |
118 | uint8_t reserved0064[8]; /* reserved, clear to zero */ |
119 | #endif /* !__LP64__ */ |
120 | } dk_format_capacities_t; |
121 | |
122 | typedef struct |
123 | { |
124 | uint64_t offset; |
125 | uint64_t length; |
126 | |
127 | uint32_t options; |
128 | |
129 | uint8_t reserved0160[4]; /* reserved, clear to zero */ |
130 | } dk_synchronize_t; |
131 | |
132 | typedef struct |
133 | { |
134 | dk_extent_t * extents; |
135 | uint32_t extentsCount; |
136 | |
137 | uint32_t options; |
138 | |
139 | #ifndef __LP64__ |
140 | uint8_t reserved0096[4]; /* reserved, clear to zero */ |
141 | #endif /* !__LP64__ */ |
142 | } dk_unmap_t; |
143 | |
144 | |
145 | typedef struct |
146 | { |
147 | uint64_t flags; |
148 | uint64_t hotfile_size; /* in bytes */ |
149 | uint64_t hibernate_minsize; |
150 | uint64_t swapfile_pinning; |
151 | |
152 | uint64_t padding[4]; |
153 | } dk_corestorage_info_t; |
154 | |
155 | #define DK_CORESTORAGE_PIN_YOUR_METADATA 0x00000001 |
156 | #define DK_CORESTORAGE_ENABLE_HOTFILES 0x00000002 |
157 | #define DK_CORESTORAGE_PIN_YOUR_SWAPFILE 0x00000004 |
158 | |
159 | #define DK_PROVISION_TYPE_MAPPED 0x00 |
160 | #define DK_PROVISION_TYPE_DEALLOCATED 0x01 |
161 | #define DK_PROVISION_TYPE_ANCHORED 0x02 |
162 | |
163 | typedef struct |
164 | { |
165 | uint64_t offset; |
166 | uint64_t length; |
167 | uint8_t provisionType; |
168 | uint8_t reserved[7]; |
169 | } dk_provision_extent_t; |
170 | |
171 | typedef struct |
172 | { |
173 | uint64_t offset; /* input: logical byte offset */ |
174 | uint64_t length; /* input: byte length, 0 for whole length */ |
175 | uint64_t options; /* reserved, clear to zero */ |
176 | uint32_t reserved; /* not used */ |
177 | uint32_t extentsCount; /* input/output: count for extents */ |
178 | dk_provision_extent_t * extents; /* output: provision extents */ |
179 | } dk_provision_status_t; |
180 | |
181 | typedef struct |
182 | { |
183 | uint64_t options; /* reserved, clear to zero */ |
184 | uint64_t reserved; /* reserved, clear to zero */ |
185 | uint64_t description_size; |
186 | char * description; |
187 | } dk_error_description_t; |
188 | |
189 | |
190 | #ifdef KERNEL |
191 | #ifdef PRIVATE |
192 | |
193 | /* Definitions of option bits for dk_unmap_t */ |
194 | #define _DK_UNMAP_INITIALIZE 0x00000100 |
195 | |
196 | #endif /* PRIVATE */ |
197 | #endif /* KERNEL */ |
198 | |
199 | #define DKIOCEJECT _IO('d', 21) |
200 | #define DKIOCSYNCHRONIZE _IOW('d', 22, dk_synchronize_t) |
201 | |
202 | #define DKIOCFORMAT _IOW('d', 26, dk_format_capacity_t) |
203 | #define DKIOCGETFORMATCAPACITIES _IOWR('d', 26, dk_format_capacities_t) |
204 | |
205 | #define DKIOCGETBLOCKSIZE _IOR('d', 24, uint32_t) |
206 | #define DKIOCGETBLOCKCOUNT _IOR('d', 25, uint64_t) |
207 | #define DKIOCGETFIRMWAREPATH _IOR('d', 28, dk_firmware_path_t) |
208 | |
209 | #define DKIOCISFORMATTED _IOR('d', 23, uint32_t) |
210 | #define DKIOCISWRITABLE _IOR('d', 29, uint32_t) |
211 | |
212 | #define DKIOCREQUESTIDLE _IO('d', 30) |
213 | #define DKIOCUNMAP _IOW('d', 31, dk_unmap_t) |
214 | #define DKIOCCORESTORAGE _IOR('d', 32, dk_corestorage_info_t) |
215 | |
216 | #define DKIOCGETMAXBLOCKCOUNTREAD _IOR('d', 64, uint64_t) |
217 | #define DKIOCGETMAXBLOCKCOUNTWRITE _IOR('d', 65, uint64_t) |
218 | #define DKIOCGETMAXBYTECOUNTREAD _IOR('d', 70, uint64_t) |
219 | #define DKIOCGETMAXBYTECOUNTWRITE _IOR('d', 71, uint64_t) |
220 | |
221 | #define DKIOCGETMAXSEGMENTCOUNTREAD _IOR('d', 66, uint64_t) |
222 | #define DKIOCGETMAXSEGMENTCOUNTWRITE _IOR('d', 67, uint64_t) |
223 | #define DKIOCGETMAXSEGMENTBYTECOUNTREAD _IOR('d', 68, uint64_t) |
224 | #define DKIOCGETMAXSEGMENTBYTECOUNTWRITE _IOR('d', 69, uint64_t) |
225 | |
226 | #define DKIOCGETMINSEGMENTALIGNMENTBYTECOUNT _IOR('d', 74, uint64_t) |
227 | #define DKIOCGETMAXSEGMENTADDRESSABLEBITCOUNT _IOR('d', 75, uint64_t) |
228 | |
229 | #define DKIOCGETFEATURES _IOR('d', 76, uint32_t) |
230 | #define DKIOCGETPHYSICALBLOCKSIZE _IOR('d', 77, uint32_t) |
231 | #define DKIOCGETCOMMANDPOOLSIZE _IOR('d', 78, uint32_t) |
232 | |
233 | #define DKIOCGETPROVISIONSTATUS _IOWR('d', 79, dk_provision_status_t) |
234 | |
235 | #define DKIOCGETERRORDESCRIPTION _IOR('d', 80, dk_error_description_t) |
236 | |
237 | #define DKIOCSYNCHRONIZECACHE _IO('d', 22) |
238 | |
239 | #ifdef KERNEL |
240 | #define DK_FEATURE_FORCE_UNIT_ACCESS 0x00000001 |
241 | |
242 | #define DK_ENCRYPTION_TYPE_AES_CBC 1 |
243 | #define DK_ENCRYPTION_TYPE_AES_XEX 2 |
244 | #define DK_ENCRYPTION_TYPE_AES_XTS 3 |
245 | |
246 | #define DK_TIER_MASK 0xC0 |
247 | #define DK_TIER_SHIFT 6 |
248 | |
249 | #define DK_TIER_TO_PRIORITY(tier) (((tier) << DK_TIER_SHIFT) | ~DK_TIER_MASK) |
250 | #define DK_PRIORITY_TO_TIER(priority) ((priority) >> DK_TIER_SHIFT) |
251 | |
252 | typedef struct |
253 | { |
254 | uint64_t offset; |
255 | uint64_t length; |
256 | |
257 | uint8_t reserved0128[12]; /* reserved, clear to zero */ |
258 | |
259 | dev_t dev; |
260 | } dk_physical_extent_t; |
261 | |
262 | typedef struct |
263 | { |
264 | dk_extent_t * extents; |
265 | uint32_t extentsCount; |
266 | |
267 | uint8_t tier; |
268 | |
269 | #ifdef __LP64__ |
270 | uint8_t reserved0104[3]; /* reserved, clear to zero */ |
271 | #else /* !__LP64__ */ |
272 | uint8_t reserved0072[7]; /* reserved, clear to zero */ |
273 | #endif /* !__LP64__ */ |
274 | } dk_set_tier_t; |
275 | |
276 | #define DKIOCSETBLOCKSIZE _IOW('d', 24, uint32_t) |
277 | #define DKIOCGETBSDUNIT _IOR('d', 27, uint32_t) |
278 | #define DKIOCISSOLIDSTATE _IOR('d', 79, uint32_t) |
279 | #define DKIOCISVIRTUAL _IOR('d', 72, uint32_t) |
280 | #define DKIOCGETBASE _IOR('d', 73, uint64_t) |
281 | #define DKIOCGETTHROTTLEMASK _IOR('d', 80, uint64_t) |
282 | #define DKIOCLOCKPHYSICALEXTENTS _IO('d', 81) |
283 | #define DKIOCGETPHYSICALEXTENT _IOWR('d', 82, dk_physical_extent_t) |
284 | #define DKIOCUNLOCKPHYSICALEXTENTS _IO('d', 83) |
285 | #define DKIOCSETTIER _IOW('d', 85, dk_set_tier_t) |
286 | #define DKIOCGETENCRYPTIONTYPE _IOR('d', 86, uint32_t) |
287 | #define DKIOCISLOWPOWERMODE _IOR('d', 87, uint32_t) |
288 | #define DKIOCGETIOMINSATURATIONBYTECOUNT _IOR('d', 88, uint32_t) |
289 | |
290 | #ifdef XNU_KERNEL_PRIVATE |
291 | typedef struct |
292 | { |
293 | boolean_t mi_mdev; /* Is this a memdev device? */ |
294 | boolean_t mi_phys; /* Physical memory? */ |
295 | uint32_t mi_base; /* Base page number of the device? */ |
296 | uint64_t mi_size; /* Size of the device (in ) */ |
297 | } dk_memdev_info_t; |
298 | |
299 | typedef dk_memdev_info_t memdev_info_t; |
300 | |
301 | #define DKIOCGETMEMDEVINFO _IOR('d', 90, dk_memdev_info_t) |
302 | #endif /* XNU_KERNEL_PRIVATE */ |
303 | #ifdef PRIVATE |
304 | typedef struct _dk_cs_pin { |
305 | dk_extent_t cp_extent; |
306 | int64_t cp_flags; |
307 | } _dk_cs_pin_t; |
308 | /* The following are modifiers to _DKIOCCSPINEXTENT/cp_flags operation */ |
309 | #define _DKIOCCSPINTOFASTMEDIA (0) /* Pin extent to the fast (SSD) media */ |
310 | #define _DKIOCCSPINFORHIBERNATION (1 << 0) /* Pin of hibernation file, content not preserved */ |
311 | #define _DKIOCCSPINDISCARDBLACKLIST (1 << 1) /* Hibernation complete/error, stop blacklisting */ |
312 | #define _DKIOCCSPINTOSLOWMEDIA (1 << 2) /* Pin extent to the slow (HDD) media */ |
313 | #define _DKIOCCSTEMPORARYPIN (1 << 3) /* Relocate, but do not pin, to indicated media */ |
314 | #define _DKIOCCSHIBERNATEIMGSIZE (1 << 4) /* Anticipate/Max size of the upcoming hibernate */ |
315 | #define _DKIOCCSPINFORSWAPFILE (1 << 5) /* Pin of swap file, content not preserved */ |
316 | |
317 | #define _DKIOCCSSETLVNAME _IOW('d', 198, char[256]) |
318 | #define _DKIOCCSPINEXTENT _IOW('d', 199, _dk_cs_pin_t) |
319 | #define _DKIOCCSUNPINEXTENT _IOW('d', 200, _dk_cs_pin_t) |
320 | #define _DKIOCGETMIGRATIONUNITBYTESIZE _IOR('d', 201, uint32_t) |
321 | |
322 | typedef struct _dk_cs_map { |
323 | dk_extent_t cm_extent; |
324 | uint64_t cm_bytes_mapped; |
325 | } _dk_cs_map_t; |
326 | |
327 | typedef struct _dk_cs_unmap { |
328 | dk_extent_t *extents; |
329 | uint32_t extentsCount; |
330 | uint32_t options; |
331 | } _dk_cs_unmap_t; |
332 | |
333 | #define _DKIOCCSMAP _IOWR('d', 202, _dk_cs_map_t) |
334 | // No longer used: _DKIOCCSSETFSVNODE (203) & _DKIOCCSGETFREEBYTES (204) |
335 | #define _DKIOCCSUNMAP _IOWR('d', 205, _dk_cs_unmap_t) |
336 | |
337 | typedef enum { |
338 | DK_APFS_ONE_DEVICE = 1, |
339 | DK_APFS_FUSION |
340 | } dk_apfs_flavour_t; |
341 | |
342 | #define DKIOCGETAPFSFLAVOUR _IOR('d', 91, dk_apfs_flavour_t) |
343 | |
344 | // Extent's offset and length returned in bytes |
345 | typedef struct dk_apfs_wbc_range { |
346 | dev_t dev; // Physical device for extents |
347 | uint32_t count; // Number of extents |
348 | dk_extent_t extents[2]; // Addresses are relative to device we return |
349 | } dk_apfs_wbc_range_t; |
350 | |
351 | #define DKIOCAPFSGETWBCRANGE _IOR('d', 92, dk_apfs_wbc_range_t) |
352 | #define DKIOCAPFSRELEASEWBCRANGE _IO('d', 93) |
353 | |
354 | #define DKIOCGETMAXSWAPWRITE _IOR('d', 94, uint64_t) |
355 | |
356 | #endif /* PRIVATE */ |
357 | #endif /* KERNEL */ |
358 | |
359 | #ifdef PRIVATE |
360 | #if TARGET_OS_EMBEDDED |
361 | #define _DKIOCSETSTATIC _IO('d', 84) |
362 | #endif /* TARGET_OS_EMBEDDED */ |
363 | #endif /* PRIVATE */ |
364 | |
365 | #endif /* _SYS_DISK_H_ */ |
366 | |