1/* 2 * Copyright (c) 1998-2014 Apple Inc. All rights reserved. 3 * 4 * @APPLE_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. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24/* 25 * This header contains the IOGUIDPartitionScheme class definition. 26 */ 27 28#ifndef _IOGUIDPARTITIONSCHEME_H 29#define _IOGUIDPARTITIONSCHEME_H 30 31#include <IOKit/IOTypes.h> 32 33/* 34 * kIOGUIDPartitionSchemeClass is the name of the IOGUIDPartitionScheme class. 35 */ 36 37#define kIOGUIDPartitionSchemeClass "IOGUIDPartitionScheme" 38 39/* 40 * GUID Partition Map Definitions 41 */ 42 43#include <uuid/uuid.h> 44 45#pragma pack(push, 1) /* (enable 8-bit struct packing) */ 46 47/* Partition map. */ 48 49struct gpt_hdr 50{ 51 uint8_t hdr_sig[8]; 52 uint32_t hdr_revision; 53 uint32_t hdr_size; 54 uint32_t hdr_crc_self; 55 uint32_t __reserved; 56 uint64_t hdr_lba_self; 57 uint64_t hdr_lba_alt; 58 uint64_t hdr_lba_start; 59 uint64_t hdr_lba_end; 60 uuid_t hdr_uuid; 61 uint64_t hdr_lba_table; 62 uint32_t hdr_entries; 63 uint32_t hdr_entsz; 64 uint32_t hdr_crc_table; 65 uint32_t padding; 66}; 67 68/* Partition map entry. */ 69 70struct gpt_ent 71{ 72 uuid_t ent_type; 73 uuid_t ent_uuid; 74 uint64_t ent_lba_start; 75 uint64_t ent_lba_end; 76 uint64_t ent_attr; 77 uint16_t ent_name[36]; 78}; 79 80/* Partition map signature (hdr_sig). */ 81 82#define GPT_HDR_SIG "EFI PART" 83 84/* Partition map version (hdr_revision). */ 85 86#define GPT_HDR_REVISION 0x00010000 87 88/* Partition map entry flags (ent_attr). */ 89 90#define GPT_ENT_ATTR_PLATFORM 0x00000001 91 92#pragma pack(pop) /* (reset to default struct packing) */ 93 94#ifdef KERNEL 95#ifdef __cplusplus 96 97/* 98 * Kernel 99 */ 100 101#include <IOKit/storage/IOPartitionScheme.h> 102 103/* 104 * Class 105 */ 106 107class IOGUIDPartitionScheme : public IOPartitionScheme 108{ 109 OSDeclareDefaultStructors(IOGUIDPartitionScheme); 110 111protected: 112 113 struct ExpansionData { /* */ }; 114 ExpansionData * _expansionData; 115 116 OSSet * _partitions; /* (set of media objects representing partitions) */ 117 118 /* 119 * Free all of this object's outstanding resources. 120 */ 121 122 virtual void free(void); 123 124 /* 125 * Scan the provider media for a GUID partition map. Returns the set 126 * of media objects representing each of the partitions (the retain for 127 * the set is passed to the caller), or null should no partition map be 128 * found. The default probe score can be adjusted up or down, based on 129 * the confidence of the scan. 130 */ 131 132 virtual OSSet * scan(SInt32 * score); 133 134 /* 135 * Ask whether the given partition is used. 136 */ 137 138 virtual bool isPartitionUsed(gpt_ent * partition); 139 140 /* 141 * Ask whether the given partition appears to be corrupt. A partition that 142 * is corrupt will cause the failure of the GUID partition map recognition 143 * altogether. 144 */ 145 146 virtual bool isPartitionCorrupt( gpt_ent * partition, 147 UInt32 partitionID ); 148 149 /* 150 * Ask whether the given partition appears to be invalid. A partition that 151 * is invalid will cause it to be skipped in the scan, but will not cause a 152 * failure of the GUID partition map recognition. 153 */ 154 155 virtual bool isPartitionInvalid( gpt_ent * partition, 156 UInt32 partitionID ); 157 158 /* 159 * Instantiate a new media object to represent the given partition. 160 */ 161 162 virtual IOMedia * instantiateMediaObject( gpt_ent * partition, 163 UInt32 partitionID ); 164 165 /* 166 * Allocate a new media object (called from instantiateMediaObject). 167 */ 168 169 virtual IOMedia * instantiateDesiredMediaObject( gpt_ent * partition, 170 UInt32 partitionID ); 171 172#ifndef __LP64__ 173 /* 174 * Attach the given media object to the device tree plane. 175 */ 176 177 virtual bool attachMediaObjectToDeviceTree(IOMedia * media) __attribute__ ((deprecated)); 178 179 /* 180 * Detach the given media object from the device tree plane. 181 */ 182 183 virtual void detachMediaObjectFromDeviceTree(IOMedia * media) __attribute__ ((deprecated)); 184#endif /* !__LP64__ */ 185 186public: 187 188 /* 189 * Initialize this object's minimal state. 190 */ 191 192 virtual bool init(OSDictionary * properties = 0); 193 194 /* 195 * Determine whether the provider media contains a GUID partition map. 196 */ 197 198 virtual IOService * probe(IOService * provider, SInt32 * score); 199 200 /* 201 * Publish the new media objects which represent our partitions. 202 */ 203 204 virtual bool start(IOService * provider); 205 206 /* 207 * Clean up after the media objects we published before terminating. 208 */ 209 210 virtual void stop(IOService * provider); 211 212 /* 213 * Request that the provider media be re-scanned for partitions. 214 */ 215 216 virtual IOReturn requestProbe(IOOptionBits options); 217 218 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 0); 219 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 1); 220 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 2); 221 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 3); 222 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 4); 223 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 5); 224 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 6); 225 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 7); 226 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 8); 227 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 9); 228 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 10); 229 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 11); 230 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 12); 231 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 13); 232 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 14); 233 OSMetaClassDeclareReservedUnused(IOGUIDPartitionScheme, 15); 234}; 235 236#endif /* __cplusplus */ 237#endif /* KERNEL */ 238#endif /* !_IOGUIDPARTITIONSCHEME_H */ 239