Disklabel separation work - more.
[dragonfly.git] / sys / sys / odisklabel.h
1 /*
2  * Copyright (c) 1987, 1988, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *      @(#)disklabel.h 8.2 (Berkeley) 7/10/94
34  * $FreeBSD: src/sys/sys/disklabel.h,v 1.49.2.7 2001/05/27 05:58:26 jkh Exp $
35  * $DragonFly: src/sys/sys/Attic/odisklabel.h,v 1.18 2007/05/16 05:20:25 dillon Exp $
36  */
37
38 #ifndef _SYS_ODISKLABEL_H_
39 #define _SYS_ODISKLABEL_H_
40
41 #ifndef _SYS_TYPES_H_
42 #include <sys/types.h>
43 #endif
44 #if defined(_KERNEL) && !defined(_SYS_SYSTM_H_)
45 #include <sys/systm.h>
46 #endif
47 #ifndef _SYS_IOCCOM_H_
48 #include <sys/ioccom.h>
49 #endif
50 #if defined(_KERNEL) && !defined(_SYS_CONF_H_)
51 #include <sys/conf.h>           /* for make_sub_dev() */
52 #endif
53
54 #define DISKMAGIC       ((u_int32_t)0x82564557) /* The disk magic number */
55 #ifndef MAXPARTITIONS
56 #define MAXPARTITIONS   16
57 #endif
58
59 #define LABEL_PART      2               /* partition containing label */
60 #define RAW_PART        2               /* partition containing whole disk */
61 #define SWAP_PART       1               /* partition normally containing swap */
62
63 #ifndef LOCORE
64 struct odisklabel {
65         u_int32_t d_magic;              /* the magic number */
66         u_int16_t d_type;               /* drive type */
67         u_int16_t d_subtype;            /* controller/d_type specific */
68         char      d_typename[16];       /* type name, e.g. "eagle" */
69
70         /* 
71          * d_packname contains the pack identifier and is returned when
72          * the disklabel is read off the disk or in-core copy.
73          * d_boot0 and d_boot1 are the (optional) names of the
74          * primary (block 0) and secondary (block 1-15) bootstraps
75          * as found in /boot.  These are returned when using
76          * getdiskbyname(3) to retrieve the values from /etc/disktab.
77          */
78         union {
79                 char    un_d_packname[16];      /* pack identifier */
80                 struct {
81                         char *un_d_boot0;       /* primary bootstrap name */
82                         char *un_d_boot1;       /* secondary bootstrap name */
83                 } un_b;
84         } d_un;
85 #define d_packname      d_un.un_d_packname
86 #define d_boot0         d_un.un_b.un_d_boot0
87 #define d_boot1         d_un.un_b.un_d_boot1
88
89                         /* disk geometry: */
90         u_int32_t d_secsize;            /* # of bytes per sector */
91         u_int32_t d_nsectors;           /* # of data sectors per track */
92         u_int32_t d_ntracks;            /* # of tracks per cylinder */
93         u_int32_t d_ncylinders;         /* # of data cylinders per unit */
94         u_int32_t d_secpercyl;          /* # of data sectors per cylinder */
95         u_int32_t d_secperunit;         /* # of data sectors per unit */
96
97         /*
98          * Spares (bad sector replacements) below are not counted in
99          * d_nsectors or d_secpercyl.  Spare sectors are assumed to
100          * be physical sectors which occupy space at the end of each
101          * track and/or cylinder.
102          */
103         u_int16_t d_sparespertrack;     /* # of spare sectors per track */
104         u_int16_t d_sparespercyl;       /* # of spare sectors per cylinder */
105         /*
106          * Alternate cylinders include maintenance, replacement, configuration
107          * description areas, etc.
108          */
109         u_int32_t d_acylinders;         /* # of alt. cylinders per unit */
110
111                         /* hardware characteristics: */
112         /*
113          * d_interleave, d_trackskew and d_cylskew describe perturbations
114          * in the media format used to compensate for a slow controller.
115          * Interleave is physical sector interleave, set up by the
116          * formatter or controller when formatting.  When interleaving is
117          * in use, logically adjacent sectors are not physically
118          * contiguous, but instead are separated by some number of
119          * sectors.  It is specified as the ratio of physical sectors
120          * traversed per logical sector.  Thus an interleave of 1:1
121          * implies contiguous layout, while 2:1 implies that logical
122          * sector 0 is separated by one sector from logical sector 1.
123          * d_trackskew is the offset of sector 0 on track N relative to
124          * sector 0 on track N-1 on the same cylinder.  Finally, d_cylskew
125          * is the offset of sector 0 on cylinder N relative to sector 0
126          * on cylinder N-1.
127          */
128         u_int16_t d_rpm;                /* rotational speed */
129         u_int16_t d_interleave;         /* hardware sector interleave */
130         u_int16_t d_trackskew;          /* sector 0 skew, per track */
131         u_int16_t d_cylskew;            /* sector 0 skew, per cylinder */
132         u_int32_t d_headswitch;         /* head switch time, usec */
133         u_int32_t d_trkseek;            /* track-to-track seek, usec */
134         u_int32_t d_flags;              /* generic flags */
135 #define NDDATA 5
136         u_int32_t d_drivedata[NDDATA];  /* drive-type specific information */
137 #define NSPARE 5
138         u_int32_t d_spare[NSPARE];      /* reserved for future use */
139         u_int32_t d_magic2;             /* the magic number (again) */
140         u_int16_t d_checksum;           /* xor of data incl. partitions */
141
142                         /* filesystem and partition information: */
143         u_int16_t d_npartitions;        /* number of partitions in following */
144         u_int32_t d_bbsize;             /* size of boot area at sn0, bytes */
145         u_int32_t d_sbsize;             /* max size of fs superblock, bytes */
146         struct  opartition {            /* the partition table */
147                 u_int32_t p_size;       /* number of sectors in partition */
148                 u_int32_t p_offset;     /* starting sector */
149                 u_int32_t p_fsize;      /* filesystem basic fragment size */
150                 u_int8_t p_fstype;      /* filesystem type, see below */
151                 u_int8_t p_frag;        /* filesystem fragments per block */
152                 union {
153                         u_int16_t cpg;  /* UFS: FS cylinders per group */
154                         u_int16_t sgs;  /* LFS: FS segment shift */
155                 } __partition_u1;
156 #define p_cpg   __partition_u1.cpg
157 #define p_sgs   __partition_u1.sgs
158         } d_partitions[MAXPARTITIONS];  /* actually may be more */
159 };
160
161 static u_int16_t odkcksum(struct odisklabel *lp);
162
163 static __inline u_int16_t
164 odkcksum(struct odisklabel *lp)
165 {
166         u_int16_t *start, *end;
167         u_int16_t sum = 0;
168
169         start = (u_int16_t *)lp;
170         end = (u_int16_t *)&lp->d_partitions[lp->d_npartitions];
171         while (start < end)
172                 sum ^= *start++;
173         return (sum);
174 }
175
176 #else /* LOCORE */
177         /*
178          * offsets for asm boot files.
179          */
180         .set    d_secsize,40
181         .set    d_nsectors,44
182         .set    d_ntracks,48
183         .set    d_ncylinders,52
184         .set    d_secpercyl,56
185         .set    d_secperunit,60
186         .set    d_end_,276              /* size of disk label */
187 #endif /* LOCORE */
188
189 /* d_type values: */
190 #define DTYPE_SMD               1               /* SMD, XSMD; VAX hp/up */
191 #define DTYPE_MSCP              2               /* MSCP */
192 #define DTYPE_DEC               3               /* other DEC (rk, rl) */
193 #define DTYPE_SCSI              4               /* SCSI */
194 #define DTYPE_ESDI              5               /* ESDI interface */
195 #define DTYPE_ST506             6               /* ST506 etc. */
196 #define DTYPE_HPIB              7               /* CS/80 on HP-IB */
197 #define DTYPE_HPFL              8               /* HP Fiber-link */
198 #define DTYPE_FLOPPY            10              /* floppy */
199 #define DTYPE_CCD               11              /* concatenated disk */
200 #define DTYPE_VINUM             12              /* vinum volume */
201 #define DTYPE_DOC2K             13              /* Msys DiskOnChip */
202
203 #ifdef DKTYPENAMES
204 static const char *dktypenames[] = {
205         "unknown",
206         "SMD",
207         "MSCP",
208         "old DEC",
209         "SCSI",
210         "ESDI",
211         "ST506",
212         "HP-IB",
213         "HP-FL",
214         "type 9",
215         "floppy",
216         "CCD",
217         "Vinum",
218         "DOC2K",
219         NULL
220 };
221 #define DKMAXTYPES      (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
222 #endif
223
224 /*
225  * Filesystem type and version.
226  * Used to interpret other filesystem-specific
227  * per-partition information.
228  */
229 #define FS_UNUSED       0               /* unused */
230 #define FS_SWAP         1               /* swap */
231 #define FS_V6           2               /* Sixth Edition */
232 #define FS_V7           3               /* Seventh Edition */
233 #define FS_SYSV         4               /* System V */
234 #define FS_V71K         5               /* V7 with 1K blocks (4.1, 2.9) */
235 #define FS_V8           6               /* Eighth Edition, 4K blocks */
236 #define FS_BSDFFS       7               /* 4.2BSD fast file system */
237 #define FS_MSDOS        8               /* MSDOS file system */
238 #define FS_BSDLFS       9               /* 4.4BSD log-structured file system */
239 #define FS_OTHER        10              /* in use, but unknown/unsupported */
240 #define FS_HPFS         11              /* OS/2 high-performance file system */
241 #define FS_ISO9660      12              /* ISO 9660, normally CD-ROM */
242 #define FS_BOOT         13              /* partition contains bootstrap */
243 #define FS_VINUM        14              /* Vinum drive */
244
245 #ifdef  DKTYPENAMES
246 static const char *fstypenames[] = {
247         "unused",
248         "swap",
249         "Version 6",
250         "Version 7",
251         "System V",
252         "4.1BSD",
253         "Eighth Edition",
254         "4.2BSD",
255         "MSDOS",
256         "4.4LFS",
257         "unknown",
258         "HPFS",
259         "ISO9660",
260         "boot",
261         "vinum",
262         NULL
263 };
264 #define FSMAXTYPES      (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
265 #endif
266
267 #ifndef LOCORE
268
269 /*
270  * Disk-specific ioctls.
271  */
272                 /* get and set disklabel; DIOCGPART used internally */
273 #define ODIOCGDINFO     _IOR('d', 101, struct odisklabel)/* get */
274 #define ODIOCSDINFO     _IOW('d', 102, struct odisklabel)/* set */
275 #define ODIOCWDINFO     _IOW('d', 103, struct odisklabel)/* set, update disk */
276 #define ODIOCGDVIRGIN   _IOR('d', 105, struct odisklabel) /* get virgin label */
277
278 #endif /* LOCORE */
279
280 #endif /* !_SYS_ODISKLABEL_H_ */