xref: /xnu-12377.81.4/bsd/sys/disk.h (revision 043036a2b3718f7f0be807e2870f8f47d3fa0796)
1 /*
2  * Copyright (c) 1998-2025 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 /*
36  * Definitions
37  *
38  * ioctl                                 description
39  * ------------------------------------- ---------------------------------------
40  * DKIOCEJECT                            eject media
41  * DKIOCSYNCHRONIZE                      flush media
42  *
43  * DKIOCFORMAT                           format media
44  * DKIOCGETFORMATCAPACITIES              get media's formattable capacities
45  *
46  * DKIOCGETBLOCKSIZE                     get media's block size
47  * DKIOCGETBLOCKCOUNT                    get media's block count
48  * DKIOCGETFIRMWAREPATH                  get media's firmware path
49  *
50  * DKIOCISFORMATTED                      is media formatted?
51  * DKIOCISWRITABLE                       is media writable?
52  *
53  * DKIOCREQUESTIDLE                      idle media
54  * DKIOCUNMAP                            delete unused data
55  *
56  * DKIOCGETLOCATION                      get device's physical location
57  *
58  * DKIOCGETMAXBLOCKCOUNTREAD             get maximum block count for reads
59  * DKIOCGETMAXBLOCKCOUNTWRITE            get maximum block count for writes
60  * DKIOCGETMAXBYTECOUNTREAD              get maximum byte count for reads
61  * DKIOCGETMAXBYTECOUNTWRITE             get maximum byte count for writes
62  *
63  * DKIOCGETMAXSEGMENTCOUNTREAD           get maximum segment count for reads
64  * DKIOCGETMAXSEGMENTCOUNTWRITE          get maximum segment count for writes
65  * DKIOCGETMAXSEGMENTBYTECOUNTREAD       get maximum segment byte count for reads
66  * DKIOCGETMAXSEGMENTBYTECOUNTWRITE      get maximum segment byte count for writes
67  *
68  * DKIOCGETMINSEGMENTALIGNMENTBYTECOUNT  get minimum segment alignment in bytes
69  * DKIOCGETMAXSEGMENTADDRESSABLEBITCOUNT get maximum segment width in bits
70  *
71  * DKIOCGETFEATURES                      get device's feature set
72  * DKIOCGETPHYSICALBLOCKSIZE             get device's block size
73  * DKIOCGETCOMMANDPOOLSIZE               get device's queue depth
74  *
75  * DKIOCGETPROVISIONSTATUS               get device's block provision status
76  * DKIOCGETIOMINSATURATIONBYTECOUNT      get minimum byte count to saturate storage bandwidth
77  *
78  * DKIOCGETERRORDESCRIPTION              get description of any drive error
79  *
80  * DKIOCGETMAXSWAPWRITE                  get maximum swap file write per day in bytes
81  */
82 
83 #define DK_FEATURE_BARRIER                    0x00000002
84 #define DK_FEATURE_PRIORITY                   0x00000004
85 #define DK_FEATURE_UNMAP                      0x00000010
86 
87 #define DK_SYNCHRONIZE_OPTION_BARRIER         0x00000002
88 
89 typedef struct{
90 	uint64_t               offset;
91 	uint64_t               length;
92 } dk_extent_t;
93 
94 typedef struct{
95 	char                   path[128];
96 } dk_firmware_path_t;
97 
98 typedef struct{
99 	uint64_t               blockCount;
100 	uint32_t               blockSize;
101 
102 	uint8_t                reserved0096[4];    /* reserved, clear to zero */
103 } dk_format_capacity_t;
104 
105 typedef struct{
106 	dk_format_capacity_t * capacities;
107 	uint32_t               capacitiesCount;    /* use zero to probe count */
108 
109 #ifdef __LP64__
110 	uint8_t                reserved0096[4];    /* reserved, clear to zero */
111 #else /* !__LP64__ */
112 	uint8_t                reserved0064[8];    /* reserved, clear to zero */
113 #endif /* !__LP64__ */
114 } dk_format_capacities_t;
115 
116 typedef struct{
117 	uint64_t               offset;
118 	uint64_t               length;
119 
120 	uint32_t               options;
121 
122 	uint8_t                reserved0160[4];    /* reserved, clear to zero */
123 } dk_synchronize_t;
124 
125 typedef struct{
126 	dk_extent_t *          extents;
127 	uint32_t               extentsCount;
128 
129 	uint32_t               options;
130 
131 #ifndef __LP64__
132 	uint8_t                reserved0096[4];    /* reserved, clear to zero */
133 #endif /* !__LP64__ */
134 } dk_unmap_t;
135 
136 typedef struct{
137 	uint64_t           flags;
138 	uint64_t           hotfile_size;           /* in bytes */
139 	uint64_t           hibernate_minsize;
140 	uint64_t           swapfile_pinning;
141 
142 	uint64_t           padding[4];
143 } dk_corestorage_info_t;
144 
145 #define DK_CORESTORAGE_PIN_YOUR_METADATA        0x00000001
146 #define DK_CORESTORAGE_ENABLE_HOTFILES          0x00000002
147 #define DK_CORESTORAGE_PIN_YOUR_SWAPFILE        0x00000004
148 
149 #define DK_PROVISION_TYPE_MAPPED                0x00
150 #define DK_PROVISION_TYPE_DEALLOCATED           0x01
151 #define DK_PROVISION_TYPE_ANCHORED              0x02
152 
153 typedef struct{
154 	uint64_t           offset;
155 	uint64_t           length;
156 	uint8_t            provisionType;
157 	uint8_t            reserved[7];
158 } dk_provision_extent_t;
159 
160 typedef struct{
161 	uint64_t                offset;         /* input:        logical byte offset */
162 	uint64_t                length;         /* input:        byte length, 0 for whole length */
163 	uint64_t                options;        /*               reserved, clear to zero */
164 	uint32_t                reserved;       /*               not used */
165 	uint32_t                extentsCount;   /* input/output: count for extents */
166 	dk_provision_extent_t * extents;        /* output:       provision extents */
167 } dk_provision_status_t;
168 
169 typedef struct{
170 	uint64_t               options;        /*               reserved, clear to zero */
171 	uint64_t               reserved;       /*               reserved, clear to zero */
172 	uint64_t               description_size;
173 	char *                 description;
174 } dk_error_description_t;
175 
176 #define DK_LOCATION_INTERNAL                   0x00000000
177 #define DK_LOCATION_EXTERNAL                   0x00000001
178 
179 #define DKIOCEJECT                            _IO('d', 21)
180 #define DKIOCSYNCHRONIZE                      _IOW('d', 22, dk_synchronize_t)
181 
182 #define DKIOCFORMAT                           _IOW('d', 26, dk_format_capacity_t)
183 #define DKIOCGETFORMATCAPACITIES              _IOWR('d', 26, dk_format_capacities_t)
184 
185 #define DKIOCGETBLOCKSIZE                     _IOR('d', 24, uint32_t)
186 #define DKIOCGETBLOCKCOUNT                    _IOR('d', 25, uint64_t)
187 #define DKIOCGETFIRMWAREPATH                  _IOR('d', 28, dk_firmware_path_t)
188 
189 #define DKIOCISFORMATTED                      _IOR('d', 23, uint32_t)
190 #define DKIOCISWRITABLE                       _IOR('d', 29, uint32_t)
191 
192 #define DKIOCREQUESTIDLE                      _IO('d', 30)
193 #define DKIOCUNMAP                            _IOW('d', 31, dk_unmap_t)
194 #define DKIOCCORESTORAGE                      _IOR('d', 32, dk_corestorage_info_t)
195 
196 #define DKIOCGETLOCATION                      _IOR('d', 33, uint64_t)
197 
198 #define DKIOCGETMAXBLOCKCOUNTREAD             _IOR('d', 64, uint64_t)
199 #define DKIOCGETMAXBLOCKCOUNTWRITE            _IOR('d', 65, uint64_t)
200 #define DKIOCGETMAXBYTECOUNTREAD              _IOR('d', 70, uint64_t)
201 #define DKIOCGETMAXBYTECOUNTWRITE             _IOR('d', 71, uint64_t)
202 
203 #define DKIOCGETMAXSEGMENTCOUNTREAD           _IOR('d', 66, uint64_t)
204 #define DKIOCGETMAXSEGMENTCOUNTWRITE          _IOR('d', 67, uint64_t)
205 #define DKIOCGETMAXSEGMENTBYTECOUNTREAD       _IOR('d', 68, uint64_t)
206 #define DKIOCGETMAXSEGMENTBYTECOUNTWRITE      _IOR('d', 69, uint64_t)
207 
208 #define DKIOCGETMINSEGMENTALIGNMENTBYTECOUNT  _IOR('d', 74, uint64_t)
209 #define DKIOCGETMAXSEGMENTADDRESSABLEBITCOUNT _IOR('d', 75, uint64_t)
210 
211 #define DKIOCGETFEATURES                      _IOR('d', 76, uint32_t)
212 #define DKIOCGETPHYSICALBLOCKSIZE             _IOR('d', 77, uint32_t)
213 #define DKIOCGETCOMMANDPOOLSIZE               _IOR('d', 78, uint32_t)
214 
215 #define DKIOCGETPROVISIONSTATUS               _IOWR('d', 79, dk_provision_status_t)
216 
217 #define DKIOCGETERRORDESCRIPTION              _IOR('d', 80, dk_error_description_t)
218 
219 #define DKIOCSYNCHRONIZECACHE                 _IO('d', 22)
220 
221 #ifdef KERNEL
222 #define DK_FEATURE_FORCE_UNIT_ACCESS          0x00000001
223 
224 #define DK_ENCRYPTION_TYPE_AES_CBC            1
225 #define DK_ENCRYPTION_TYPE_AES_XEX            2
226 #define DK_ENCRYPTION_TYPE_AES_XTS            3
227 
228 #define DK_TIER_MASK                          0xC0
229 #define DK_TIER_SHIFT                         6
230 
231 #define DK_TIER_TO_PRIORITY(tier)             (((tier) << DK_TIER_SHIFT) | ~DK_TIER_MASK)
232 #define DK_PRIORITY_TO_TIER(priority)         ((priority) >> DK_TIER_SHIFT)
233 
234 typedef struct{
235 	uint64_t               offset;
236 	uint64_t               length;
237 
238 	uint8_t                reserved0128[12];   /* reserved, clear to zero */
239 
240 	dev_t                  dev;
241 } dk_physical_extent_t;
242 
243 typedef struct{
244 	dk_extent_t *          extents;
245 	uint32_t               extentsCount;
246 
247 	uint8_t                tier;
248 
249 #ifdef __LP64__
250 	uint8_t                reserved0104[3];    /* reserved, clear to zero */
251 #else /* !__LP64__ */
252 	uint8_t                reserved0072[7];    /* reserved, clear to zero */
253 #endif /* !__LP64__ */
254 } dk_set_tier_t;
255 
256 #define DKIOCSETBLOCKSIZE                     _IOW('d', 24, uint32_t)
257 #define DKIOCGETBSDUNIT                       _IOR('d', 27, uint32_t)
258 #define DKIOCISSOLIDSTATE                     _IOR('d', 79, uint32_t)
259 #define DKIOCISVIRTUAL                        _IOR('d', 72, uint32_t)
260 #define DKIOCGETBASE                          _IOR('d', 73, uint64_t)
261 #define DKIOCGETTHROTTLEMASK                  _IOR('d', 80, uint64_t)
262 #define DKIOCLOCKPHYSICALEXTENTS              _IO('d', 81)
263 #define DKIOCGETPHYSICALEXTENT                _IOWR('d', 82, dk_physical_extent_t)
264 #define DKIOCUNLOCKPHYSICALEXTENTS            _IO('d', 83)
265 #define DKIOCSETTIER                          _IOW('d', 85, dk_set_tier_t)
266 #define DKIOCGETENCRYPTIONTYPE                _IOR('d', 86, uint32_t)
267 #define DKIOCISLOWPOWERMODE                   _IOR('d', 87, uint32_t)
268 #define DKIOCGETIOMINSATURATIONBYTECOUNT      _IOR('d', 88, uint32_t)
269 #endif /* KERNEL */
270 
271 #ifdef PRIVATE
272 /* See disk_private.h for additional ioctls */
273 #ifndef MODULES_SUPPORTED
274 #include <sys/disk_private.h>
275 #endif /* !MODULES_SUPPORTED */
276 #endif /* PRIVATE */
277 
278 #endif  /* _SYS_DISK_H_ */
279