]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/disklabel.h
a62ef42ed1a62c659903d2578b05556c6f7961ae
[apple/xnu.git] / bsd / sys / disklabel.h
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
31 /*
32 * Copyright (c) 1987, 1988, 1993
33 * The Regents of the University of California. All rights reserved.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * 4. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
62 *
63 * @(#)disklabel.h 8.2 (Berkeley) 7/10/94
64 */
65 #ifndef _SYS_DISKLABEL_H_
66 #define _SYS_DISKLABEL_H_
67
68 #include <sys/appleapiopts.h>
69 #include <sys/types.h> /* for daddr_t */
70
71 #ifdef __APPLE_API_OBSOLETE
72
73 /*
74 * Disk description table, see disktab(5)
75 */
76 #define _PATH_DISKTAB "/etc/disktab"
77 #define DISKTAB "/etc/disktab" /* deprecated */
78
79 /*
80 * Each disk has a label which includes information about the hardware
81 * disk geometry, filesystem partitions, and drive specific information.
82 * The location of the label, as well as the number of partitions the
83 * label can describe and the number of the "whole disk" (raw)
84 * paritition are machine dependent.
85 */
86 #include <machine/disklabel.h>
87
88 /*
89 * The absolute maximum number of disk partitions allowed.
90 * This is the maximum value of MAXPARTITIONS for which 'struct disklabel'
91 * is <= DEV_BSIZE bytes long. If MAXPARTITIONS is greater than this, beware.
92 */
93 #define MAXMAXPARTITIONS 22
94 #if MAXPARTITIONS > MAXMAXPARTITIONS
95 #warning beware: MAXPARTITIONS bigger than MAXMAXPARTITIONS
96 #endif
97
98 /*
99 * Translate between device numbers and major/disk unit/disk partition.
100 */
101 #define DISKUNIT(dev) (minor(dev) / MAXPARTITIONS)
102 #define DISKPART(dev) (minor(dev) % MAXPARTITIONS)
103 #define MAKEDISKDEV(maj, unit, part) \
104 (makedev((maj), ((unit) * MAXPARTITIONS) + (part)))
105
106 #define DISKMAGIC ((u_int32_t)0x82564557) /* The disk magic number */
107
108 #ifndef LOCORE
109 struct disklabel {
110 u_int32_t d_magic; /* the magic number */
111 u_int16_t d_type; /* drive type */
112 u_int16_t d_subtype; /* controller/d_type specific */
113 char d_typename[16]; /* type name, e.g. "eagle" */
114
115 /*
116 * d_packname contains the pack identifier and is returned when
117 * the disklabel is read off the disk or in-core copy.
118 * d_boot0 and d_boot1 are the (optional) names of the
119 * primary (block 0) and secondary (block 1-15) bootstraps
120 * as found in /usr/mdec. These are returned when using
121 * getdiskbyname(3) to retrieve the values from /etc/disktab.
122 */
123 union {
124 char un_d_packname[16]; /* pack identifier */
125 struct {
126 char *un_d_boot0; /* primary bootstrap name */
127 char *un_d_boot1; /* secondary bootstrap name */
128 } un_b;
129 } d_un;
130 #define d_packname d_un.un_d_packname
131 #define d_boot0 d_un.un_b.un_d_boot0
132 #define d_boot1 d_un.un_b.un_d_boot1
133
134 /* disk geometry: */
135 u_int32_t d_secsize; /* # of bytes per sector */
136 u_int32_t d_nsectors; /* # of data sectors per track */
137 u_int32_t d_ntracks; /* # of tracks per cylinder */
138 u_int32_t d_ncylinders; /* # of data cylinders per unit */
139 u_int32_t d_secpercyl; /* # of data sectors per cylinder */
140 u_int32_t d_secperunit; /* # of data sectors per unit */
141
142 /*
143 * Spares (bad sector replacements) below are not counted in
144 * d_nsectors or d_secpercyl. Spare sectors are assumed to
145 * be physical sectors which occupy space at the end of each
146 * track and/or cylinder.
147 */
148 u_int16_t d_sparespertrack; /* # of spare sectors per track */
149 u_int16_t d_sparespercyl; /* # of spare sectors per cylinder */
150 /*
151 * Alternate cylinders include maintenance, replacement, configuration
152 * description areas, etc.
153 */
154 u_int32_t d_acylinders; /* # of alt. cylinders per unit */
155
156 /* hardware characteristics: */
157 /*
158 * d_interleave, d_trackskew and d_cylskew describe perturbations
159 * in the media format used to compensate for a slow controller.
160 * Interleave is physical sector interleave, set up by the
161 * formatter or controller when formatting. When interleaving is
162 * in use, logically adjacent sectors are not physically
163 * contiguous, but instead are separated by some number of
164 * sectors. It is specified as the ratio of physical sectors
165 * traversed per logical sector. Thus an interleave of 1:1
166 * implies contiguous layout, while 2:1 implies that logical
167 * sector 0 is separated by one sector from logical sector 1.
168 * d_trackskew is the offset of sector 0 on track N relative to
169 * sector 0 on track N-1 on the same cylinder. Finally, d_cylskew
170 * is the offset of sector 0 on cylinder N relative to sector 0
171 * on cylinder N-1.
172 */
173 u_int16_t d_rpm; /* rotational speed */
174 u_int16_t d_interleave; /* hardware sector interleave */
175 u_int16_t d_trackskew; /* sector 0 skew, per track */
176 u_int16_t d_cylskew; /* sector 0 skew, per cylinder */
177 u_int32_t d_headswitch; /* head switch time, usec */
178 u_int32_t d_trkseek; /* track-to-track seek, usec */
179 u_int32_t d_flags; /* generic flags */
180 #define NDDATA 5
181 u_int32_t d_drivedata[NDDATA]; /* drive-type specific information */
182 #define NSPARE 5
183 u_int32_t d_spare[NSPARE]; /* reserved for future use */
184 u_int32_t d_magic2; /* the magic number (again) */
185 u_int16_t d_checksum; /* xor of data incl. partitions */
186
187 /* filesystem and partition information: */
188 u_int16_t d_npartitions; /* number of partitions in following */
189 u_int32_t d_bbsize; /* size of boot area at sn0, bytes */
190 u_int32_t d_sbsize; /* max size of fs superblock, bytes */
191 struct partition { /* the partition table */
192 u_int32_t p_size; /* number of sectors in partition */
193 u_int32_t p_offset; /* starting sector */
194 u_int32_t p_fsize; /* filesystem basic fragment size */
195 u_int8_t p_fstype; /* filesystem type, see below */
196 u_int8_t p_frag; /* filesystem fragments per block */
197 union {
198 u_int16_t cpg; /* UFS: FS cylinders per group */
199 u_int16_t sgs; /* LFS: FS segment shift */
200 } __partition_u1;
201 #define p_cpg __partition_u1.cpg
202 #define p_sgs __partition_u1.sgs
203 } d_partitions[MAXPARTITIONS]; /* actually may be more */
204 };
205 #else /* LOCORE */
206 /*
207 * offsets for asm boot files.
208 */
209 .set d_secsize,40
210 .set d_nsectors,44
211 .set d_ntracks,48
212 .set d_ncylinders,52
213 .set d_secpercyl,56
214 .set d_secperunit,60
215 .set d_end_,276 /* size of disk label */
216 #endif /* LOCORE */
217
218 /* d_type values: */
219 #define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */
220 #define DTYPE_MSCP 2 /* MSCP */
221 #define DTYPE_DEC 3 /* other DEC (rk, rl) */
222 #define DTYPE_SCSI 4 /* SCSI */
223 #define DTYPE_ESDI 5 /* ESDI interface */
224 #define DTYPE_ST506 6 /* ST506 etc. */
225 #define DTYPE_HPIB 7 /* CS/80 on HP-IB */
226 #define DTYPE_HPFL 8 /* HP Fiber-link */
227 #define DTYPE_FLOPPY 10 /* floppy */
228
229 #ifdef DKTYPENAMES
230 static char *dktypenames[] = {
231 "unknown",
232 "SMD",
233 "MSCP",
234 "old DEC",
235 "SCSI",
236 "ESDI",
237 "ST506",
238 "HP-IB",
239 "HP-FL",
240 "type 9",
241 "floppy",
242 NULL
243 };
244 #define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
245 #endif
246
247 /*
248 * Filesystem type and version.
249 * Used to interpret other filesystem-specific
250 * per-partition information.
251 */
252 #define FS_UNUSED 0 /* unused */
253 #define FS_SWAP 1 /* swap */
254 #define FS_V6 2 /* Sixth Edition */
255 #define FS_V7 3 /* Seventh Edition */
256 #define FS_SYSV 4 /* System V */
257 #define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */
258 #define FS_V8 6 /* Eighth Edition, 4K blocks */
259 #define FS_BSDFFS 7 /* 4.2BSD fast file system */
260 #define FS_MSDOS 8 /* MSDOS file system */
261 #define FS_BSDLFS 9 /* 4.4BSD log-structured file system */
262 #define FS_OTHER 10 /* in use, but unknown/unsupported */
263 #define FS_HPFS 11 /* OS/2 high-performance file system */
264 #define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */
265 #define FS_BOOT 13 /* partition contains bootstrap */
266 #define FS_ADOS 14 /* AmigaDOS fast file system */
267 #define FS_HFS 15 /* Macintosh HFS */
268
269 #ifdef DKTYPENAMES
270 static char *fstypenames[] = {
271 "unused",
272 "swap",
273 "Version 6",
274 "Version 7",
275 "System V",
276 "4.1BSD",
277 "Eighth Edition",
278 "4.2BSD",
279 "MSDOS",
280 "4.4LFS",
281 "unknown",
282 "HPFS",
283 "ISO9660",
284 "boot",
285 "ADOS",
286 "HFS",
287 NULL
288 };
289 #define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
290 #endif
291
292 /*
293 * flags shared by various drives:
294 */
295 #define D_REMOVABLE 0x01 /* removable media */
296 #define D_ECC 0x02 /* supports ECC */
297 #define D_BADSECT 0x04 /* supports bad sector forw. */
298 #define D_RAMDISK 0x08 /* disk emulator */
299 #define D_CHAIN 0x10 /* can do back-back transfers */
300
301 /*
302 * Drive data for SMD.
303 */
304 #define d_smdflags d_drivedata[0]
305 #define D_SSE 0x1 /* supports skip sectoring */
306 #define d_mindist d_drivedata[1]
307 #define d_maxdist d_drivedata[2]
308 #define d_sdist d_drivedata[3]
309
310 /*
311 * Drive data for ST506.
312 */
313 #define d_precompcyl d_drivedata[0]
314 #define d_gap3 d_drivedata[1] /* used only when formatting */
315
316 /*
317 * Drive data for SCSI.
318 */
319 #define d_blind d_drivedata[0]
320
321 #ifndef LOCORE
322 /*
323 * Structure used to perform a format or other raw operation, returning
324 * data and/or register values. Register identification and format
325 * are device- and driver-dependent.
326 */
327 struct format_op {
328 char *df_buf;
329 int df_count; /* value-result */
330 daddr_t df_startblk;
331 int df_reg[8]; /* result */
332 };
333
334 /*
335 * Structure used internally to retrieve information about a partition
336 * on a disk.
337 */
338 struct partinfo {
339 struct disklabel *disklab;
340 struct partition *part;
341 };
342
343 /*
344 * Disk-specific ioctls.
345 */
346 /* get and set disklabel; DIOCGPART used internally */
347 #define DIOCGDINFO _IOR('d', 101, struct disklabel)/* get */
348 #define DIOCSDINFO _IOW('d', 102, struct disklabel)/* set */
349 #define DIOCWDINFO _IOW('d', 103, struct disklabel)/* set, update disk */
350 #define DIOCGPART _IOW('d', 104, struct partinfo) /* get partition */
351
352 /* do format operation, read or write */
353 #define DIOCRFORMAT _IOWR('d', 105, struct format_op)
354 #define DIOCWFORMAT _IOWR('d', 106, struct format_op)
355
356 #define DIOCSSTEP _IOW('d', 107, int) /* set step rate */
357 #define DIOCSRETRIES _IOW('d', 108, int) /* set # of retries */
358 #define DIOCWLABEL _IOW('d', 109, int) /* write en/disable label */
359
360 #define DIOCSBAD _IOW('d', 110, struct dkbad) /* set kernel dkbad */
361
362 #endif /* LOCORE */
363
364 #if !defined(KERNEL) && !defined(LOCORE)
365
366 #include <sys/cdefs.h>
367
368 __BEGIN_DECLS
369 struct disklabel *getdiskbyname(const char *);
370 __END_DECLS
371
372 #endif
373
374 #endif /* __APPLE_API_OBSOLETE */
375
376 #endif /* ! _SYS_DISKLABEL_H_ */
377