]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/storage/IOApplePartitionScheme.h
xnu-124.13.tar.gz
[apple/xnu.git] / iokit / IOKit / storage / IOApplePartitionScheme.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #ifndef _IOAPPLEPARTITIONSCHEME_H
24 #define _IOAPPLEPARTITIONSCHEME_H
25
26 #include <IOKit/IOTypes.h>
27
28 /*
29 * Apple Partition Map Definitions
30 */
31
32 #pragma pack(2) /* (enable 16-bit struct packing for dpme, DDMap, Block0) */
33
34 /* Structure constants. */
35
36 #define DPISTRLEN 32
37
38 /* Partition map entry, as found in blocks 1 to dpme_map_entries of the disk. */
39
40 typedef struct dpme
41 {
42 UInt16 dpme_signature; /* (unique value for partition entry, 'PM') */
43 UInt16 dpme_reserved_1; /* (reserved for future use) */
44 UInt32 dpme_map_entries; /* (number of partition entries) */
45 UInt32 dpme_pblock_start; /* (physical block start of partition) */
46 UInt32 dpme_pblocks; /* (physical block count of partition) */
47 char dpme_name[DPISTRLEN]; /* (name of partition) */
48 char dpme_type[DPISTRLEN]; /* (type of partition, eg. Apple_HFS) */
49 UInt32 dpme_lblock_start; /* (logical block start of partition) */
50 UInt32 dpme_lblocks; /* (logical block count of partition) */
51 UInt32 dpme_flags; /* (partition flags, see defines below) */
52 UInt32 dpme_boot_block; /* (logical block start of boot code) */
53 UInt32 dpme_boot_bytes; /* (byte count of boot code) */
54 UInt8 * dpme_load_addr; /* (load address in memory of boot code) */
55 UInt8 * dpme_load_addr_2; /* (reserved for future use) */
56 UInt8 * dpme_goto_addr; /* (jump address in memory of boot code) */
57 UInt8 * dpme_goto_addr_2; /* (reserved for future use) */
58 UInt32 dpme_checksum; /* (checksum of boot code) */
59 UInt8 dpme_process_id[16]; /* (processor type) */
60 UInt32 dpme_reserved_2[32]; /* (reserved for future use) */
61 UInt32 dpme_reserved_3[62]; /* (reserved for future use) */
62 } DPME;
63
64 /* Driver descriptor map entry. */
65
66 typedef struct DDMap
67 {
68 UInt32 ddBlock; /* (driver's block start, sbBlkSize-blocks) */
69 UInt16 ddSize; /* (driver's block count, 512-blocks) */
70 UInt16 ddType; /* (driver's system type) */
71 } DDMap;
72
73 /* Driver descriptor map, as found in block zero of the disk. */
74
75 typedef struct Block0
76 {
77 UInt16 sbSig; /* (unique value for block zero, 'ER') */
78 UInt16 sbBlkSize; /* (block size for this device) */
79 UInt32 sbBlkCount; /* (block count for this device) */
80 UInt16 sbDevType; /* (device type) */
81 UInt16 sbDevId; /* (device id) */
82 UInt32 sbDrvrData; /* (driver data) */
83 UInt16 sbDrvrCount; /* (driver descriptor count) */
84 DDMap sbDrvrMap[8]; /* (driver descriptor table) */
85 UInt8 sbReserved[430]; /* (reserved for future use) */
86 } Block0;
87
88 /* Partition map signature (sbSig). */
89
90 #define BLOCK0_SIGNATURE 0x4552
91
92 /* Partition map entry signature (dpme_signature). */
93
94 #define DPME_SIGNATURE 0x504D
95
96 /* Partition map entry flags (dpme_flags). */
97
98 #define DPME_FLAGS_VALID 0x00000001 /* (bit 0) */
99 #define DPME_FLAGS_ALLOCATED 0x00000002 /* (bit 1) */
100 #define DPME_FLAGS_IN_USE 0x00000004 /* (bit 2) */
101 #define DPME_FLAGS_BOOTABLE 0x00000008 /* (bit 3) */
102 #define DPME_FLAGS_READABLE 0x00000010 /* (bit 4) */
103 #define DPME_FLAGS_WRITABLE 0x00000020 /* (bit 5) */
104 #define DPME_FLAGS_OS_PIC_CODE 0x00000040 /* (bit 6) */
105 #define DPME_FLAGS_OS_SPECIFIC_2 0x00000080 /* (bit 7) */
106 #define DPME_FLAGS_OS_SPECIFIC_1 0x00000100 /* (bit 8) */
107 #define DPME_FLAGS_RESERVED_2 0xFFFFFE00 /* (bit 9..31) */
108
109 #pragma options align=reset /* (reset to default struct packing) */
110
111 /*
112 * Kernel
113 */
114
115 #if defined(KERNEL) && defined(__cplusplus)
116
117 #include <IOKit/storage/IOPartitionScheme.h>
118
119 /*
120 * Class
121 */
122
123 class IOApplePartitionScheme : public IOPartitionScheme
124 {
125 OSDeclareDefaultStructors(IOApplePartitionScheme);
126
127 protected:
128
129 struct ExpansionData { /* */ };
130 ExpansionData * _expansionData;
131
132 OSSet * _partitions; /* (set of media objects representing partitions) */
133
134 /*
135 * Free all of this object's outstanding resources.
136 */
137
138 virtual void free(void);
139
140 /*
141 * Scan the provider media for an Apple partition map. Returns the set
142 * of media objects representing each of the partitions (the retain for
143 * the set is passed to the caller), or null should no partition map be
144 * found. The default probe score can be adjusted up or down, based on
145 * the confidence of the scan.
146 */
147
148 virtual OSSet * scan(SInt32 * score);
149
150 /*
151 * Ask whether the given partition appears to be corrupt. A partition that
152 * is corrupt will cause the failure of the Apple partition map recognition
153 * altogether.
154 */
155
156 virtual bool isPartitionCorrupt( dpme * partition,
157 UInt32 partitionID,
158 UInt32 partitionBlockSize );
159
160 /*
161 * Ask whether the given partition appears to be invalid. A partition that
162 * is invalid will cause it to be skipped in the scan, but will not cause a
163 * failure of the Apple partition map recognition.
164 */
165
166 virtual bool isPartitionInvalid( dpme * partition,
167 UInt32 partitionID,
168 UInt32 partitionBlockSize );
169
170 /*
171 * Instantiate a new media object to represent the given partition.
172 */
173
174 virtual IOMedia * instantiateMediaObject( dpme * partition,
175 UInt32 partitionID,
176 UInt32 partitionBlockSize );
177
178 /*
179 * Allocate a new media object (called from instantiateMediaObject).
180 */
181
182 virtual IOMedia * instantiateDesiredMediaObject(
183 dpme * partition,
184 UInt32 partitionID,
185 UInt32 partitionBlockSize );
186
187 /*
188 * Attach the given media object to the device tree plane.
189 */
190
191 virtual bool attachMediaObjectToDeviceTree(IOMedia * media);
192
193 /*
194 * Detach the given media object from the device tree plane.
195 */
196
197 virtual void detachMediaObjectFromDeviceTree(IOMedia * media);
198
199 public:
200
201 /*
202 * Initialize this object's minimal state.
203 */
204
205 virtual bool init(OSDictionary * properties = 0);
206
207 /*
208 * Determine whether the provider media contains an Apple partition map.
209 */
210
211 virtual IOService * probe(IOService * provider, SInt32 * score);
212
213 /*
214 * Publish the new media objects which represent our partitions.
215 */
216
217 virtual bool start(IOService * provider);
218
219 /*
220 * Clean up after the media objects we published before terminating.
221 */
222
223 virtual void stop(IOService * provider);
224
225 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 0);
226 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 1);
227 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 2);
228 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 3);
229 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 4);
230 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 5);
231 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 6);
232 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 7);
233 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 8);
234 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 9);
235 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 10);
236 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 11);
237 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 12);
238 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 13);
239 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 14);
240 OSMetaClassDeclareReservedUnused(IOApplePartitionScheme, 15);
241 };
242
243 #endif /* defined(KERNEL) && defined(__cplusplus) */
244
245 #endif /* !_IOAPPLEPARTITIONSCHEME_H */