]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/storage/IONeXTPartitionScheme.h
3172c6bd02a3374ca2dd912c14b663731c685731
[apple/xnu.git] / iokit / IOKit / storage / IONeXTPartitionScheme.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 _IONEXTPARTITIONSCHEME_H
24 #define _IONEXTPARTITIONSCHEME_H
25
26 #include <IOKit/IOTypes.h>
27
28 /*
29 * NeXT Partition Map Definitions
30 */
31
32 #pragma pack(2) /* (enable 16-bit struct packing for dl_un, disk[tab,_label]) */
33
34 #include <sys/disktab.h>
35
36 /* Structure constants. */
37
38 #define MAXLBLLEN 24 /* (length of disk name) */
39 #define NBAD 1670 /* (size of bad sector table in map) */
40 #define NLABELS 4 /* (number of partition maps on disk) */
41
42 /* Structure aliases, for disktab and dl_un fields. */
43
44 #define dl_name dl_dt.d_name
45 #define dl_type dl_dt.d_type
46 #define dl_part dl_dt.d_partitions
47 #define dl_front dl_dt.d_front
48 #define dl_back dl_dt.d_back
49 #define dl_ngroups dl_dt.d_ngroups
50 #define dl_ag_size dl_dt.d_ag_size
51 #define dl_ag_alts dl_dt.d_ag_alts
52 #define dl_ag_off dl_dt.d_ag_off
53 #define dl_secsize dl_dt.d_secsize
54 #define dl_ncyl dl_dt.d_ncylinders
55 #define dl_nsect dl_dt.d_nsectors
56 #define dl_ntrack dl_dt.d_ntracks
57 #define dl_rpm dl_dt.d_rpm
58 #define dl_bootfile dl_dt.d_bootfile
59 #define dl_boot0_blkno dl_dt.d_boot0_blkno
60 #define dl_hostname dl_dt.d_hostname
61 #define dl_rootpartition dl_dt.d_rootpartition
62 #define dl_rwpartition dl_dt.d_rwpartition
63 #define dl_v3_checksum dl_un.DL_v3_checksum
64 #define dl_bad dl_un.DL_bad
65
66 /* Partition map, as found in block zero (or a redundant block) of the disk. */
67
68 typedef union
69 {
70 UInt16 DL_v3_checksum; /* (V3: ones complement checksum) */
71 SInt32 DL_bad[NBAD]; /* (V1-V2: bad sector table) */
72 } dl_un_t;
73
74 typedef struct disk_label
75 {
76 SInt32 dl_version; /* (unique signature for map) */
77 SInt32 dl_label_blkno; /* (block on which this map resides) */
78 SInt32 dl_size; /* (device block count) */
79 char dl_label[MAXLBLLEN]; /* (device name) */
80 UInt32 dl_flags; /* (device flags) */
81 UInt32 dl_tag; /* (device tag) */
82 struct disktab dl_dt; /* (device info, partition entries) */
83 dl_un_t dl_un;
84 UInt16 dl_checksum; /* (V1-V2: ones complement checksum) */
85
86 /* (add things here so dl_checksum stays in a fixed place) */
87 } disk_label_t;
88
89 /* Partition map signature (dl_version). */
90
91 #define DL_V1 0x4e655854 /* (version 1: "NeXT") */
92 #define DL_V2 0x646c5632 /* (version 2: "dlV2") */
93 #define DL_V3 0x646c5633 /* (version 3: "dlV3") */
94 #define DL_VERSION DL_V3 /* (default version) */
95
96 /* Partition map flags (dl_flags). */
97
98 #define DL_UNINIT 0x80000000 /* (is uninitialized?) */
99
100 #pragma options align=reset /* (reset to default struct packing) */
101
102 /*
103 * Kernel
104 */
105
106 #if defined(KERNEL) && defined(__cplusplus)
107
108 #include <IOKit/storage/IOPartitionScheme.h>
109
110 /*
111 * Class
112 */
113
114 class IONeXTPartitionScheme : public IOPartitionScheme
115 {
116 OSDeclareDefaultStructors(IONeXTPartitionScheme);
117
118 private:
119
120 /*
121 * Compute a 16-bit (big-endian) checksum over the specified data range.
122 */
123
124 UInt16 checksum16(void * data, UInt32 bytes) const;
125
126 protected:
127
128 struct ExpansionData { /* */ };
129 ExpansionData * _expansionData;
130
131 OSSet * _partitions; /* (set of media objects representing partitions) */
132
133 /*
134 * Free all of this object's outstanding resources.
135 */
136
137 virtual void free(void);
138
139 /*
140 * Scan the provider media for a NeXT partition map. Returns the set
141 * of media objects representing each of the partitions (the retain for
142 * the set is passed to the caller), or null should no partition map be
143 * found. The default probe score can be adjusted up or down, based on
144 * the confidence of the scan.
145 */
146
147 virtual OSSet * scan(SInt32 * score);
148
149 /*
150 * Ask whether the given partition is used.
151 */
152
153 virtual bool isPartitionUsed(partition_t * partition);
154
155 /*
156 * Ask whether the given partition appears to be corrupt. A partition that
157 * is corrupt will cause the failure of the NeXT partition map recognition
158 * altogether.
159 */
160
161 virtual bool isPartitionCorrupt( partition_t * partition,
162 UInt32 partitionID,
163 UInt64 nextBase,
164 disk_label_t * nextMap );
165
166 /*
167 * Ask whether the given partition appears to be invalid. A partition that
168 * is invalid will cause it to be skipped in the scan, but will not cause a
169 * failure of the NeXT partition map recognition.
170 */
171
172 virtual bool isPartitionInvalid( partition_t * partition,
173 UInt32 partitionID,
174 UInt64 nextBase,
175 disk_label_t * nextMap );
176
177 /*
178 * Instantiate a new media object to represent the given partition.
179 */
180
181 virtual IOMedia * instantiateMediaObject( partition_t * partition,
182 UInt32 partitionID,
183 UInt64 nextBase,
184 disk_label_t * nextMap );
185
186 /*
187 * Allocate a new media object (called from instantiateMediaObject).
188 */
189
190 virtual IOMedia * instantiateDesiredMediaObject( partition_t * partition,
191 UInt32 partitionID,
192 UInt64 nextBase,
193 disk_label_t * nextMap );
194
195 public:
196
197 /*
198 * Initialize this object's minimal state.
199 */
200
201 virtual bool init(OSDictionary * properties = 0);
202
203 /*
204 * Determine whether the provider media contains a NeXT partition map.
205 */
206
207 virtual IOService * probe(IOService * provider, SInt32 * score);
208
209 /*
210 * Publish the new media objects which represent our partitions.
211 */
212
213 virtual bool start(IOService * provider);
214
215 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 0);
216 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 1);
217 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 2);
218 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 3);
219 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 4);
220 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 5);
221 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 6);
222 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 7);
223 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 8);
224 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 9);
225 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 10);
226 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 11);
227 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 12);
228 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 13);
229 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 14);
230 OSMetaClassDeclareReservedUnused(IONeXTPartitionScheme, 15);
231 };
232
233 #endif /* defined(KERNEL) && defined(__cplusplus) */
234
235 #endif /* !_IONEXTPARTITIONSCHEME_H */