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