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 IOFDiskPartitionScheme class definition.
26 */
27
28#ifndef _IOFDISKPARTITIONSCHEME_H
29#define _IOFDISKPARTITIONSCHEME_H
30
31#include <IOKit/IOTypes.h>
32
33/*
34 * kIOFDiskPartitionSchemeClass is the name of the IOFDiskPartitionScheme class.
35 */
36
37#define kIOFDiskPartitionSchemeClass "IOFDiskPartitionScheme"
38
39/*
40 * FDisk Partition Map Definitions
41 */
42
43#pragma pack(push, 1)                        /* (enable 8-bit struct packing) */
44
45/* Structure constants. */
46
47#define DISK_BLK0SZ sizeof(struct disk_blk0)    /* (size of partition map)    */
48#define DISK_BOOTSZ 446                         /* (size of boot code in map) */
49#define DISK_NPART  4                           /* (number of entries in map) */
50
51/* Partition map entry. */
52
53struct fdisk_part
54{
55    UInt8   bootid;    /* (is active boot partition?)                         */
56    UInt8   beghead;   /* (beginning head)                                    */
57    UInt8   begsect;   /* (beginning sector; beginning cylinder, high 2 bits) */
58    UInt8   begcyl;    /* (beginning cylinder, low 8 bits)                    */
59    UInt8   systid;    /* (type)                                              */
60    UInt8   endhead;   /* (ending head)                                       */
61    UInt8   endsect;   /* (ending sector; ending cylinder, high 2 bits)       */
62    UInt8   endcyl;    /* (ending cylinder, low 8 bits)                       */
63    UInt32  relsect;   /* (block start)                                       */
64    UInt32  numsect;   /* (block count)                                       */
65};
66
67/* Partition map, as found in block zero of the disk (or extended partition). */
68
69struct disk_blk0
70{
71    UInt8             bootcode[DISK_BOOTSZ];    /* (boot code)                */
72    struct fdisk_part parts[DISK_NPART];        /* (partition entries)        */
73    UInt16            signature;                /* (unique signature for map) */
74};
75
76/* Partition map signature (signature). */
77
78#define DISK_SIGNATURE 0xAA55
79
80/* Partition map entry types (systid). */
81
82#define FDISK_PARTITION_TYPE_01 "DOS_FAT_12"
83#define FDISK_PARTITION_TYPE_04 "DOS_FAT_16_S"
84#define FDISK_PARTITION_TYPE_06 "DOS_FAT_16"
85#define FDISK_PARTITION_TYPE_07 "Windows_NTFS"
86#define FDISK_PARTITION_TYPE_0B "DOS_FAT_32"
87#define FDISK_PARTITION_TYPE_0C "Windows_FAT_32"
88#define FDISK_PARTITION_TYPE_0E "Windows_FAT_16"
89#define FDISK_PARTITION_TYPE_42 "Windows_LDM"
90#define FDISK_PARTITION_TYPE_82 "Linux_Swap"
91#define FDISK_PARTITION_TYPE_83 "Linux"
92#define FDISK_PARTITION_TYPE_8E "Linux_LVM"
93#define FDISK_PARTITION_TYPE_A5 "FreeBSD"
94#define FDISK_PARTITION_TYPE_A6 "OpenBSD"
95#define FDISK_PARTITION_TYPE_A7 "Apple_Rhapsody_UFS"
96#define FDISK_PARTITION_TYPE_A8 "Apple_UFS"
97#define FDISK_PARTITION_TYPE_A9 "NetBSD"
98#define FDISK_PARTITION_TYPE_AB "Apple_Boot"
99#define FDISK_PARTITION_TYPE_AE "Apple_Encrypted"
100#define FDISK_PARTITION_TYPE_AF "Apple_HFS"
101#define FDISK_PARTITION_TYPE_FD "Linux_RAID"
102
103#pragma pack(pop)                        /* (reset to default struct packing) */
104
105#ifdef KERNEL
106#ifdef __cplusplus
107
108/*
109 * Kernel
110 */
111
112#include <IOKit/storage/IOPartitionScheme.h>
113
114/*
115 * Class
116 */
117
118class IOFDiskPartitionScheme : public IOPartitionScheme
119{
120    OSDeclareDefaultStructors(IOFDiskPartitionScheme);
121
122protected:
123
124    struct ExpansionData { /* */ };
125    ExpansionData * _expansionData;
126
127    OSSet * _partitions;    /* (set of media objects representing partitions) */
128
129    /*
130     * Free all of this object's outstanding resources.
131     */
132
133    virtual void free(void);
134
135    /*
136     * Scan the provider media for an FDisk partition map.  Returns the set
137     * of media objects representing each of the partitions (the retain for
138     * the set is passed to the caller), or null should no partition map be
139     * found.  The default probe score can be adjusted up or down, based on
140     * the confidence of the scan.
141     */
142
143    virtual OSSet * scan(SInt32 * score);
144
145    /*
146     * Ask whether the given partition is extended.
147     */
148
149    virtual bool isPartitionExtended(fdisk_part * partition);
150
151    /*
152     * Ask whether the given partition is used.
153     */
154
155    virtual bool isPartitionUsed(fdisk_part * partition);
156
157    /*
158     * Ask whether the given partition appears to be corrupt.  A partition that
159     * is corrupt will cause the failure of the FDisk partition map recognition
160     * altogether.
161     */
162
163    virtual bool isPartitionCorrupt( fdisk_part * partition,
164                                     UInt32       partitionID,
165                                     UInt32       fdiskBlock );
166
167    /*
168     * Ask whether the given partition appears to be invalid.  A partition that
169     * is invalid will cause it to be skipped in the scan, but will not cause a
170     * failure of the FDisk partition map recognition.
171     */
172
173    virtual bool isPartitionInvalid( fdisk_part * partition,
174                                     UInt32       partitionID,
175                                     UInt32       fdiskBlock );
176
177    /*
178     * Instantiate a new media object to represent the given partition.
179     */
180
181    virtual IOMedia * instantiateMediaObject( fdisk_part * partition,
182                                              UInt32       partitionID,
183                                              UInt32       fdiskBlock );
184
185    /*
186     * Allocate a new media object (called from instantiateMediaObject).
187     */
188
189    virtual IOMedia * instantiateDesiredMediaObject( fdisk_part * partition,
190                                                     UInt32       partitionID,
191                                                     UInt32       fdiskBlock );
192
193#ifndef __LP64__
194    /*
195     * Attach the given media object to the device tree plane.
196     */
197
198    virtual bool attachMediaObjectToDeviceTree(IOMedia * media) __attribute__ ((deprecated));
199
200    /*
201     * Detach the given media object from the device tree plane.
202     */
203
204    virtual void detachMediaObjectFromDeviceTree(IOMedia * media) __attribute__ ((deprecated));
205#endif /* !__LP64__ */
206
207public:
208
209    /*
210     * Initialize this object's minimal state.
211     */
212
213    virtual bool init(OSDictionary * properties = 0);
214
215    /*
216     * Determine whether the provider media contains an FDisk partition map.
217     */
218
219    virtual IOService * probe(IOService * provider, SInt32 * score);
220
221    /*
222     * Publish the new media objects which represent our partitions.
223     */
224
225    virtual bool start(IOService * provider);
226
227    /*
228     * Clean up after the media objects we published before terminating.
229     */
230
231    virtual void stop(IOService * provider);
232
233    /*
234     * Request that the provider media be re-scanned for partitions.
235     */
236
237    virtual IOReturn requestProbe(IOOptionBits options);
238
239#ifdef __LP64__
240    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme,  0);
241    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme,  1);
242#else /* !__LP64__ */
243    OSMetaClassDeclareReservedUsed(IOFDiskPartitionScheme,  0);
244    OSMetaClassDeclareReservedUsed(IOFDiskPartitionScheme,  1);
245#endif /* !__LP64__ */
246    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme,  2);
247    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme,  3);
248    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme,  4);
249    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme,  5);
250    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme,  6);
251    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme,  7);
252    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme,  8);
253    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme,  9);
254    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme, 10);
255    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme, 11);
256    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme, 12);
257    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme, 13);
258    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme, 14);
259    OSMetaClassDeclareReservedUnused(IOFDiskPartitionScheme, 15);
260};
261
262#endif /* __cplusplus */
263#endif /* KERNEL */
264#endif /* !_IOFDISKPARTITIONSCHEME_H */
265