disklabel.h revision 105056
1193323Sed/*
2193323Sed * Copyright (c) 1987, 1988, 1993
3193323Sed *	The Regents of the University of California.  All rights reserved.
4193323Sed *
5193323Sed * Redistribution and use in source and binary forms, with or without
6193323Sed * modification, are permitted provided that the following conditions
7193323Sed * are met:
8193323Sed * 1. Redistributions of source code must retain the above copyright
9193323Sed *    notice, this list of conditions and the following disclaimer.
10193323Sed * 2. Redistributions in binary form must reproduce the above copyright
11193323Sed *    notice, this list of conditions and the following disclaimer in the
12193323Sed *    documentation and/or other materials provided with the distribution.
13193323Sed * 3. All advertising materials mentioning features or use of this software
14193323Sed *    must display the following acknowledgement:
15193323Sed *	This product includes software developed by the University of
16193323Sed *	California, Berkeley and its contributors.
17249423Sdim * 4. Neither the name of the University nor the names of its contributors
18249423Sdim *    may be used to endorse or promote products derived from this software
19193323Sed *    without specific prior written permission.
20249423Sdim *
21193323Sed * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22243830Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23193323Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24193323Sed * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25193323Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26193323Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27193323Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28193323Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29193323Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30193323Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31193323Sed * SUCH DAMAGE.
32193323Sed *
33193323Sed *	@(#)disklabel.h	8.2 (Berkeley) 7/10/94
34193323Sed * $FreeBSD: head/sys/sys/disklabel.h 105056 2002-10-13 17:28:14Z phk $
35193323Sed */
36193323Sed
37193323Sed#ifndef _SYS_DISKLABEL_H_
38193323Sed#define	_SYS_DISKLABEL_H_
39193323Sed
40193323Sed#ifndef _KERNEL
41193323Sed#include <sys/types.h>
42193323Sed#endif
43249423Sdim#include <sys/ioccom.h>
44249423Sdim
45249423Sdim/*
46193323Sed * Disk description table, see disktab(5)
47249423Sdim */
48249423Sdim#define	_PATH_DISKTAB	"/etc/disktab"
49193323Sed
50249423Sdim/*
51249423Sdim * Each disk has a label which includes information about the hardware
52249423Sdim * disk geometry, filesystem partitions, and drive specific information.
53193323Sed * The label is in block 0 or 1, possibly offset from the beginning
54249423Sdim * to leave room for a bootstrap, etc.
55249423Sdim */
56249423Sdim
57193323Sed/* XXX these should be defined per controller (or drive) elsewhere, not here! */
58249423Sdim#ifdef __i386__
59249423Sdim#define LABELSECTOR	1			/* sector containing label */
60249423Sdim#define LABELOFFSET	0			/* offset of label in sector */
61193323Sed#endif
62193323Sed
63193323Sed#ifdef __alpha__
64193323Sed#define LABELSECTOR	0
65193323Sed#define LABELOFFSET	64
66193323Sed#endif
67193323Sed
68193323Sed#ifdef __ia64__
69193323Sed#define LABELSECTOR	1
70234353Sdim#define LABELOFFSET	0
71234353Sdim#endif
72234353Sdim
73234353Sdim#ifdef __sparc64__
74193323Sed#define LABELSECTOR	0
75193323Sed#define LABELOFFSET	128
76249423Sdim#endif
77193323Sed
78193323Sed#ifndef	LABELSECTOR
79193323Sed#define LABELSECTOR	0
80193323Sed#endif
81193323Sed
82198090Srdivacky#ifndef	LABELOFFSET
83198090Srdivacky#define LABELOFFSET	64
84198090Srdivacky#endif
85198090Srdivacky
86198090Srdivacky#define DISKMAGIC	((u_int32_t)0x82564557)	/* The disk magic number */
87193323Sed#ifndef MAXPARTITIONS
88193323Sed#define	MAXPARTITIONS	8
89198090Srdivacky#endif
90198090Srdivacky
91193323Sed/* Size of bootblock area in sector-size neutral bytes */
92193323Sed#define BBSIZE		8192
93193323Sed
94193323Sed#define	LABEL_PART	2		/* partition containing label */
95193323Sed#define	RAW_PART	2		/* partition containing whole disk */
96249423Sdim#define	SWAP_PART	1		/* partition normally containing swap */
97249423Sdim
98249423Sdimstruct disklabel {
99249423Sdim	u_int32_t d_magic;		/* the magic number */
100249423Sdim	u_int16_t d_type;		/* drive type */
101249423Sdim	u_int16_t d_subtype;		/* controller/d_type specific */
102249423Sdim	char	  d_typename[16];	/* type name, e.g. "eagle" */
103249423Sdim
104249423Sdim	char      d_packname[16];	/* pack identifier */
105193323Sed
106249423Sdim			/* disk geometry: */
107249423Sdim	u_int32_t d_secsize;		/* # of bytes per sector */
108249423Sdim	u_int32_t d_nsectors;		/* # of data sectors per track */
109249423Sdim	u_int32_t d_ntracks;		/* # of tracks per cylinder */
110249423Sdim	u_int32_t d_ncylinders;		/* # of data cylinders per unit */
111193323Sed	u_int32_t d_secpercyl;		/* # of data sectors per cylinder */
112249423Sdim	u_int32_t d_secperunit;		/* # of data sectors per unit */
113249423Sdim
114249423Sdim	/*
115249423Sdim	 * Spares (bad sector replacements) below are not counted in
116193323Sed	 * d_nsectors or d_secpercyl.  Spare sectors are assumed to
117193323Sed	 * be physical sectors which occupy space at the end of each
118193323Sed	 * track and/or cylinder.
119210299Sed	 */
120210299Sed	u_int16_t d_sparespertrack;	/* # of spare sectors per track */
121221345Sdim	u_int16_t d_sparespercyl;	/* # of spare sectors per cylinder */
122210299Sed	/*
123193323Sed	 * Alternate cylinders include maintenance, replacement, configuration
124198090Srdivacky	 * description areas, etc.
125198090Srdivacky	 */
126193323Sed	u_int32_t d_acylinders;		/* # of alt. cylinders per unit */
127249423Sdim
128249423Sdim			/* hardware characteristics: */
129249423Sdim	/*
130249423Sdim	 * d_interleave, d_trackskew and d_cylskew describe perturbations
131193323Sed	 * in the media format used to compensate for a slow controller.
132249423Sdim	 * Interleave is physical sector interleave, set up by the
133249423Sdim	 * formatter or controller when formatting.  When interleaving is
134263508Sdim	 * in use, logically adjacent sectors are not physically
135249423Sdim	 * contiguous, but instead are separated by some number of
136249423Sdim	 * sectors.  It is specified as the ratio of physical sectors
137249423Sdim	 * traversed per logical sector.  Thus an interleave of 1:1
138249423Sdim	 * implies contiguous layout, while 2:1 implies that logical
139249423Sdim	 * sector 0 is separated by one sector from logical sector 1.
140249423Sdim	 * d_trackskew is the offset of sector 0 on track N relative to
141249423Sdim	 * sector 0 on track N-1 on the same cylinder.  Finally, d_cylskew
142249423Sdim	 * is the offset of sector 0 on cylinder N relative to sector 0
143249423Sdim	 * on cylinder N-1.
144263508Sdim	 */
145249423Sdim	u_int16_t d_rpm;		/* rotational speed */
146249423Sdim	u_int16_t d_interleave;		/* hardware sector interleave */
147249423Sdim	u_int16_t d_trackskew;		/* sector 0 skew, per track */
148249423Sdim	u_int16_t d_cylskew;		/* sector 0 skew, per cylinder */
149249423Sdim	u_int32_t d_headswitch;		/* head switch time, usec */
150193323Sed	u_int32_t d_trkseek;		/* track-to-track seek, usec */
151193323Sed	u_int32_t d_flags;		/* generic flags */
152193323Sed#define NDDATA 5
153193323Sed	u_int32_t d_drivedata[NDDATA];	/* drive-type specific information */
154193323Sed#define NSPARE 5
155193323Sed	u_int32_t d_spare[NSPARE];	/* reserved for future use */
156193323Sed	u_int32_t d_magic2;		/* the magic number (again) */
157193323Sed	u_int16_t d_checksum;		/* xor of data incl. partitions */
158193323Sed
159193323Sed			/* filesystem and partition information: */
160198090Srdivacky	u_int16_t d_npartitions;	/* number of partitions in following */
161198090Srdivacky	u_int32_t d_bbsize;		/* size of boot area at sn0, bytes */
162198090Srdivacky	u_int32_t d_sbsize;		/* max size of fs superblock, bytes */
163193323Sed	struct partition {		/* the partition table */
164198090Srdivacky		u_int32_t p_size;	/* number of sectors in partition */
165243830Sdim		u_int32_t p_offset;	/* starting sector */
166193323Sed		u_int32_t p_fsize;	/* filesystem basic fragment size */
167249423Sdim		u_int8_t p_fstype;	/* filesystem type, see below */
168249423Sdim		u_int8_t p_frag;	/* filesystem fragments per block */
169249423Sdim		u_int16_t p_cpg;	/* filesystem cylinders per group */
170198090Srdivacky	} d_partitions[MAXPARTITIONS];	/* actually may be more */
171249423Sdim};
172249423Sdim
173234353Sdim#ifdef CTASSERT
174198090SrdivackyCTASSERT(sizeof(struct disklabel) == 148 + MAXPARTITIONS * 16);
175198090Srdivacky#endif
176198090Srdivacky
177198090Srdivackystatic __inline u_int16_t dkcksum(struct disklabel *lp);
178198090Srdivackystatic __inline u_int16_t
179198090Srdivackydkcksum(struct disklabel *lp)
180198090Srdivacky{
181234353Sdim	u_int16_t *start, *end;
182198090Srdivacky	u_int16_t sum = 0;
183198090Srdivacky
184198090Srdivacky	start = (u_int16_t *)lp;
185198090Srdivacky	end = (u_int16_t *)&lp->d_partitions[lp->d_npartitions];
186198090Srdivacky	while (start < end)
187249423Sdim		sum ^= *start++;
188249423Sdim	return (sum);
189249423Sdim}
190249423Sdim
191198090Srdivacky
192198090Srdivacky/* d_type values: */
193198090Srdivacky#define	DTYPE_SMD		1		/* SMD, XSMD; VAX hp/up */
194210299Sed#define	DTYPE_MSCP		2		/* MSCP */
195210299Sed#define	DTYPE_DEC		3		/* other DEC (rk, rl) */
196210299Sed#define	DTYPE_SCSI		4		/* SCSI */
197210299Sed#define	DTYPE_ESDI		5		/* ESDI interface */
198210299Sed#define	DTYPE_ST506		6		/* ST506 etc. */
199210299Sed#define	DTYPE_HPIB		7		/* CS/80 on HP-IB */
200198090Srdivacky#define	DTYPE_HPFL		8		/* HP Fiber-link */
201198090Srdivacky#define	DTYPE_FLOPPY		10		/* floppy */
202198090Srdivacky#define	DTYPE_CCD		11		/* concatenated disk */
203198090Srdivacky#define	DTYPE_VINUM		12		/* vinum volume */
204193323Sed#define	DTYPE_DOC2K		13		/* Msys DiskOnChip */
205198090Srdivacky#define	DTYPE_JFS2		16		/* IBM JFS 2 */
206193323Sed
207193323Sed#ifdef DKTYPENAMES
208193323Sedstatic const char *dktypenames[] = {
209	"unknown",
210	"SMD",
211	"MSCP",
212	"old DEC",
213	"SCSI",
214	"ESDI",
215	"ST506",
216	"HP-IB",
217	"HP-FL",
218	"type 9",
219	"floppy",
220	"CCD",
221	"Vinum",
222	"DOC2K",
223	"?",
224	"?",
225	"jfs",
226	NULL
227};
228#define DKMAXTYPES	(sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
229#endif
230
231/*
232 * Filesystem type and version.
233 * Used to interpret other filesystem-specific
234 * per-partition information.
235 */
236#define	FS_UNUSED	0		/* unused */
237#define	FS_SWAP		1		/* swap */
238#define	FS_V6		2		/* Sixth Edition */
239#define	FS_V7		3		/* Seventh Edition */
240#define	FS_SYSV		4		/* System V */
241#define	FS_V71K		5		/* V7 with 1K blocks (4.1, 2.9) */
242#define	FS_V8		6		/* Eighth Edition, 4K blocks */
243#define	FS_BSDFFS	7		/* 4.2BSD fast filesystem */
244#define	FS_MSDOS	8		/* MSDOS filesystem */
245#define	FS_BSDLFS	9		/* 4.4BSD log-structured filesystem */
246#define	FS_OTHER	10		/* in use, but unknown/unsupported */
247#define	FS_HPFS		11		/* OS/2 high-performance filesystem */
248#define	FS_ISO9660	12		/* ISO 9660, normally CD-ROM */
249#define	FS_BOOT		13		/* partition contains bootstrap */
250#define	FS_VINUM	14		/* Vinum drive */
251#define	FS_JFS2		21		/* IBM JFS2 */
252
253#ifdef	FSTYPENAMES
254static const char *fstypenames[] = {
255	"unused",
256	"swap",
257	"Version 6",
258	"Version 7",
259	"System V",
260	"4.1BSD",
261	"Eighth Edition",
262	"4.2BSD",
263	"MSDOS",
264	"4.4LFS",
265	"unknown",
266	"HPFS",
267	"ISO9660",
268	"boot",
269	"vinum",
270	"?",
271	"?",
272	"?",
273	"?",
274	"?",
275	"?",
276	"jfs",
277	NULL
278};
279#define FSMAXTYPES	(sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
280#endif
281
282/*
283 * flags shared by various drives:
284 */
285#define	D_REMOVABLE	0x01		/* removable media */
286#define	D_ECC		0x02		/* supports ECC */
287#define	D_BADSECT	0x04		/* supports bad sector forw. */
288#define	D_RAMDISK	0x08		/* disk emulator */
289#define	D_CHAIN		0x10		/* can do back-back transfers */
290
291/*
292 * Disklabel-specific ioctls.
293 *
294 * NB: <sys/disk.h> defines ioctls from 'd'/128 and up.
295 */
296		/* get and set disklabel */
297#define DIOCGDINFO	_IOR('d', 101, struct disklabel)/* get */
298#define DIOCSDINFO	_IOW('d', 102, struct disklabel)/* set */
299#define DIOCWDINFO	_IOW('d', 103, struct disklabel)/* set, update disk */
300
301#define DIOCWLABEL	_IOW('d', 109, int)	/* write en/disable label */
302
303#ifdef _KERNEL
304
305/*
306 * XXX encoding of disk minor numbers, should be elsewhere.
307 *
308 * See <sys/reboot.h> for a possibly better encoding.
309 *
310 * "cpio -H newc" can be used to back up device files with large minor
311 * numbers (but not ones >= 2^31).  Old cpio formats and all tar formats
312 * don't have enough bits, and cpio and tar don't notice the lossage.
313 * There are also some sign extension bugs.
314 */
315
316/*
317       3                   2                   1                   0
318     1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
319    _________________________________________________________________
320    | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
321    -----------------------------------------------------------------
322    |    SPARE    |UNIT_2 | SLICE   |  MAJOR?       |  UNIT   |PART |
323    -----------------------------------------------------------------
324*/
325
326#define	DKMAXUNIT	0x1ff
327
328#define	dkmakeminor(unit, slice, part) \
329				(((slice) << 16) | (((unit) & 0x1e0) << 16) | \
330				(((unit) & 0x1f) << 3) | (part))
331#define	dkpart(dev)		(minor(dev) & 7)
332#define	dkslice(dev)		((minor(dev) >> 16) & 0x1f)
333#define	dksparebits(dev)       	((minor(dev) >> 25) & 0x7f)
334
335struct	bio;
336struct	bio_queue_head;
337
338int	bounds_check_with_label(struct bio *bp, struct disklabel *lp,
339	    int wlabel);
340dev_t	dkmodpart(dev_t dev, int part);
341dev_t	dkmodslice(dev_t dev, int slice);
342u_int	dkunit(dev_t dev);
343char	*readdisklabel(dev_t dev, struct disklabel *lp);
344int	setdisklabel(struct disklabel *olp, struct disklabel *nlp,
345	    u_long openmask);
346int	writedisklabel(dev_t dev, struct disklabel *lp);
347#ifdef __alpha__
348struct	buf;
349void	alpha_fix_srm_checksum(struct buf *bp);
350#endif
351
352#endif /* _KERNEL */
353
354
355#ifndef _KERNEL
356__BEGIN_DECLS
357struct disklabel *getdiskbyname(const char *);
358__END_DECLS
359#endif
360
361#endif /* !_SYS_DISKLABEL_H_ */
362