enable login utils
[framework/base/util-linux-ng.git] / fdisk / fdiskbsdlabel.h
1 #ifndef FDISK_BSD_LABEL_H
2 #define FDISK_BSD_LABEL_H
3
4 /*
5  * Copyright (c) 1987, 1988 Regents of the University of California.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by the University of
19  *      California, Berkeley and its contributors.
20  * 4. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  */
36
37 #include <stdint.h>
38
39 #ifndef BSD_DISKMAGIC
40 #define BSD_DISKMAGIC     ((uint32_t) 0x82564557)
41 #endif
42
43 #ifndef BSD_MAXPARTITIONS
44 #define BSD_MAXPARTITIONS 16
45 #endif
46
47 #define BSD_LINUX_BOOTDIR "/usr/ucb/mdec"
48
49 #if defined (i386) || defined (__sparc__) || defined (__arm__) || \
50     defined (__mips__) || defined (__s390__) || defined (__sh__) || \
51     defined(__x86_64__) || defined (__avr32__) || defined(__cris__)
52 #define BSD_LABELSECTOR   1
53 #define BSD_LABELOFFSET   0
54 #elif defined (__alpha__) || defined (__powerpc__) || defined (__ia64__) || defined (__hppa__)
55 #define BSD_LABELSECTOR   0
56 #define BSD_LABELOFFSET   64
57 #elif defined (__s390__) || defined (__s390x__)
58 #define BSD_LABELSECTOR   1
59 #define BSD_LABELOFFSET   0
60 #else
61 #error unknown architecture
62 #endif
63
64 #define BSD_BBSIZE        8192          /* size of boot area, with label */
65 #define BSD_SBSIZE        8192          /* max size of fs superblock */
66
67 struct xbsd_disklabel {
68         uint32_t        d_magic;                /* the magic number */
69         int16_t d_type;                 /* drive type */
70         int16_t d_subtype;              /* controller/d_type specific */
71         char    d_typename[16];         /* type name, e.g. "eagle" */
72         char    d_packname[16];                 /* pack identifier */ 
73                         /* disk geometry: */
74         uint32_t        d_secsize;              /* # of bytes per sector */
75         uint32_t        d_nsectors;             /* # of data sectors per track */
76         uint32_t        d_ntracks;              /* # of tracks per cylinder */
77         uint32_t        d_ncylinders;           /* # of data cylinders per unit */
78         uint32_t        d_secpercyl;            /* # of data sectors per cylinder */
79         uint32_t        d_secperunit;           /* # of data sectors per unit */
80         /*
81          * Spares (bad sector replacements) below
82          * are not counted in d_nsectors or d_secpercyl.
83          * Spare sectors are assumed to be physical sectors
84          * which occupy space at the end of each track and/or cylinder.
85          */
86         uint16_t        d_sparespertrack;       /* # of spare sectors per track */
87         uint16_t        d_sparespercyl;         /* # of spare sectors per cylinder */
88         /*
89          * Alternate cylinders include maintenance, replacement,
90          * configuration description areas, etc.
91          */
92         uint32_t        d_acylinders;           /* # of alt. cylinders per unit */
93
94                         /* hardware characteristics: */
95         /*
96          * d_interleave, d_trackskew and d_cylskew describe perturbations
97          * in the media format used to compensate for a slow controller.
98          * Interleave is physical sector interleave, set up by the formatter
99          * or controller when formatting.  When interleaving is in use,
100          * logically adjacent sectors are not physically contiguous,
101          * but instead are separated by some number of sectors.
102          * It is specified as the ratio of physical sectors traversed
103          * per logical sector.  Thus an interleave of 1:1 implies contiguous
104          * layout, while 2:1 implies that logical sector 0 is separated
105          * by one sector from logical sector 1.
106          * d_trackskew is the offset of sector 0 on track N
107          * relative to sector 0 on track N-1 on the same cylinder.
108          * Finally, d_cylskew is the offset of sector 0 on cylinder N
109          * relative to sector 0 on cylinder N-1.
110          */
111         uint16_t        d_rpm;                  /* rotational speed */
112         uint16_t        d_interleave;           /* hardware sector interleave */
113         uint16_t        d_trackskew;            /* sector 0 skew, per track */
114         uint16_t        d_cylskew;              /* sector 0 skew, per cylinder */
115         uint32_t        d_headswitch;           /* head switch time, usec */
116         uint32_t        d_trkseek;              /* track-to-track seek, usec */
117         uint32_t        d_flags;                /* generic flags */
118 #define NDDATA 5
119         uint32_t        d_drivedata[NDDATA];    /* drive-type specific information */
120 #define NSPARE 5
121         uint32_t        d_spare[NSPARE];        /* reserved for future use */
122         uint32_t        d_magic2;               /* the magic number (again) */
123         uint16_t        d_checksum;             /* xor of data incl. partitions */
124                         /* filesystem and partition information: */
125         uint16_t        d_npartitions;          /* number of partitions in following */
126         uint32_t        d_bbsize;               /* size of boot area at sn0, bytes */
127         uint32_t        d_sbsize;               /* max size of fs superblock, bytes */
128         struct xbsd_partition    {      /* the partition table */
129                 uint32_t        p_size;         /* number of sectors in partition */
130                 uint32_t        p_offset;       /* starting sector */
131                 uint32_t        p_fsize;        /* filesystem basic fragment size */
132                 uint8_t p_fstype;       /* filesystem type, see below */
133                 uint8_t p_frag;         /* filesystem fragments per block */
134                 uint16_t        p_cpg;          /* filesystem cylinders per group */
135         } d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */
136 };
137
138 /* d_type values: */
139 #define BSD_DTYPE_SMD           1               /* SMD, XSMD; VAX hp/up */
140 #define BSD_DTYPE_MSCP          2               /* MSCP */
141 #define BSD_DTYPE_DEC           3               /* other DEC (rk, rl) */
142 #define BSD_DTYPE_SCSI          4               /* SCSI */
143 #define BSD_DTYPE_ESDI          5               /* ESDI interface */
144 #define BSD_DTYPE_ST506         6               /* ST506 etc. */
145 #define BSD_DTYPE_HPIB          7               /* CS/80 on HP-IB */
146 #define BSD_DTYPE_HPFL          8               /* HP Fiber-link */
147 #define BSD_DTYPE_FLOPPY        10              /* floppy */
148
149 /* d_subtype values: */
150 #define BSD_DSTYPE_INDOSPART    0x8             /* is inside dos partition */
151 #define BSD_DSTYPE_DOSPART(s)   ((s) & 3)       /* dos partition number */
152 #define BSD_DSTYPE_GEOMETRY     0x10            /* drive params in label */
153
154 #ifdef DKTYPENAMES
155 static char *xbsd_dktypenames[] = {
156         "unknown",
157         "SMD",
158         "MSCP",
159         "old DEC",
160         "SCSI",
161         "ESDI",
162         "ST506",
163         "HP-IB",
164         "HP-FL",
165         "type 9",
166         "floppy",
167         0
168 };
169 #define BSD_DKMAXTYPES  (sizeof(xbsd_dktypenames) / sizeof(xbsd_dktypenames[0]) - 1)
170 #endif
171
172 /*
173  * Filesystem type and version.
174  * Used to interpret other filesystem-specific
175  * per-partition information.
176  */
177 #define BSD_FS_UNUSED   0               /* unused */
178 #define BSD_FS_SWAP     1               /* swap */
179 #define BSD_FS_V6       2               /* Sixth Edition */
180 #define BSD_FS_V7       3               /* Seventh Edition */
181 #define BSD_FS_SYSV     4               /* System V */
182 #define BSD_FS_V71K     5               /* V7 with 1K blocks (4.1, 2.9) */
183 #define BSD_FS_V8       6               /* Eighth Edition, 4K blocks */
184 #define BSD_FS_BSDFFS   7               /* 4.2BSD fast file system */
185 #define BSD_FS_BSDLFS   9               /* 4.4BSD log-structured file system */
186 #define BSD_FS_OTHER    10              /* in use, but unknown/unsupported */
187 #define BSD_FS_HPFS     11              /* OS/2 high-performance file system */
188 #define BSD_FS_ISO9660  12              /* ISO-9660 filesystem (cdrom) */
189 #define BSD_FS_ISOFS    BSD_FS_ISO9660
190 #define BSD_FS_BOOT     13              /* partition contains bootstrap */
191 #define BSD_FS_ADOS     14              /* AmigaDOS fast file system */
192 #define BSD_FS_HFS      15              /* Macintosh HFS */
193 #define BSD_FS_ADVFS    16              /* Digital Unix AdvFS */
194
195 /* this is annoying, but it's also the way it is :-( */
196 #ifdef __alpha__
197 #define BSD_FS_EXT2     8               /* ext2 file system */
198 #else
199 #define BSD_FS_MSDOS    8               /* MS-DOS file system */
200 #endif
201
202 #ifdef  DKTYPENAMES
203 static struct systypes xbsd_fstypes[] = {
204         {BSD_FS_UNUSED, "unused"},
205         {BSD_FS_SWAP,   "swap"},
206         {BSD_FS_V6,     "Version 6"},
207         {BSD_FS_V7,     "Version 7"},
208         {BSD_FS_SYSV,   "System V"},
209         {BSD_FS_V71K,   "4.1BSD"},
210         {BSD_FS_V8,     "Eighth Edition"},
211         {BSD_FS_BSDFFS, "4.2BSD"},
212 #ifdef __alpha__
213         {BSD_FS_EXT2,   "ext2"},
214 #else
215         {BSD_FS_MSDOS,  "MS-DOS"},
216 #endif
217         {BSD_FS_BSDLFS, "4.4LFS"},
218         {BSD_FS_OTHER,  "unknown"},
219         {BSD_FS_HPFS,   "HPFS"},
220         {BSD_FS_ISO9660,"ISO-9660"},
221         {BSD_FS_BOOT,   "boot"},
222         {BSD_FS_ADOS,   "ADOS"},
223         {BSD_FS_HFS,    "HFS"},
224         {BSD_FS_ADVFS,  "AdvFS"},
225         { 0, NULL }
226 };
227 #define BSD_FSMAXTYPES (ARRAY_SIZE(xbsd_fstypes)-1)
228
229 #endif
230
231 /*
232  * flags shared by various drives:
233  */
234 #define BSD_D_REMOVABLE 0x01            /* removable media */
235 #define BSD_D_ECC       0x02            /* supports ECC */
236 #define BSD_D_BADSECT   0x04            /* supports bad sector forw. */
237 #define BSD_D_RAMDISK   0x08            /* disk emulator */
238 #define BSD_D_CHAIN     0x10            /* can do back-back transfers */
239 #define BSD_D_DOSPART   0x20            /* within MSDOS partition */
240
241 #endif /* FDISK_BSD_LABEL_H */