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