906566fe023c361ae16f4171dc44236d3dad1af5
[dragonfly.git] / sys / i386 / boot / dosboot / disklabe.h
1 /*\r
2  * Copyright (c) 1987, 1988, 1993\r
3  *      The Regents of the University of California.  All rights reserved.\r
4  *\r
5  * Redistribution and use in source and binary forms, with or without\r
6  * modification, are permitted provided that the following conditions\r
7  * are met:\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
20  *\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
31  * SUCH DAMAGE.\r
32  *\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
36  */\r
37 \r
38 #ifndef _SYS_DISKLABEL_H_\r
39 #define _SYS_DISKLABEL_H_\r
40 \r
41 /*\r
42  * Disk description table, see disktab(5)\r
43  */\r
44 #define _PATH_DISKTAB   "/etc/disktab"\r
45 #define DISKTAB         "/etc/disktab"          /* deprecated */\r
46 \r
47 /*\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
52  */\r
53 \r
54 /* XXX these should be defined per controller (or drive) elsewhere, not here! */\r
55 #ifdef __i386__\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
61 #endif\r
62 \r
63 #ifndef readMSPtolabel\r
64 #define readMSPtolabel(a,b,c,d,e)               /* zap calls if irrelevant */\r
65 #endif\r
66 \r
67 #ifdef  tahoe\r
68 #define RAWPART         0\r
69 #endif\r
70 \r
71 #ifndef RAWPART\r
72 #define RAWPART         2\r
73 #endif\r
74 \r
75 #ifndef OURPART\r
76 #define OURPART         RAWPART                 /* by default it's all ours */\r
77 #endif\r
78 \r
79 #ifndef LABELSECTOR\r
80 #define LABELSECTOR     0                       /* sector containing label */\r
81 #endif\r
82 \r
83 #ifndef LABELOFFSET\r
84 #define LABELOFFSET     64                      /* offset of label in sector */\r
85 #endif\r
86 \r
87 #define DISKMAGIC       ((u_long) 0x82564557ul) /* The disk magic number */\r
88 #ifndef MAXPARTITIONS\r
89 #define MAXPARTITIONS   8\r
90 #endif\r
91 \r
92 \r
93 #ifndef LOCORE\r
94 struct disklabel {\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
99         /* \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
106          */\r
107 #if defined(_KERNEL) || defined(STANDALONE)\r
108         char    d_packname[16];                 /* pack identifier */ \r
109 #else\r
110         union {\r
111                 char    un_d_packname[16];      /* pack identifier */ \r
112                 struct {\r
113                         char *un_d_boot0;       /* primary bootstrap name */\r
114                         char *un_d_boot1;       /* secondary bootstrap name */\r
115                 } un_b; \r
116         } d_un; \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
128         /*\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
133          */\r
134         u_short d_sparespertrack;       /* # of spare sectors per track */\r
135         u_short d_sparespercyl;         /* # of spare sectors per cylinder */\r
136         /*\r
137          * Alternate cylinders include maintenance, replacement,\r
138          * configuration description areas, etc.\r
139          */\r
140         u_long  d_acylinders;           /* # of alt. cylinders per unit */\r
141 \r
142                         /* hardware characteristics: */\r
143         /*\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
158          */\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
166 #define NDDATA 5\r
167         u_long  d_drivedata[NDDATA];    /* drive-type specific information */\r
168 #define NSPARE 5\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
172 \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
183                 union {\r
184                         u_short cpg;    /* UFS: FS cylinders per group */\r
185                         u_short sgs;    /* LFS: FS segment shift */\r
186                 } __partition_u1;\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
190 };\r
191 /*\r
192 struct cpu_disklabel {\r
193 };\r
194 */\r
195 #else /* LOCORE */\r
196         /*\r
197          * offsets for asm boot files.\r
198          */\r
199         .set    d_secsize,40\r
200         .set    d_nsectors,44\r
201         .set    d_ntracks,48\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
207 \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
218 \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
223 \r
224 #ifdef DKTYPENAMES\r
225 static char *dktypenames[] = {\r
226         "unknown",\r
227         "SMD",\r
228         "MSCP",\r
229         "old DEC",\r
230         "SCSI",\r
231         "ESDI",\r
232         "ST506",\r
233         "HP-IB",\r
234         "HP-FL",\r
235         "type 9",\r
236         "floppy",\r
237         0\r
238 };\r
239 #define DKMAXTYPES      (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)\r
240 #endif\r
241 \r
242 /*\r
243  * Filesystem type and version.\r
244  * Used to interpret other filesystem-specific\r
245  * per-partition information.\r
246  */\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
261 \r
262 #ifdef  DKTYPENAMES\r
263 static char *fstypenames[] = {\r
264         "unused",\r
265         "swap",\r
266         "Version 6",\r
267         "Version 7",\r
268         "System V",\r
269         "4.1BSD",\r
270         "Eighth Edition",\r
271         "4.2BSD",\r
272         "MSDOS",\r
273         "4.4LFS",\r
274         "unknown",\r
275         "HPFS",\r
276         "ISO9660",\r
277         "boot",\r
278         0\r
279 };\r
280 #define FSMAXTYPES      (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)\r
281 #endif\r
282 \r
283 /*\r
284  * flags shared by various drives:\r
285  */\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
291 \r
292 /*\r
293  * Drive data for SMD.\r
294  */\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
300 \r
301 /*\r
302  * Drive data for ST506.\r
303  */\r
304 #define d_precompcyl    d_drivedata[0]\r
305 #define d_gap3          d_drivedata[1]          /* used only when formatting */\r
306 \r
307 /*\r
308  * Drive data for SCSI.\r
309  */\r
310 #define d_blind         d_drivedata[0]\r
311 \r
312 #ifndef LOCORE\r
313 /*\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
319  */\r
320 struct format_op {\r
321         char    *df_buf;\r
322         long    df_count;               /* value-result */\r
323         daddr_t df_startblk;\r
324         long    df_reg[8];              /* result */\r
325 };\r
326 \r
327 /*\r
328  * Structure used internally to retrieve\r
329  * information about a partition on a disk.\r
330  */\r
331 struct partinfo {\r
332         struct disklabel *disklab;\r
333         struct partition *part;\r
334 };\r
335 \r
336 /* DOS partition table -- located in boot block */\r
337 \r
338 #define DOSBBSECTOR     0       /* DOS boot block relative sector number */\r
339 #define DOSPARTOFF      446\r
340 #define NDOSPART        4\r
341 #define DOSPTYP_386BSD  0xa5    /* 386BSD partition type */\r
342 #define MBR_PTYPE_FreeBSD 0xa5  /* FreeBSD partition type */\r
343 \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
355 };\r
356 \r
357 extern struct dos_partition dos_partitions[NDOSPART];\r
358 \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
361 \r
362 /*\r
363  * Disk-specific ioctls.\r
364  */\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
370 \r
371 #define DIOCWLABEL      _IOW('d', 109, int)     /* write en/disable label */\r
372 \r
373 #define DIOCSBAD        _IOW('d', 110, struct dkbad)    /* set kernel dkbad */\r
374 \r
375 #endif /* LOCORE */\r
376 \r
377 #ifdef KERNEL\r
378 struct dkbad;\r
379 \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
386 #ifdef __i386\r
387 char *  readMBRtolabel __P(( dev_t dev , void (*strat)(), register struct disklabel *lp, struct dos_partition *dp, int *cyl));\r
388 #endif\r
389 #endif\r
390 \r
391 #if !defined(_KERNEL) && !defined(LOCORE)\r
392 \r
393 #include "cdefs.h"\r
394 \r
395 __BEGIN_DECLS\r
396 struct disklabel *getdiskbyname __P((const char *));\r
397 __END_DECLS\r
398 \r
399 #endif\r
400 \r
401 #ifdef __i386\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
406 #endif\r
407 \r
408 #endif\r
409 \r
410 \r