2 * Copyright (c) 1987, 1988, 1993
\r
3 * The Regents of the University of California. All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without
\r
6 * modification, are permitted provided that the following conditions
\r
8 * 1. Redistributions of source code must retain the above copyright
\r
9 * notice, this list of conditions and the following disclaimer.
\r
10 * 2. Redistributions in binary form must reproduce the above copyright
\r
11 * notice, this list of conditions and the following disclaimer in the
\r
12 * documentation and/or other materials provided with the distribution.
\r
13 * 3. All advertising materials mentioning features or use of this software
\r
14 * must display the following acknowledgement:
\r
15 * This product includes software developed by the University of
\r
16 * California, Berkeley and its contributors.
\r
17 * 4. Neither the name of the University nor the names of its contributors
\r
18 * may be used to endorse or promote products derived from this software
\r
19 * without specific prior written permission.
\r
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
\r
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
\r
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
\r
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
\r
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
\r
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
\r
33 * @(#)disklabel.h 8.1 (Berkeley) 6/2/93
\r
34 * $FreeBSD: src/sys/i386/boot/dosboot/disklabe.h,v 1.8 1999/12/29 04:32:50 peter Exp $
\r
35 * $DragonFly: src/sys/i386/boot/dosboot/Attic/disklabe.h,v 1.2 2003/06/17 04:28:34 dillon Exp $
\r
38 #ifndef _SYS_DISKLABEL_H_
\r
39 #define _SYS_DISKLABEL_H_
\r
42 * Disk description table, see disktab(5)
\r
44 #define _PATH_DISKTAB "/etc/disktab"
\r
45 #define DISKTAB "/etc/disktab" /* deprecated */
\r
48 * Each disk has a label which includes information about the hardware
\r
49 * disk geometry, filesystem partitions, and drive specific information.
\r
50 * The label is in block 0 or 1, possibly offset from the beginning
\r
51 * to leave room for a bootstrap, etc.
\r
54 /* XXX these should be defined per controller (or drive) elsewhere, not here! */
\r
56 #define LABELSECTOR 1 /* sector containing label */
\r
57 #define LABELOFFSET 0 /* offset of label in sector */
\r
58 #define OURPART 2 /* partition is 'all BSD' */
\r
59 #define RAWPART 3 /* partition is 'all device' */
\r
60 #define readMSPtolabel readMBRtolabel
\r
63 #ifndef readMSPtolabel
\r
64 #define readMSPtolabel(a,b,c,d,e) /* zap calls if irrelevant */
\r
76 #define OURPART RAWPART /* by default it's all ours */
\r
80 #define LABELSECTOR 0 /* sector containing label */
\r
84 #define LABELOFFSET 64 /* offset of label in sector */
\r
87 #define DISKMAGIC ((u_long) 0x82564557ul) /* The disk magic number */
\r
88 #ifndef MAXPARTITIONS
\r
89 #define MAXPARTITIONS 8
\r
95 u_long d_magic; /* the magic number */
\r
96 short d_type; /* drive type */
\r
97 short d_subtype; /* controller/d_type specific */
\r
98 char d_typename[16]; /* type name, e.g. "eagle" */
\r
100 * d_packname contains the pack identifier and is returned when
\r
101 * the disklabel is read off the disk or in-core copy.
\r
102 * d_boot0 and d_boot1 are the (optional) names of the
\r
103 * primary (block 0) and secondary (block 1-15) bootstraps
\r
104 * as found in /boot. These are returned when using
\r
105 * getdiskbyname(3) to retrieve the values from /etc/disktab.
\r
107 #if defined(_KERNEL) || defined(STANDALONE)
\r
108 char d_packname[16]; /* pack identifier */
\r
111 char un_d_packname[16]; /* pack identifier */
\r
113 char *un_d_boot0; /* primary bootstrap name */
\r
114 char *un_d_boot1; /* secondary bootstrap name */
\r
117 #define d_packname d_un.un_d_packname
\r
118 #define d_boot0 d_un.un_b.un_d_boot0
\r
119 #define d_boot1 d_un.un_b.un_d_boot1
\r
120 #endif /* ! _KERNEL or STANDALONE */
\r
121 /* disk geometry: */
\r
122 u_long d_secsize; /* # of bytes per sector */
\r
123 u_long d_nsectors; /* # of data sectors per track */
\r
124 u_long d_ntracks; /* # of tracks per cylinder */
\r
125 u_long d_ncylinders; /* # of data cylinders per unit */
\r
126 u_long d_secpercyl; /* # of data sectors per cylinder */
\r
127 u_long d_secperunit; /* # of data sectors per unit */
\r
129 * Spares (bad sector replacements) below
\r
130 * are not counted in d_nsectors or d_secpercyl.
\r
131 * Spare sectors are assumed to be physical sectors
\r
132 * which occupy space at the end of each track and/or cylinder.
\r
134 u_short d_sparespertrack; /* # of spare sectors per track */
\r
135 u_short d_sparespercyl; /* # of spare sectors per cylinder */
\r
137 * Alternate cylinders include maintenance, replacement,
\r
138 * configuration description areas, etc.
\r
140 u_long d_acylinders; /* # of alt. cylinders per unit */
\r
142 /* hardware characteristics: */
\r
144 * d_interleave, d_trackskew and d_cylskew describe perturbations
\r
145 * in the media format used to compensate for a slow controller.
\r
146 * Interleave is physical sector interleave, set up by the formatter
\r
147 * or controller when formatting. When interleaving is in use,
\r
148 * logically adjacent sectors are not physically contiguous,
\r
149 * but instead are separated by some number of sectors.
\r
150 * It is specified as the ratio of physical sectors traversed
\r
151 * per logical sector. Thus an interleave of 1:1 implies contiguous
\r
152 * layout, while 2:1 implies that logical sector 0 is separated
\r
153 * by one sector from logical sector 1.
\r
154 * d_trackskew is the offset of sector 0 on track N
\r
155 * relative to sector 0 on track N-1 on the same cylinder.
\r
156 * Finally, d_cylskew is the offset of sector 0 on cylinder N
\r
157 * relative to sector 0 on cylinder N-1.
\r
159 u_short d_rpm; /* rotational speed */
\r
160 u_short d_interleave; /* hardware sector interleave */
\r
161 u_short d_trackskew; /* sector 0 skew, per track */
\r
162 u_short d_cylskew; /* sector 0 skew, per cylinder */
\r
163 u_long d_headswitch; /* head switch time, usec */
\r
164 u_long d_trkseek; /* track-to-track seek, usec */
\r
165 u_long d_flags; /* generic flags */
\r
167 u_long d_drivedata[NDDATA]; /* drive-type specific information */
\r
169 u_long d_spare[NSPARE]; /* reserved for future use */
\r
170 u_long d_magic2; /* the magic number (again) */
\r
171 u_short d_checksum; /* xor of data incl. partitions */
\r
173 /* filesystem and partition information: */
\r
174 u_short d_npartitions; /* number of partitions in following */
\r
175 u_long d_bbsize; /* size of boot area at sn0, bytes */
\r
176 u_long d_sbsize; /* max size of fs superblock, bytes */
\r
177 struct partition { /* the partition table */
\r
178 u_long p_size; /* number of sectors in partition */
\r
179 u_long p_offset; /* starting sector */
\r
180 u_long p_fsize; /* filesystem basic fragment size */
\r
181 u_char p_fstype; /* filesystem type, see below */
\r
182 u_char p_frag; /* filesystem fragments per block */
\r
184 u_short cpg; /* UFS: FS cylinders per group */
\r
185 u_short sgs; /* LFS: FS segment shift */
\r
187 #define p_cpg __partition_u1.cpg
\r
188 #define p_sgs __partition_u1.sgs
\r
189 } d_partitions[MAXPARTITIONS]; /* actually may be more */
\r
192 struct cpu_disklabel {
\r
197 * offsets for asm boot files.
\r
202 .set d_ncylinders,52
\r
203 .set d_secpercyl,56
\r
204 .set d_secperunit,60
\r
205 .set d_end_,276 /* size of disk label */
\r
206 #endif /* LOCORE */
\r
208 /* d_type values: */
\r
209 #define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */
\r
210 #define DTYPE_MSCP 2 /* MSCP */
\r
211 #define DTYPE_DEC 3 /* other DEC (rk, rl) */
\r
212 #define DTYPE_SCSI 4 /* SCSI */
\r
213 #define DTYPE_ESDI 5 /* ESDI interface */
\r
214 #define DTYPE_ST506 6 /* ST506 etc. */
\r
215 #define DTYPE_HPIB 7 /* CS/80 on HP-IB */
\r
216 #define DTYPE_HPFL 8 /* HP Fiber-link */
\r
217 #define DTYPE_FLOPPY 10 /* floppy */
\r
219 /* d_subtype values: */
\r
220 #define DSTYPE_INDOSPART 0x8 /* is inside dos partition */
\r
221 #define DSTYPE_DOSPART(s) ((s) & 3) /* dos partition number */
\r
222 #define DSTYPE_GEOMETRY 0x10 /* drive params in label */
\r
225 static char *dktypenames[] = {
\r
239 #define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
\r
243 * Filesystem type and version.
\r
244 * Used to interpret other filesystem-specific
\r
245 * per-partition information.
\r
247 #define FS_UNUSED 0 /* unused */
\r
248 #define FS_SWAP 1 /* swap */
\r
249 #define FS_V6 2 /* Sixth Edition */
\r
250 #define FS_V7 3 /* Seventh Edition */
\r
251 #define FS_SYSV 4 /* System V */
\r
252 #define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */
\r
253 #define FS_V8 6 /* Eighth Edition, 4K blocks */
\r
254 #define FS_BSDFFS 7 /* 4.2BSD fast file system */
\r
255 #define FS_MSDOS 8 /* MSDOS file system */
\r
256 #define FS_BSDLFS 9 /* 4.4BSD log-structured file system */
\r
257 #define FS_OTHER 10 /* in use, but unknown/unsupported */
\r
258 #define FS_HPFS 11 /* OS/2 high-performance file system */
\r
259 #define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */
\r
260 #define FS_BOOT 13 /* partition contains bootstrap */
\r
263 static char *fstypenames[] = {
\r
280 #define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
\r
284 * flags shared by various drives:
\r
286 #define D_REMOVABLE 0x01 /* removable media */
\r
287 #define D_ECC 0x02 /* supports ECC */
\r
288 #define D_BADSECT 0x04 /* supports bad sector forw. */
\r
289 #define D_RAMDISK 0x08 /* disk emulator */
\r
290 #define D_CHAIN 0x10 /* can do back-back transfers */
\r
293 * Drive data for SMD.
\r
295 #define d_smdflags d_drivedata[0]
\r
296 #define D_SSE 0x1 /* supports skip sectoring */
\r
297 #define d_mindist d_drivedata[1]
\r
298 #define d_maxdist d_drivedata[2]
\r
299 #define d_sdist d_drivedata[3]
\r
302 * Drive data for ST506.
\r
304 #define d_precompcyl d_drivedata[0]
\r
305 #define d_gap3 d_drivedata[1] /* used only when formatting */
\r
308 * Drive data for SCSI.
\r
310 #define d_blind d_drivedata[0]
\r
314 * Structure used to perform a format
\r
315 * or other raw operation, returning data
\r
316 * and/or register values.
\r
317 * Register identification and format
\r
318 * are device- and driver-dependent.
\r
322 long df_count; /* value-result */
\r
323 daddr_t df_startblk;
\r
324 long df_reg[8]; /* result */
\r
328 * Structure used internally to retrieve
\r
329 * information about a partition on a disk.
\r
332 struct disklabel *disklab;
\r
333 struct partition *part;
\r
336 /* DOS partition table -- located in boot block */
\r
338 #define DOSBBSECTOR 0 /* DOS boot block relative sector number */
\r
339 #define DOSPARTOFF 446
\r
341 #define DOSPTYP_386BSD 0xa5 /* 386BSD partition type */
\r
342 #define MBR_PTYPE_FreeBSD 0xa5 /* FreeBSD partition type */
\r
344 struct dos_partition {
\r
345 unsigned char dp_flag; /* bootstrap flags */
\r
346 unsigned char dp_shd; /* starting head */
\r
347 unsigned char dp_ssect; /* starting sector */
\r
348 unsigned char dp_scyl; /* starting cylinder */
\r
349 unsigned char dp_typ; /* partition type */
\r
350 unsigned char dp_ehd; /* end head */
\r
351 unsigned char dp_esect; /* end sector */
\r
352 unsigned char dp_ecyl; /* end cylinder */
\r
353 unsigned long dp_start; /* absolute starting sector number */
\r
354 unsigned long dp_size; /* partition size in sectors */
\r
357 extern struct dos_partition dos_partitions[NDOSPART];
\r
359 #define DPSECT(s) ((s) & 0x3f) /* isolate relevant bits of sector */
\r
360 #define DPCYL(c, s) ((c) + (((s) & 0xc0)<<2)) /* and those that are cylinder */
\r
363 * Disk-specific ioctls.
\r
365 /* get and set disklabel; DIOCGPART used internally */
\r
366 #define DIOCGDINFO _IOR('d', 101, struct disklabel)/* get */
\r
367 #define DIOCSDINFO _IOW('d', 102, struct disklabel)/* set */
\r
368 #define DIOCWDINFO _IOW('d', 103, struct disklabel)/* set, update disk */
\r
369 #define DIOCGPART _IOW('d', 104, struct partinfo) /* get partition */
\r
371 #define DIOCWLABEL _IOW('d', 109, int) /* write en/disable label */
\r
373 #define DIOCSBAD _IOW('d', 110, struct dkbad) /* set kernel dkbad */
\r
375 #endif /* LOCORE */
\r
380 u_int dkcksum __P((struct disklabel *));
\r
381 int writedisklabel __P((dev_t dev, void (*strat)(), struct disklabel *lp));
\r
382 char * readdisklabel __P((dev_t dev, void (*strat)(), struct disklabel *lp, struct dos_partition *dp, struct dkbad *bdp));
\r
383 int setdisklabel __P((struct disklabel *olp, struct disklabel *nlp, u_long openmask));
\r
384 void disksort __P((struct buf *ap, struct buf *bp));
\r
385 void diskerr __P((struct buf *, char *, char *, int, int, struct disklabel *));
\r
387 char * readMBRtolabel __P(( dev_t dev , void (*strat)(), register struct disklabel *lp, struct dos_partition *dp, int *cyl));
\r
391 #if !defined(_KERNEL) && !defined(LOCORE)
\r
396 struct disklabel *getdiskbyname __P((const char *));
\r
402 /* encoding of disk minor numbers, should be elsewhere... */
\r
403 #define dkunit(dev) (minor(dev) >> 3)
\r
404 #define dkpart(dev) (minor(dev) & 07)
\r
405 #define dkminor(unit, part) (((unit) << 3) | (part))
\r