xref: /original-bsd/sys/sys/disklabel.h (revision 3b6250d9)
1 /*
2  * Copyright (c) 1987, 1988 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)disklabel.h	7.21 (Berkeley) 11/04/91
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_FLOPPY		10		/* floppy */
162 
163 #ifdef DKTYPENAMES
164 static char *dktypenames[] = {
165 	"unknown",
166 	"SMD",
167 	"MSCP",
168 	"old DEC",
169 	"SCSI",
170 	"ESDI",
171 	"ST506",
172 	"type 7",
173 	"type 8",
174 	"type 9",
175 	"floppy",
176 	0
177 };
178 #define DKMAXTYPES	(sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
179 #endif
180 
181 /*
182  * Filesystem type and version.
183  * Used to interpret other filesystem-specific
184  * per-partition information.
185  */
186 #define	FS_UNUSED	0		/* unused */
187 #define	FS_SWAP		1		/* swap */
188 #define	FS_V6		2		/* Sixth Edition */
189 #define	FS_V7		3		/* Seventh Edition */
190 #define	FS_SYSV		4		/* System V */
191 #define	FS_V71K		5		/* V7 with 1K blocks (4.1, 2.9) */
192 #define	FS_V8		6		/* Eighth Edition, 4K blocks */
193 #define	FS_BSDFFS	7		/* 4.2BSD fast file system */
194 #define	FS_MSDOS	8		/* MSDOS file system */
195 #define	FS_BSDLFS	9		/* 4.4BSD log-structured file system */
196 
197 #ifdef	DKTYPENAMES
198 static char *fstypenames[] = {
199 	"unused",
200 	"swap",
201 	"Version 6",
202 	"Version 7",
203 	"System V",
204 	"4.1BSD",
205 	"Eighth Edition",
206 	"4.2BSD",
207 	"MSDOS",
208 	"4.4LFS",
209 	0
210 };
211 #define FSMAXTYPES	(sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
212 #endif
213 
214 /*
215  * flags shared by various drives:
216  */
217 #define		D_REMOVABLE	0x01		/* removable media */
218 #define		D_ECC		0x02		/* supports ECC */
219 #define		D_BADSECT	0x04		/* supports bad sector forw. */
220 #define		D_RAMDISK	0x08		/* disk emulator */
221 #define		D_CHAIN		0x10		/* can do back-back transfers */
222 
223 /*
224  * Drive data for SMD.
225  */
226 #define	d_smdflags	d_drivedata[0]
227 #define		D_SSE		0x1		/* supports skip sectoring */
228 #define	d_mindist	d_drivedata[1]
229 #define	d_maxdist	d_drivedata[2]
230 #define	d_sdist		d_drivedata[3]
231 
232 /*
233  * Drive data for ST506.
234  */
235 #define d_precompcyl	d_drivedata[0]
236 #define d_gap3		d_drivedata[1]		/* used only when formatting */
237 
238 /*
239  * Drive data for SCSI.
240  */
241 #define	d_blind		d_drivedata[0]
242 
243 #ifndef LOCORE
244 /*
245  * Structure used to perform a format
246  * or other raw operation, returning data
247  * and/or register values.
248  * Register identification and format
249  * are device- and driver-dependent.
250  */
251 struct format_op {
252 	char	*df_buf;
253 	int	df_count;		/* value-result */
254 	daddr_t	df_startblk;
255 	int	df_reg[8];		/* result */
256 };
257 
258 /*
259  * Structure used internally to retrieve
260  * information about a partition on a disk.
261  */
262 struct partinfo {
263 	struct disklabel *disklab;
264 	struct partition *part;
265 };
266 
267 /*
268  * Disk-specific ioctls.
269  */
270 		/* get and set disklabel; DIOCGPART used internally */
271 #define DIOCGDINFO	_IOR('d', 101, struct disklabel)/* get */
272 #define DIOCSDINFO	_IOW('d', 102, struct disklabel)/* set */
273 #define DIOCWDINFO	_IOW('d', 103, struct disklabel)/* set, update disk */
274 #define DIOCGPART	_IOW('d', 104, struct partinfo)	/* get partition */
275 
276 /* do format operation, read or write */
277 #define DIOCRFORMAT	_IOWR('d', 105, struct format_op)
278 #define DIOCWFORMAT	_IOWR('d', 106, struct format_op)
279 
280 #define DIOCSSTEP	_IOW('d', 107, int)	/* set step rate */
281 #define DIOCSRETRIES	_IOW('d', 108, int)	/* set # of retries */
282 #define DIOCWLABEL	_IOW('d', 109, int)	/* write en/disable label */
283 
284 #define DIOCSBAD	_IOW('d', 110, struct dkbad)	/* set kernel dkbad */
285 
286 #endif LOCORE
287 
288 #if !defined(KERNEL) && !defined(LOCORE)
289 
290 #include <sys/cdefs.h>
291 
292 __BEGIN_DECLS
293 struct disklabel *getdiskbyname __P((const char *));
294 __END_DECLS
295 
296 #endif
297