1*f6217f89SApple OSS Distributions /* 2*f6217f89SApple OSS Distributions * Copyright (c) 1998-2025 Apple Computer, Inc. All rights reserved. 3*f6217f89SApple OSS Distributions * 4*f6217f89SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*f6217f89SApple OSS Distributions * 6*f6217f89SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*f6217f89SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*f6217f89SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*f6217f89SApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*f6217f89SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*f6217f89SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*f6217f89SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*f6217f89SApple OSS Distributions * terms of an Apple operating system software license agreement. 14*f6217f89SApple OSS Distributions * 15*f6217f89SApple OSS Distributions * Please obtain a copy of the License at 16*f6217f89SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*f6217f89SApple OSS Distributions * 18*f6217f89SApple OSS Distributions * The Original Code and all software distributed under the License are 19*f6217f89SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*f6217f89SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*f6217f89SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*f6217f89SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*f6217f89SApple OSS Distributions * Please see the License for the specific language governing rights and 24*f6217f89SApple OSS Distributions * limitations under the License. 25*f6217f89SApple OSS Distributions * 26*f6217f89SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*f6217f89SApple OSS Distributions */ 28*f6217f89SApple OSS Distributions 29*f6217f89SApple OSS Distributions #ifndef _SYS_DISK_H_ 30*f6217f89SApple OSS Distributions #define _SYS_DISK_H_ 31*f6217f89SApple OSS Distributions 32*f6217f89SApple OSS Distributions #include <stdint.h> 33*f6217f89SApple OSS Distributions #include <sys/ioctl.h> 34*f6217f89SApple OSS Distributions 35*f6217f89SApple OSS Distributions /* 36*f6217f89SApple OSS Distributions * Definitions 37*f6217f89SApple OSS Distributions * 38*f6217f89SApple OSS Distributions * ioctl description 39*f6217f89SApple OSS Distributions * ------------------------------------- --------------------------------------- 40*f6217f89SApple OSS Distributions * DKIOCEJECT eject media 41*f6217f89SApple OSS Distributions * DKIOCSYNCHRONIZE flush media 42*f6217f89SApple OSS Distributions * 43*f6217f89SApple OSS Distributions * DKIOCFORMAT format media 44*f6217f89SApple OSS Distributions * DKIOCGETFORMATCAPACITIES get media's formattable capacities 45*f6217f89SApple OSS Distributions * 46*f6217f89SApple OSS Distributions * DKIOCGETBLOCKSIZE get media's block size 47*f6217f89SApple OSS Distributions * DKIOCGETBLOCKCOUNT get media's block count 48*f6217f89SApple OSS Distributions * DKIOCGETFIRMWAREPATH get media's firmware path 49*f6217f89SApple OSS Distributions * 50*f6217f89SApple OSS Distributions * DKIOCISFORMATTED is media formatted? 51*f6217f89SApple OSS Distributions * DKIOCISWRITABLE is media writable? 52*f6217f89SApple OSS Distributions * 53*f6217f89SApple OSS Distributions * DKIOCREQUESTIDLE idle media 54*f6217f89SApple OSS Distributions * DKIOCUNMAP delete unused data 55*f6217f89SApple OSS Distributions * 56*f6217f89SApple OSS Distributions * DKIOCGETLOCATION get device's physical location 57*f6217f89SApple OSS Distributions * 58*f6217f89SApple OSS Distributions * DKIOCGETMAXBLOCKCOUNTREAD get maximum block count for reads 59*f6217f89SApple OSS Distributions * DKIOCGETMAXBLOCKCOUNTWRITE get maximum block count for writes 60*f6217f89SApple OSS Distributions * DKIOCGETMAXBYTECOUNTREAD get maximum byte count for reads 61*f6217f89SApple OSS Distributions * DKIOCGETMAXBYTECOUNTWRITE get maximum byte count for writes 62*f6217f89SApple OSS Distributions * 63*f6217f89SApple OSS Distributions * DKIOCGETMAXSEGMENTCOUNTREAD get maximum segment count for reads 64*f6217f89SApple OSS Distributions * DKIOCGETMAXSEGMENTCOUNTWRITE get maximum segment count for writes 65*f6217f89SApple OSS Distributions * DKIOCGETMAXSEGMENTBYTECOUNTREAD get maximum segment byte count for reads 66*f6217f89SApple OSS Distributions * DKIOCGETMAXSEGMENTBYTECOUNTWRITE get maximum segment byte count for writes 67*f6217f89SApple OSS Distributions * 68*f6217f89SApple OSS Distributions * DKIOCGETMINSEGMENTALIGNMENTBYTECOUNT get minimum segment alignment in bytes 69*f6217f89SApple OSS Distributions * DKIOCGETMAXSEGMENTADDRESSABLEBITCOUNT get maximum segment width in bits 70*f6217f89SApple OSS Distributions * 71*f6217f89SApple OSS Distributions * DKIOCGETFEATURES get device's feature set 72*f6217f89SApple OSS Distributions * DKIOCGETPHYSICALBLOCKSIZE get device's block size 73*f6217f89SApple OSS Distributions * DKIOCGETCOMMANDPOOLSIZE get device's queue depth 74*f6217f89SApple OSS Distributions * 75*f6217f89SApple OSS Distributions * DKIOCGETPROVISIONSTATUS get device's block provision status 76*f6217f89SApple OSS Distributions * DKIOCGETIOMINSATURATIONBYTECOUNT get minimum byte count to saturate storage bandwidth 77*f6217f89SApple OSS Distributions * 78*f6217f89SApple OSS Distributions * DKIOCGETERRORDESCRIPTION get description of any drive error 79*f6217f89SApple OSS Distributions * 80*f6217f89SApple OSS Distributions * DKIOCGETMAXSWAPWRITE get maximum swap file write per day in bytes 81*f6217f89SApple OSS Distributions */ 82*f6217f89SApple OSS Distributions 83*f6217f89SApple OSS Distributions #define DK_FEATURE_BARRIER 0x00000002 84*f6217f89SApple OSS Distributions #define DK_FEATURE_PRIORITY 0x00000004 85*f6217f89SApple OSS Distributions #define DK_FEATURE_UNMAP 0x00000010 86*f6217f89SApple OSS Distributions 87*f6217f89SApple OSS Distributions #define DK_SYNCHRONIZE_OPTION_BARRIER 0x00000002 88*f6217f89SApple OSS Distributions 89*f6217f89SApple OSS Distributions typedef struct{ 90*f6217f89SApple OSS Distributions uint64_t offset; 91*f6217f89SApple OSS Distributions uint64_t length; 92*f6217f89SApple OSS Distributions } dk_extent_t; 93*f6217f89SApple OSS Distributions 94*f6217f89SApple OSS Distributions typedef struct{ 95*f6217f89SApple OSS Distributions char path[128]; 96*f6217f89SApple OSS Distributions } dk_firmware_path_t; 97*f6217f89SApple OSS Distributions 98*f6217f89SApple OSS Distributions typedef struct{ 99*f6217f89SApple OSS Distributions uint64_t blockCount; 100*f6217f89SApple OSS Distributions uint32_t blockSize; 101*f6217f89SApple OSS Distributions 102*f6217f89SApple OSS Distributions uint8_t reserved0096[4]; /* reserved, clear to zero */ 103*f6217f89SApple OSS Distributions } dk_format_capacity_t; 104*f6217f89SApple OSS Distributions 105*f6217f89SApple OSS Distributions typedef struct{ 106*f6217f89SApple OSS Distributions dk_format_capacity_t * capacities; 107*f6217f89SApple OSS Distributions uint32_t capacitiesCount; /* use zero to probe count */ 108*f6217f89SApple OSS Distributions 109*f6217f89SApple OSS Distributions #ifdef __LP64__ 110*f6217f89SApple OSS Distributions uint8_t reserved0096[4]; /* reserved, clear to zero */ 111*f6217f89SApple OSS Distributions #else /* !__LP64__ */ 112*f6217f89SApple OSS Distributions uint8_t reserved0064[8]; /* reserved, clear to zero */ 113*f6217f89SApple OSS Distributions #endif /* !__LP64__ */ 114*f6217f89SApple OSS Distributions } dk_format_capacities_t; 115*f6217f89SApple OSS Distributions 116*f6217f89SApple OSS Distributions typedef struct{ 117*f6217f89SApple OSS Distributions uint64_t offset; 118*f6217f89SApple OSS Distributions uint64_t length; 119*f6217f89SApple OSS Distributions 120*f6217f89SApple OSS Distributions uint32_t options; 121*f6217f89SApple OSS Distributions 122*f6217f89SApple OSS Distributions uint8_t reserved0160[4]; /* reserved, clear to zero */ 123*f6217f89SApple OSS Distributions } dk_synchronize_t; 124*f6217f89SApple OSS Distributions 125*f6217f89SApple OSS Distributions typedef struct{ 126*f6217f89SApple OSS Distributions dk_extent_t * extents; 127*f6217f89SApple OSS Distributions uint32_t extentsCount; 128*f6217f89SApple OSS Distributions 129*f6217f89SApple OSS Distributions uint32_t options; 130*f6217f89SApple OSS Distributions 131*f6217f89SApple OSS Distributions #ifndef __LP64__ 132*f6217f89SApple OSS Distributions uint8_t reserved0096[4]; /* reserved, clear to zero */ 133*f6217f89SApple OSS Distributions #endif /* !__LP64__ */ 134*f6217f89SApple OSS Distributions } dk_unmap_t; 135*f6217f89SApple OSS Distributions 136*f6217f89SApple OSS Distributions typedef struct{ 137*f6217f89SApple OSS Distributions uint64_t flags; 138*f6217f89SApple OSS Distributions uint64_t hotfile_size; /* in bytes */ 139*f6217f89SApple OSS Distributions uint64_t hibernate_minsize; 140*f6217f89SApple OSS Distributions uint64_t swapfile_pinning; 141*f6217f89SApple OSS Distributions 142*f6217f89SApple OSS Distributions uint64_t padding[4]; 143*f6217f89SApple OSS Distributions } dk_corestorage_info_t; 144*f6217f89SApple OSS Distributions 145*f6217f89SApple OSS Distributions #define DK_CORESTORAGE_PIN_YOUR_METADATA 0x00000001 146*f6217f89SApple OSS Distributions #define DK_CORESTORAGE_ENABLE_HOTFILES 0x00000002 147*f6217f89SApple OSS Distributions #define DK_CORESTORAGE_PIN_YOUR_SWAPFILE 0x00000004 148*f6217f89SApple OSS Distributions 149*f6217f89SApple OSS Distributions #define DK_PROVISION_TYPE_MAPPED 0x00 150*f6217f89SApple OSS Distributions #define DK_PROVISION_TYPE_DEALLOCATED 0x01 151*f6217f89SApple OSS Distributions #define DK_PROVISION_TYPE_ANCHORED 0x02 152*f6217f89SApple OSS Distributions 153*f6217f89SApple OSS Distributions typedef struct{ 154*f6217f89SApple OSS Distributions uint64_t offset; 155*f6217f89SApple OSS Distributions uint64_t length; 156*f6217f89SApple OSS Distributions uint8_t provisionType; 157*f6217f89SApple OSS Distributions uint8_t reserved[7]; 158*f6217f89SApple OSS Distributions } dk_provision_extent_t; 159*f6217f89SApple OSS Distributions 160*f6217f89SApple OSS Distributions typedef struct{ 161*f6217f89SApple OSS Distributions uint64_t offset; /* input: logical byte offset */ 162*f6217f89SApple OSS Distributions uint64_t length; /* input: byte length, 0 for whole length */ 163*f6217f89SApple OSS Distributions uint64_t options; /* reserved, clear to zero */ 164*f6217f89SApple OSS Distributions uint32_t reserved; /* not used */ 165*f6217f89SApple OSS Distributions uint32_t extentsCount; /* input/output: count for extents */ 166*f6217f89SApple OSS Distributions dk_provision_extent_t * extents; /* output: provision extents */ 167*f6217f89SApple OSS Distributions } dk_provision_status_t; 168*f6217f89SApple OSS Distributions 169*f6217f89SApple OSS Distributions typedef struct{ 170*f6217f89SApple OSS Distributions uint64_t options; /* reserved, clear to zero */ 171*f6217f89SApple OSS Distributions uint64_t reserved; /* reserved, clear to zero */ 172*f6217f89SApple OSS Distributions uint64_t description_size; 173*f6217f89SApple OSS Distributions char * description; 174*f6217f89SApple OSS Distributions } dk_error_description_t; 175*f6217f89SApple OSS Distributions 176*f6217f89SApple OSS Distributions #define DK_LOCATION_INTERNAL 0x00000000 177*f6217f89SApple OSS Distributions #define DK_LOCATION_EXTERNAL 0x00000001 178*f6217f89SApple OSS Distributions 179*f6217f89SApple OSS Distributions #define DKIOCEJECT _IO('d', 21) 180*f6217f89SApple OSS Distributions #define DKIOCSYNCHRONIZE _IOW('d', 22, dk_synchronize_t) 181*f6217f89SApple OSS Distributions 182*f6217f89SApple OSS Distributions #define DKIOCFORMAT _IOW('d', 26, dk_format_capacity_t) 183*f6217f89SApple OSS Distributions #define DKIOCGETFORMATCAPACITIES _IOWR('d', 26, dk_format_capacities_t) 184*f6217f89SApple OSS Distributions 185*f6217f89SApple OSS Distributions #define DKIOCGETBLOCKSIZE _IOR('d', 24, uint32_t) 186*f6217f89SApple OSS Distributions #define DKIOCGETBLOCKCOUNT _IOR('d', 25, uint64_t) 187*f6217f89SApple OSS Distributions #define DKIOCGETFIRMWAREPATH _IOR('d', 28, dk_firmware_path_t) 188*f6217f89SApple OSS Distributions 189*f6217f89SApple OSS Distributions #define DKIOCISFORMATTED _IOR('d', 23, uint32_t) 190*f6217f89SApple OSS Distributions #define DKIOCISWRITABLE _IOR('d', 29, uint32_t) 191*f6217f89SApple OSS Distributions 192*f6217f89SApple OSS Distributions #define DKIOCREQUESTIDLE _IO('d', 30) 193*f6217f89SApple OSS Distributions #define DKIOCUNMAP _IOW('d', 31, dk_unmap_t) 194*f6217f89SApple OSS Distributions #define DKIOCCORESTORAGE _IOR('d', 32, dk_corestorage_info_t) 195*f6217f89SApple OSS Distributions 196*f6217f89SApple OSS Distributions #define DKIOCGETLOCATION _IOR('d', 33, uint64_t) 197*f6217f89SApple OSS Distributions 198*f6217f89SApple OSS Distributions #define DKIOCGETMAXBLOCKCOUNTREAD _IOR('d', 64, uint64_t) 199*f6217f89SApple OSS Distributions #define DKIOCGETMAXBLOCKCOUNTWRITE _IOR('d', 65, uint64_t) 200*f6217f89SApple OSS Distributions #define DKIOCGETMAXBYTECOUNTREAD _IOR('d', 70, uint64_t) 201*f6217f89SApple OSS Distributions #define DKIOCGETMAXBYTECOUNTWRITE _IOR('d', 71, uint64_t) 202*f6217f89SApple OSS Distributions 203*f6217f89SApple OSS Distributions #define DKIOCGETMAXSEGMENTCOUNTREAD _IOR('d', 66, uint64_t) 204*f6217f89SApple OSS Distributions #define DKIOCGETMAXSEGMENTCOUNTWRITE _IOR('d', 67, uint64_t) 205*f6217f89SApple OSS Distributions #define DKIOCGETMAXSEGMENTBYTECOUNTREAD _IOR('d', 68, uint64_t) 206*f6217f89SApple OSS Distributions #define DKIOCGETMAXSEGMENTBYTECOUNTWRITE _IOR('d', 69, uint64_t) 207*f6217f89SApple OSS Distributions 208*f6217f89SApple OSS Distributions #define DKIOCGETMINSEGMENTALIGNMENTBYTECOUNT _IOR('d', 74, uint64_t) 209*f6217f89SApple OSS Distributions #define DKIOCGETMAXSEGMENTADDRESSABLEBITCOUNT _IOR('d', 75, uint64_t) 210*f6217f89SApple OSS Distributions 211*f6217f89SApple OSS Distributions #define DKIOCGETFEATURES _IOR('d', 76, uint32_t) 212*f6217f89SApple OSS Distributions #define DKIOCGETPHYSICALBLOCKSIZE _IOR('d', 77, uint32_t) 213*f6217f89SApple OSS Distributions #define DKIOCGETCOMMANDPOOLSIZE _IOR('d', 78, uint32_t) 214*f6217f89SApple OSS Distributions 215*f6217f89SApple OSS Distributions #define DKIOCGETPROVISIONSTATUS _IOWR('d', 79, dk_provision_status_t) 216*f6217f89SApple OSS Distributions 217*f6217f89SApple OSS Distributions #define DKIOCGETERRORDESCRIPTION _IOR('d', 80, dk_error_description_t) 218*f6217f89SApple OSS Distributions 219*f6217f89SApple OSS Distributions #define DKIOCSYNCHRONIZECACHE _IO('d', 22) 220*f6217f89SApple OSS Distributions 221*f6217f89SApple OSS Distributions #ifdef KERNEL 222*f6217f89SApple OSS Distributions #define DK_FEATURE_FORCE_UNIT_ACCESS 0x00000001 223*f6217f89SApple OSS Distributions 224*f6217f89SApple OSS Distributions #define DK_ENCRYPTION_TYPE_AES_CBC 1 225*f6217f89SApple OSS Distributions #define DK_ENCRYPTION_TYPE_AES_XEX 2 226*f6217f89SApple OSS Distributions #define DK_ENCRYPTION_TYPE_AES_XTS 3 227*f6217f89SApple OSS Distributions 228*f6217f89SApple OSS Distributions #define DK_TIER_MASK 0xC0 229*f6217f89SApple OSS Distributions #define DK_TIER_SHIFT 6 230*f6217f89SApple OSS Distributions 231*f6217f89SApple OSS Distributions #define DK_TIER_TO_PRIORITY(tier) (((tier) << DK_TIER_SHIFT) | ~DK_TIER_MASK) 232*f6217f89SApple OSS Distributions #define DK_PRIORITY_TO_TIER(priority) ((priority) >> DK_TIER_SHIFT) 233*f6217f89SApple OSS Distributions 234*f6217f89SApple OSS Distributions typedef struct{ 235*f6217f89SApple OSS Distributions uint64_t offset; 236*f6217f89SApple OSS Distributions uint64_t length; 237*f6217f89SApple OSS Distributions 238*f6217f89SApple OSS Distributions uint8_t reserved0128[12]; /* reserved, clear to zero */ 239*f6217f89SApple OSS Distributions 240*f6217f89SApple OSS Distributions dev_t dev; 241*f6217f89SApple OSS Distributions } dk_physical_extent_t; 242*f6217f89SApple OSS Distributions 243*f6217f89SApple OSS Distributions typedef struct{ 244*f6217f89SApple OSS Distributions dk_extent_t * extents; 245*f6217f89SApple OSS Distributions uint32_t extentsCount; 246*f6217f89SApple OSS Distributions 247*f6217f89SApple OSS Distributions uint8_t tier; 248*f6217f89SApple OSS Distributions 249*f6217f89SApple OSS Distributions #ifdef __LP64__ 250*f6217f89SApple OSS Distributions uint8_t reserved0104[3]; /* reserved, clear to zero */ 251*f6217f89SApple OSS Distributions #else /* !__LP64__ */ 252*f6217f89SApple OSS Distributions uint8_t reserved0072[7]; /* reserved, clear to zero */ 253*f6217f89SApple OSS Distributions #endif /* !__LP64__ */ 254*f6217f89SApple OSS Distributions } dk_set_tier_t; 255*f6217f89SApple OSS Distributions 256*f6217f89SApple OSS Distributions #define DKIOCSETBLOCKSIZE _IOW('d', 24, uint32_t) 257*f6217f89SApple OSS Distributions #define DKIOCGETBSDUNIT _IOR('d', 27, uint32_t) 258*f6217f89SApple OSS Distributions #define DKIOCISSOLIDSTATE _IOR('d', 79, uint32_t) 259*f6217f89SApple OSS Distributions #define DKIOCISVIRTUAL _IOR('d', 72, uint32_t) 260*f6217f89SApple OSS Distributions #define DKIOCGETBASE _IOR('d', 73, uint64_t) 261*f6217f89SApple OSS Distributions #define DKIOCGETTHROTTLEMASK _IOR('d', 80, uint64_t) 262*f6217f89SApple OSS Distributions #define DKIOCLOCKPHYSICALEXTENTS _IO('d', 81) 263*f6217f89SApple OSS Distributions #define DKIOCGETPHYSICALEXTENT _IOWR('d', 82, dk_physical_extent_t) 264*f6217f89SApple OSS Distributions #define DKIOCUNLOCKPHYSICALEXTENTS _IO('d', 83) 265*f6217f89SApple OSS Distributions #define DKIOCSETTIER _IOW('d', 85, dk_set_tier_t) 266*f6217f89SApple OSS Distributions #define DKIOCGETENCRYPTIONTYPE _IOR('d', 86, uint32_t) 267*f6217f89SApple OSS Distributions #define DKIOCISLOWPOWERMODE _IOR('d', 87, uint32_t) 268*f6217f89SApple OSS Distributions #define DKIOCGETIOMINSATURATIONBYTECOUNT _IOR('d', 88, uint32_t) 269*f6217f89SApple OSS Distributions #endif /* KERNEL */ 270*f6217f89SApple OSS Distributions 271*f6217f89SApple OSS Distributions #ifdef PRIVATE 272*f6217f89SApple OSS Distributions /* See disk_private.h for additional ioctls */ 273*f6217f89SApple OSS Distributions #ifndef MODULES_SUPPORTED 274*f6217f89SApple OSS Distributions #include <sys/disk_private.h> 275*f6217f89SApple OSS Distributions #endif /* !MODULES_SUPPORTED */ 276*f6217f89SApple OSS Distributions #endif /* PRIVATE */ 277*f6217f89SApple OSS Distributions 278*f6217f89SApple OSS Distributions #endif /* _SYS_DISK_H_ */ 279