xref: /original-bsd/sys/sys/disklabel.h (revision c3e32dec)
1 /*
2  * Copyright (c) 1987, 1988, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)disklabel.h	8.1 (Berkeley) 06/02/93
8  */
9 
10 /*
11  * Disk description table, see disktab(5)
12  */
13 #define	_PATH_DISKTAB	"/etc/disktab"
14 #define	DISKTAB		"/etc/disktab"		/* deprecated */
15 
16 /*
17  * Each disk has a label which includes information about the hardware
18  * disk geometry, filesystem partitions, and drive specific information.
19  * The label is in block 0 or 1, possibly offset from the beginning
20  * to leave room for a bootstrap, etc.
21  */
22 
23 /* XXX these should be defined per controller (or drive) elsewhere, not here! */
24 #ifdef i386
25 #define LABELSECTOR	1			/* sector containing label */
26 #define LABELOFFSET	0			/* offset of label in sector */
27 #endif
28 
29 #ifndef	LABELSECTOR
30 #define LABELSECTOR	0			/* sector containing label */
31 #endif
32 
33 #ifndef	LABELOFFSET
34 #define LABELOFFSET	64			/* offset of label in sector */
35 #endif
36 
37 #define DISKMAGIC	((u_long) 0x82564557)	/* The disk magic number */
38 #ifndef MAXPARTITIONS
39 #define	MAXPARTITIONS	8
40 #endif
41 
42 
43 #ifndef LOCORE
44 struct disklabel {
45 	u_long	d_magic;		/* the magic number */
46 	short	d_type;			/* drive type */
47 	short	d_subtype;		/* controller/d_type specific */
48 	char	d_typename[16];		/* type name, e.g. "eagle" */
49 	/*
50 	 * d_packname contains the pack identifier and is returned when
51 	 * the disklabel is read off the disk or in-core copy.
52 	 * d_boot0 and d_boot1 are the (optional) names of the
53 	 * primary (block 0) and secondary (block 1-15) bootstraps
54 	 * as found in /usr/mdec.  These are returned when using
55 	 * getdiskbyname(3) to retrieve the values from /etc/disktab.
56 	 */
57 #if defined(KERNEL) || defined(STANDALONE)
58 	char	d_packname[16];			/* pack identifier */
59 #else
60 	union {
61 		char	un_d_packname[16];	/* pack identifier */
62 		struct {
63 			char *un_d_boot0;	/* primary bootstrap name */
64 			char *un_d_boot1;	/* secondary bootstrap name */
65 		} un_b;
66 	} d_un;
67 #define d_packname	d_un.un_d_packname
68 #define d_boot0		d_un.un_b.un_d_boot0
69 #define d_boot1		d_un.un_b.un_d_boot1
70 #endif	/* ! KERNEL or STANDALONE */
71 			/* disk geometry: */
72 	u_long	d_secsize;		/* # of bytes per sector */
73 	u_long	d_nsectors;		/* # of data sectors per track */
74 	u_long	d_ntracks;		/* # of tracks per cylinder */
75 	u_long	d_ncylinders;		/* # of data cylinders per unit */
76 	u_long	d_secpercyl;		/* # of data sectors per cylinder */
77 	u_long	d_secperunit;		/* # of data sectors per unit */
78 	/*
79 	 * Spares (bad sector replacements) below
80 	 * are not counted in d_nsectors or d_secpercyl.
81 	 * Spare sectors are assumed to be physical sectors
82 	 * which occupy space at the end of each track and/or cylinder.
83 	 */
84 	u_short	d_sparespertrack;	/* # of spare sectors per track */
85 	u_short	d_sparespercyl;		/* # of spare sectors per cylinder */
86 	/*
87 	 * Alternate cylinders include maintenance, replacement,
88 	 * configuration description areas, etc.
89 	 */
90 	u_long	d_acylinders;		/* # of alt. cylinders per unit */
91 
92 			/* hardware characteristics: */
93 	/*
94 	 * d_interleave, d_trackskew and d_cylskew describe perturbations
95 	 * in the media format used to compensate for a slow controller.
96 	 * Interleave is physical sector interleave, set up by the formatter
97 	 * or controller when formatting.  When interleaving is in use,
98 	 * logically adjacent sectors are not physically contiguous,
99 	 * but instead are separated by some number of sectors.
100 	 * It is specified as the ratio of physical sectors traversed
101 	 * per logical sector.  Thus an interleave of 1:1 implies contiguous
102 	 * layout, while 2:1 implies that logical sector 0 is separated
103 	 * by one sector from logical sector 1.
104 	 * d_trackskew is the offset of sector 0 on track N
105 	 * relative to sector 0 on track N-1 on the same cylinder.
106 	 * Finally, d_cylskew is the offset of sector 0 on cylinder N
107 	 * relative to sector 0 on cylinder N-1.
108 	 */
109 	u_short	d_rpm;			/* rotational speed */
110 	u_short	d_interleave;		/* hardware sector interleave */
111 	u_short	d_trackskew;		/* sector 0 skew, per track */
112 	u_short	d_cylskew;		/* sector 0 skew, per cylinder */
113 	u_long	d_headswitch;		/* head switch time, usec */
114 	u_long	d_trkseek;		/* track-to-track seek, usec */
115 	u_long	d_flags;		/* generic flags */
116 #define NDDATA 5
117 	u_long	d_drivedata[NDDATA];	/* drive-type specific information */
118 #define NSPARE 5
119 	u_long	d_spare[NSPARE];	/* reserved for future use */
120 	u_long	d_magic2;		/* the magic number (again) */
121 	u_short	d_checksum;		/* xor of data incl. partitions */
122 
123 			/* filesystem and partition information: */
124 	u_short	d_npartitions;		/* number of partitions in following */
125 	u_long	d_bbsize;		/* size of boot area at sn0, bytes */
126 	u_long	d_sbsize;		/* max size of fs superblock, bytes */
127 	struct	partition {		/* the partition table */
128 		u_long	p_size;		/* number of sectors in partition */
129 		u_long	p_offset;	/* starting sector */
130 		u_long	p_fsize;	/* filesystem basic fragment size */
131 		u_char	p_fstype;	/* filesystem type, see below */
132 		u_char	p_frag;		/* filesystem fragments per block */
133 		union {
134 			u_short	cpg;	/* UFS: FS cylinders per group */
135 			u_short	sgs;	/* LFS: FS segment shift */
136 		} __partition_u1;
137 #define	p_cpg	__partition_u1.cpg
138 #define	p_sgs	__partition_u1.sgs
139 	} d_partitions[MAXPARTITIONS];	/* actually may be more */
140 };
141 #else /* LOCORE */
142 	/*
143 	 * offsets for asm boot files.
144 	 */
145 	.set	d_secsize,40
146 	.set	d_nsectors,44
147 	.set	d_ntracks,48
148 	.set	d_ncylinders,52
149 	.set	d_secpercyl,56
150 	.set	d_secperunit,60
151 	.set	d_end_,276		/* size of disk label */
152 #endif /* LOCORE */
153 
154 /* d_type values: */
155 #define	DTYPE_SMD		1		/* SMD, XSMD; VAX hp/up */
156 #define	DTYPE_MSCP		2		/* MSCP */
157 #define	DTYPE_DEC		3		/* other DEC (rk, rl) */
158 #define	DTYPE_SCSI		4		/* SCSI */
159 #define	DTYPE_ESDI		5		/* ESDI interface */
160 #define	DTYPE_ST506		6		/* ST506 etc. */
161 #define	DTYPE_HPIB		7		/* CS/80 on HP-IB */
162 #define	DTYPE_HPFL		8		/* HP Fiber-link */
163 #define	DTYPE_FLOPPY		10		/* floppy */
164 
165 #ifdef DKTYPENAMES
166 static char *dktypenames[] = {
167 	"unknown",
168 	"SMD",
169 	"MSCP",
170 	"old DEC",
171 	"SCSI",
172 	"ESDI",
173 	"ST506",
174 	"HP-IB",
175 	"HP-FL",
176 	"type 9",
177 	"floppy",
178 	0
179 };
180 #define DKMAXTYPES	(sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
181 #endif
182 
183 /*
184  * Filesystem type and version.
185  * Used to interpret other filesystem-specific
186  * per-partition information.
187  */
188 #define	FS_UNUSED	0		/* unused */
189 #define	FS_SWAP		1		/* swap */
190 #define	FS_V6		2		/* Sixth Edition */
191 #define	FS_V7		3		/* Seventh Edition */
192 #define	FS_SYSV		4		/* System V */
193 #define	FS_V71K		5		/* V7 with 1K blocks (4.1, 2.9) */
194 #define	FS_V8		6		/* Eighth Edition, 4K blocks */
195 #define	FS_BSDFFS	7		/* 4.2BSD fast file system */
196 #define	FS_MSDOS	8		/* MSDOS file system */
197 #define	FS_BSDLFS	9		/* 4.4BSD log-structured file system */
198 #define	FS_OTHER	10		/* in use, but unknown/unsupported */
199 #define	FS_HPFS		11		/* OS/2 high-performance file system */
200 #define	FS_ISO9660	12		/* ISO 9660, normally CD-ROM */
201 #define	FS_BOOT		13		/* partition contains bootstrap */
202 
203 #ifdef	DKTYPENAMES
204 static char *fstypenames[] = {
205 	"unused",
206 	"swap",
207 	"Version 6",
208 	"Version 7",
209 	"System V",
210 	"4.1BSD",
211 	"Eighth Edition",
212 	"4.2BSD",
213 	"MSDOS",
214 	"4.4LFS",
215 	"unknown",
216 	"HPFS",
217 	"ISO9660",
218 	"boot",
219 	0
220 };
221 #define FSMAXTYPES	(sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
222 #endif
223 
224 /*
225  * flags shared by various drives:
226  */
227 #define		D_REMOVABLE	0x01		/* removable media */
228 #define		D_ECC		0x02		/* supports ECC */
229 #define		D_BADSECT	0x04		/* supports bad sector forw. */
230 #define		D_RAMDISK	0x08		/* disk emulator */
231 #define		D_CHAIN		0x10		/* can do back-back transfers */
232 
233 /*
234  * Drive data for SMD.
235  */
236 #define	d_smdflags	d_drivedata[0]
237 #define		D_SSE		0x1		/* supports skip sectoring */
238 #define	d_mindist	d_drivedata[1]
239 #define	d_maxdist	d_drivedata[2]
240 #define	d_sdist		d_drivedata[3]
241 
242 /*
243  * Drive data for ST506.
244  */
245 #define d_precompcyl	d_drivedata[0]
246 #define d_gap3		d_drivedata[1]		/* used only when formatting */
247 
248 /*
249  * Drive data for SCSI.
250  */
251 #define	d_blind		d_drivedata[0]
252 
253 #ifndef LOCORE
254 /*
255  * Structure used to perform a format
256  * or other raw operation, returning data
257  * and/or register values.
258  * Register identification and format
259  * are device- and driver-dependent.
260  */
261 struct format_op {
262 	char	*df_buf;
263 	int	df_count;		/* value-result */
264 	daddr_t	df_startblk;
265 	int	df_reg[8];		/* result */
266 };
267 
268 /*
269  * Structure used internally to retrieve
270  * information about a partition on a disk.
271  */
272 struct partinfo {
273 	struct disklabel *disklab;
274 	struct partition *part;
275 };
276 
277 /*
278  * Disk-specific ioctls.
279  */
280 		/* get and set disklabel; DIOCGPART used internally */
281 #define DIOCGDINFO	_IOR('d', 101, struct disklabel)/* get */
282 #define DIOCSDINFO	_IOW('d', 102, struct disklabel)/* set */
283 #define DIOCWDINFO	_IOW('d', 103, struct disklabel)/* set, update disk */
284 #define DIOCGPART	_IOW('d', 104, struct partinfo)	/* get partition */
285 
286 /* do format operation, read or write */
287 #define DIOCRFORMAT	_IOWR('d', 105, struct format_op)
288 #define DIOCWFORMAT	_IOWR('d', 106, struct format_op)
289 
290 #define DIOCSSTEP	_IOW('d', 107, int)	/* set step rate */
291 #define DIOCSRETRIES	_IOW('d', 108, int)	/* set # of retries */
292 #define DIOCWLABEL	_IOW('d', 109, int)	/* write en/disable label */
293 
294 #define DIOCSBAD	_IOW('d', 110, struct dkbad)	/* set kernel dkbad */
295 
296 #endif /* LOCORE */
297 
298 #if !defined(KERNEL) && !defined(LOCORE)
299 
300 #include <sys/cdefs.h>
301 
302 __BEGIN_DECLS
303 struct disklabel *getdiskbyname __P((const char *));
304 __END_DECLS
305 
306 #endif
307