1/*
2 * Copyright (c) 1987, 1988 Regents of the University of California.
3 * 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
34#include <linux/types.h>	/* for __u32, __u16, __u8, __s16 */
35
36#ifndef BSD_DISKMAGIC
37#define BSD_DISKMAGIC     ((__u32) 0x82564557)
38#endif
39
40#ifndef BSD_MAXPARTITIONS
41#define	BSD_MAXPARTITIONS 16
42#endif
43
44#define BSD_LINUX_BOOTDIR "/usr/ucb/mdec"
45
46#if defined (i386) || defined (__sparc__) || defined (__arm__) || defined (__mips__) || defined (__s390__) || defined (__sh__) || defined(__x86_64__)
47#define BSD_LABELSECTOR   1
48#define BSD_LABELOFFSET   0
49#elif defined (__alpha__) || defined (__powerpc__) || defined (__ia64__) || defined (__hppa__)
50#define BSD_LABELSECTOR   0
51#define BSD_LABELOFFSET   64
52#elif defined (__s390__) || defined (__s390x__)
53#define BSD_LABELSECTOR   1
54#define BSD_LABELOFFSET   0
55#else
56#error unknown architecture
57#endif
58
59#define	BSD_BBSIZE        8192		/* size of boot area, with label */
60#define	BSD_SBSIZE        8192		/* max size of fs superblock */
61
62struct xbsd_disklabel {
63	__u32	d_magic;		/* the magic number */
64	__s16	d_type;			/* drive type */
65	__s16	d_subtype;		/* controller/d_type specific */
66	char	d_typename[16];		/* type name, e.g. "eagle" */
67	char	d_packname[16];			/* pack identifier */
68			/* disk geometry: */
69	__u32	d_secsize;		/* # of bytes per sector */
70	__u32	d_nsectors;		/* # of data sectors per track */
71	__u32	d_ntracks;		/* # of tracks per cylinder */
72	__u32	d_ncylinders;		/* # of data cylinders per unit */
73	__u32	d_secpercyl;		/* # of data sectors per cylinder */
74	__u32	d_secperunit;		/* # of data sectors per unit */
75	/*
76	 * Spares (bad sector replacements) below
77	 * are not counted in d_nsectors or d_secpercyl.
78	 * Spare sectors are assumed to be physical sectors
79	 * which occupy space at the end of each track and/or cylinder.
80	 */
81	__u16	d_sparespertrack;	/* # of spare sectors per track */
82	__u16	d_sparespercyl;		/* # of spare sectors per cylinder */
83	/*
84	 * Alternate cylinders include maintenance, replacement,
85	 * configuration description areas, etc.
86	 */
87	__u32	d_acylinders;		/* # of alt. cylinders per unit */
88
89			/* hardware characteristics: */
90	/*
91	 * d_interleave, d_trackskew and d_cylskew describe perturbations
92	 * in the media format used to compensate for a slow controller.
93	 * Interleave is physical sector interleave, set up by the formatter
94	 * or controller when formatting.  When interleaving is in use,
95	 * logically adjacent sectors are not physically contiguous,
96	 * but instead are separated by some number of sectors.
97	 * It is specified as the ratio of physical sectors traversed
98	 * per logical sector.  Thus an interleave of 1:1 implies contiguous
99	 * layout, while 2:1 implies that logical sector 0 is separated
100	 * by one sector from logical sector 1.
101	 * d_trackskew is the offset of sector 0 on track N
102	 * relative to sector 0 on track N-1 on the same cylinder.
103	 * Finally, d_cylskew is the offset of sector 0 on cylinder N
104	 * relative to sector 0 on cylinder N-1.
105	 */
106	__u16	d_rpm;			/* rotational speed */
107	__u16	d_interleave;		/* hardware sector interleave */
108	__u16	d_trackskew;		/* sector 0 skew, per track */
109	__u16	d_cylskew;		/* sector 0 skew, per cylinder */
110	__u32	d_headswitch;		/* head switch time, usec */
111	__u32	d_trkseek;		/* track-to-track seek, usec */
112	__u32	d_flags;		/* generic flags */
113#define NDDATA 5
114	__u32	d_drivedata[NDDATA];	/* drive-type specific information */
115#define NSPARE 5
116	__u32	d_spare[NSPARE];	/* reserved for future use */
117	__u32	d_magic2;		/* the magic number (again) */
118	__u16	d_checksum;		/* xor of data incl. partitions */
119			/* filesystem and partition information: */
120	__u16	d_npartitions;	        /* number of partitions in following */
121	__u32	d_bbsize;	        /* size of boot area at sn0, bytes */
122	__u32	d_sbsize;	        /* max size of fs superblock, bytes */
123	struct xbsd_partition	 {	/* the partition table */
124		__u32	p_size;	        /* number of sectors in partition */
125		__u32	p_offset;       /* starting sector */
126		__u32	p_fsize;        /* filesystem basic fragment size */
127		__u8	p_fstype;       /* filesystem type, see below */
128		__u8	p_frag;	        /* filesystem fragments per block */
129		__u16	p_cpg;	        /* filesystem cylinders per group */
130	} d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */
131};
132
133/* d_type values: */
134#define	BSD_DTYPE_SMD		1		/* SMD, XSMD; VAX hp/up */
135#define	BSD_DTYPE_MSCP		2		/* MSCP */
136#define	BSD_DTYPE_DEC		3		/* other DEC (rk, rl) */
137#define	BSD_DTYPE_SCSI		4		/* SCSI */
138#define	BSD_DTYPE_ESDI		5		/* ESDI interface */
139#define	BSD_DTYPE_ST506		6		/* ST506 etc. */
140#define	BSD_DTYPE_HPIB		7		/* CS/80 on HP-IB */
141#define BSD_DTYPE_HPFL		8		/* HP Fiber-link */
142#define	BSD_DTYPE_FLOPPY	10		/* floppy */
143
144/* d_subtype values: */
145#define BSD_DSTYPE_INDOSPART	0x8		/* is inside dos partition */
146#define BSD_DSTYPE_DOSPART(s)	((s) & 3)	/* dos partition number */
147#define BSD_DSTYPE_GEOMETRY	0x10		/* drive params in label */
148
149#ifdef DKTYPENAMES
150static char *xbsd_dktypenames[] = {
151	"unknown",
152	"SMD",
153	"MSCP",
154	"old DEC",
155	"SCSI",
156	"ESDI",
157	"ST506",
158	"HP-IB",
159	"HP-FL",
160	"type 9",
161	"floppy",
162	0
163};
164#define BSD_DKMAXTYPES	(sizeof(xbsd_dktypenames) / sizeof(xbsd_dktypenames[0]) - 1)
165#endif
166
167/*
168 * Filesystem type and version.
169 * Used to interpret other filesystem-specific
170 * per-partition information.
171 */
172#define	BSD_FS_UNUSED	0		/* unused */
173#define	BSD_FS_SWAP    	1		/* swap */
174#define	BSD_FS_V6      	2		/* Sixth Edition */
175#define	BSD_FS_V7      	3		/* Seventh Edition */
176#define	BSD_FS_SYSV    	4		/* System V */
177#define	BSD_FS_V71K    	5		/* V7 with 1K blocks (4.1, 2.9) */
178#define	BSD_FS_V8      	6		/* Eighth Edition, 4K blocks */
179#define	BSD_FS_BSDFFS	7		/* 4.2BSD fast file system */
180#define	BSD_FS_BSDLFS	9		/* 4.4BSD log-structured file system */
181#define	BSD_FS_OTHER	10		/* in use, but unknown/unsupported */
182#define	BSD_FS_HPFS	11		/* OS/2 high-performance file system */
183#define	BSD_FS_ISO9660	12		/* ISO-9660 filesystem (cdrom) */
184#define BSD_FS_ISOFS	BSD_FS_ISO9660
185#define BSD_FS_BOOT	13		/* partition contains bootstrap */
186#define BSD_FS_ADOS	14		/* AmigaDOS fast file system */
187#define BSD_FS_HFS	15		/* Macintosh HFS */
188#define BSD_FS_ADVFS	16		/* Digital Unix AdvFS */
189
190/* this is annoying, but it's also the way it is :-( */
191#ifdef __alpha__
192#define	BSD_FS_EXT2	8		/* ext2 file system */
193#else
194#define	BSD_FS_MSDOS	8		/* MS-DOS file system */
195#endif
196
197#ifdef DKTYPENAMES
198static struct systypes xbsd_fstypes[] = {
199        {BSD_FS_UNUSED, "unused"},
200	{BSD_FS_SWAP,   "swap"},
201	{BSD_FS_V6,     "Version 6"},
202	{BSD_FS_V7,     "Version 7"},
203	{BSD_FS_SYSV,   "System V"},
204	{BSD_FS_V71K,   "4.1BSD"},
205	{BSD_FS_V8,     "Eighth Edition"},
206	{BSD_FS_BSDFFS, "4.2BSD"},
207#ifdef __alpha__
208	{BSD_FS_EXT2,   "ext2"},
209#else
210	{BSD_FS_MSDOS,  "MS-DOS"},
211#endif
212	{BSD_FS_BSDLFS, "4.4LFS"},
213	{BSD_FS_OTHER,  "unknown"},
214	{BSD_FS_HPFS,   "HPFS"},
215	{BSD_FS_ISO9660,"ISO-9660"},
216	{BSD_FS_BOOT,   "boot"},
217	{BSD_FS_ADOS,   "ADOS"},
218	{BSD_FS_HFS,    "HFS"},
219	{BSD_FS_ADVFS,	"AdvFS"},
220	{ 0, NULL }
221};
222#define BSD_FSMAXTYPES (SIZE(xbsd_fstypes)-1)
223
224#endif
225
226/*
227 * flags shared by various drives:
228 */
229#define	BSD_D_REMOVABLE	0x01		/* removable media */
230#define	BSD_D_ECC      	0x02		/* supports ECC */
231#define	BSD_D_BADSECT	0x04		/* supports bad sector forw. */
232#define	BSD_D_RAMDISK	0x08		/* disk emulator */
233#define	BSD_D_CHAIN    	0x10		/* can do back-back transfers */
234#define	BSD_D_DOSPART	0x20		/* within MSDOS partition */
235