xref: /NextBSD/sys/sys/mach/device/disk_status.h (revision 33da5adc555b3bc29986eeadca03829e4ad06b1e)
1 /*
2  * Copyright 1991-1998 by Open Software Foundation, Inc.
3  *              All Rights Reserved
4  *
5  * Permission to use, copy, modify, and distribute this software and
6  * its documentation for any purpose and without fee is hereby granted,
7  * provided that the above copyright notice appears in all copies and
8  * that both the copyright notice and this permission notice appear in
9  * supporting documentation.
10  *
11  * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
12  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13  * FOR A PARTICULAR PURPOSE.
14  *
15  * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
16  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17  * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
18  * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
19  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  */
21 /*
22  * MkLinux
23  */
24 /* CMU_HIST */
25 /*
26  * Revision 2.3.4.2  92/04/30  11:49:19  bernadat
27  * 	Changes from TRUNK:
28  * 	We add one more partition so that we can point to the "whole"
29  * 	  	disk.  It is at slot MAXPARTITIONS.
30  * 	  	[92/04/01            rvb]
31  *
32  * Revision 2.3.4.1  92/02/18  18:39:17  jeffreyh
33  * 	Increase number of disk partitions to 16 to be compatible with 2.5
34  * 	[92/02/08            bernadat]
35  *
36  * Revision 2.3  91/05/14  15:43:50  mrt
37  * 	Correcting copyright
38  *
39  * Revision 2.2  91/05/13  06:02:21  af
40  * 	Created, starting from Reno's disklabel.h (copyright included).
41  * 	[91/05/03            af]
42  *
43  */
44 /* CMU_ENDHIST */
45 /*
46  * Mach Operating System
47  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
48  * All Rights Reserved.
49  *
50  * Permission to use, copy, modify and distribute this software and its
51  * documentation is hereby granted, provided that both the copyright
52  * notice and this permission notice appear in all copies of the
53  * software, derivative works or modified versions, and any portions
54  * thereof, and that both notices appear in supporting documentation.
55  *
56  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
57  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
58  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
59  *
60  * Carnegie Mellon requests users of this software to return to
61  *
62  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
63  *  School of Computer Science
64  *  Carnegie Mellon University
65  *  Pittsburgh PA 15213-3890
66  *
67  * any improvements or extensions that they make and grant Carnegie Mellon
68  * the rights to redistribute these changes.
69  */
70 /*
71  */
72 /*
73  * Copyright (c) 1987, 1988 Regents of the University of California.
74  * All rights reserved.
75  *
76  * Redistribution and use in source and binary forms are permitted
77  * provided that the above copyright notice and this paragraph are
78  * duplicated in all such forms and that any documentation,
79  * advertising materials, and other materials related to such
80  * distribution and use acknowledge that the software was developed
81  * by the University of California, Berkeley.  The name of the
82  * University may not be used to endorse or promote products derived
83  * from this software without specific prior written permission.
84  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
85  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
86  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
87  *
88  *	@(#)disklabel.h	7.10 (Berkeley) 6/27/88
89  */
90 
91 #ifndef	_DISK_STATUS_H_
92 #define	_DISK_STATUS_H_
93 
94 #include <device/ds_status.h>
95 
96 /*
97  * Each disk has a label which includes information about the hardware
98  * disk geometry, filesystem partitions, and drive specific information.
99  * The label is in block 0 or 1, possibly offset from the beginning
100  * to leave room for a bootstrap, etc.
101  */
102 
103 #ifdef hp_pa
104 
105 #ifndef LABELSECTOR
106 #define LABELSECTOR	2       /* sector containing label */
107 #endif
108 #define LABELOFFSET	0	/* offset of label in sector */
109 
110 #else /* hp_pa */
111 
112 #define LABELSECTOR	0	/* sector containing label */
113 #define LABELOFFSET	64	/* offset of label in sector */
114 
115 #endif /* hp_pa */
116 
117 #define DISKMAGIC	((uint32) 0x82564557U)	/* The disk magic number */
118 
119 #ifndef MAXPARTITIONS
120 #ifdef hp_pa
121 #define	MAXPARTITIONS	8
122 #else
123 #define	MAXPARTITIONS	16
124 #define PARTITIONS	(MAXPARTITIONS + 1)
125 #endif
126 #endif
127 
128 #ifndef PARTITIONS
129 #define PARTITIONS	MAXPARTITIONS
130 #endif
131 
132 #ifndef LOCORE
133 struct disklabel {
134 	uint32	d_magic;		/* the magic number */
135 	short	d_type;			/* drive type */
136 	short	d_subtype;		/* controller/d_type specific */
137 	char	d_typename[16];		/* type name, e.g. "eagle" */
138 	/*
139 	 * d_packname contains the pack identifier and is returned when
140 	 * the disklabel is read off the disk or in-core copy.
141 	 * d_boot0 and d_boot1 are the (optional) names of the
142 	 * primary (block 0) and secondary (block 1-15) bootstraps
143 	 * as found in /usr/mdec.  These are returned when using
144 	 * getdiskbyname(3) to retrieve the values from /etc/disktab.
145 	 */
146 #if defined(MACH_KERNEL) || defined(STANDALONE)
147 	char	d_packname[16];			/* pack identifier */
148 #else
149 	union {
150 		char	un_d_packname[16];	/* pack identifier */
151 		struct {
152 			char *un_d_boot0;	/* primary bootstrap name */
153 			char *un_d_boot1;	/* secondary bootstrap name */
154 		} un_b;
155 	} d_un;
156 #define d_packname	d_un.un_d_packname
157 #define d_boot0		d_un.un_b.un_d_boot0
158 #define d_boot1		d_un.un_b.un_d_boot1
159 #endif	/* ! MACH_KERNEL or STANDALONE */
160 			/* disk geometry: */
161 	uint32	d_secsize;		/* # of bytes per sector */
162 	uint32	d_nsectors;		/* # of data sectors per track */
163 	uint32	d_ntracks;		/* # of tracks per cylinder */
164 	uint32	d_ncylinders;		/* # of data cylinders per unit */
165 	uint32	d_secpercyl;		/* # of data sectors per cylinder */
166 	uint32	d_secperunit;		/* # of data sectors per unit */
167 	/*
168 	 * Spares (bad sector replacements) below
169 	 * are not counted in d_nsectors or d_secpercyl.
170 	 * Spare sectors are assumed to be physical sectors
171 	 * which occupy space at the end of each track and/or cylinder.
172 	 */
173 	unsigned short	d_sparespertrack;	/* # of spare sectors per track */
174 	unsigned short	d_sparespercyl;		/* # of spare sectors per cylinder */
175 	/*
176 	 * Alternate cylinders include maintenance, replacement,
177 	 * configuration description areas, etc.
178 	 */
179 	uint32	d_acylinders;		/* # of alt. cylinders per unit */
180 
181 			/* hardware characteristics: */
182 	/*
183 	 * d_interleave, d_trackskew and d_cylskew describe perturbations
184 	 * in the media format used to compensate for a slow controller.
185 	 * Interleave is physical sector interleave, set up by the formatter
186 	 * or controller when formatting.  When interleaving is in use,
187 	 * logically adjacent sectors are not physically contiguous,
188 	 * but instead are separated by some number of sectors.
189 	 * It is specified as the ratio of physical sectors traversed
190 	 * per logical sector.  Thus an interleave of 1:1 implies contiguous
191 	 * layout, while 2:1 implies that logical sector 0 is separated
192 	 * by one sector from logical sector 1.
193 	 * d_trackskew is the offset of sector 0 on track N
194 	 * relative to sector 0 on track N-1 on the same cylinder.
195 	 * Finally, d_cylskew is the offset of sector 0 on cylinder N
196 	 * relative to sector 0 on cylinder N-1.
197 	 */
198 	unsigned short	d_rpm;			/* rotational speed */
199 	unsigned short	d_interleave;		/* hardware sector interleave */
200 	unsigned short	d_trackskew;		/* sector 0 skew, per track */
201 	unsigned short	d_cylskew;		/* sector 0 skew, per cylinder */
202 	uint32	d_headswitch;		/* head switch time, usec */
203 	uint32	d_trkseek;		/* track-to-track seek, usec */
204 	uint32	d_flags;		/* generic flags */
205 #define NDDATA 5
206 	uint32	d_drivedata[NDDATA];	/* drive-type specific information */
207 #define NSPARE 5
208 	uint32	d_spare[NSPARE];	/* reserved for future use */
209 	uint32	d_magic2;		/* the magic number (again) */
210 	unsigned short	d_checksum;		/* xor of data incl. partitions */
211 
212 			/* filesystem and partition information: */
213 	unsigned short	d_npartitions;		/* number of partitions in following */
214 	uint32	d_bbsize;		/* size of boot area at sn0, bytes */
215 	uint32	d_sbsize;		/* max size of fs superblock, bytes */
216 	struct	label_partition {		/* the partition table */
217 		uint32	p_size;		/* number of sectors in partition */
218 		uint32	p_offset;	/* starting sector */
219 		uint32	p_fsize;	/* filesystem basic fragment size */
220 		unsigned char	p_fstype;	/* filesystem type, see below */
221 		unsigned char	p_frag;		/* filesystem fragments per block */
222 		unsigned short	p_cpg;		/* filesystem cylinders per group */
223 	} d_partitions[PARTITIONS];	/* actually may be more */
224 
225 #if	defined(__alpha) && defined(MACH_KERNEL)
226 	/*
227 	 * Disgusting hack. If this structure contains a pointer,
228 	 * as it does for non-kernel, then the compiler rounds
229 	 * the size to make it pointer-sized properly (arrays of..).
230 	 * But if I define the pointer for the kernel then instances
231 	 * of this structure better be aligned otherwise picking
232 	 * up a short might be done by too-smart compilers (GCC) with
233 	 * a load-long instruction expecting the short to be aligned.
234 	 */
235 	int32	bugfix;
236 #endif
237 };
238 #else /* LOCORE */
239 	/*
240 	 * offsets for asm boot files.
241 	 */
242 	.set	d_secsize,40
243 	.set	d_nsectors,44
244 	.set	d_ntracks,48
245 	.set	d_ncylinders,52
246 	.set	d_secpercyl,56
247 	.set	d_secperunit,60
248 	.set	d_end_,276		/* size of disk label */
249 #endif /* LOCORE */
250 
251 /* d_type values: */
252 #define	DTYPE_SMD		1		/* SMD, XSMD; VAX hp/up */
253 #define	DTYPE_MSCP		2		/* MSCP */
254 #define	DTYPE_DEC		3		/* other DEC (rk, rl) */
255 #define	DTYPE_SCSI		4		/* SCSI */
256 #define	DTYPE_ESDI		5		/* ESDI interface */
257 #define	DTYPE_ST506		6		/* ST506 etc. */
258 #define	DTYPE_IPI		7		/* IPI */
259 #define	DTYPE_FLOPPY		10		/* floppy */
260 
261 #ifdef DKTYPENAMES
262 static char *dktypenames[] = {
263 	"unknown",
264 	"SMD",
265 	"MSCP",
266 	"old DEC",
267 	"SCSI",
268 	"ESDI",
269 	"type 6",
270 	"IPI",
271 	"type 8",
272 	"type 9",
273 	"floppy",
274 	0
275 };
276 #define DKMAXTYPES	(sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
277 #endif
278 
279 /*
280  * Filesystem type and version.
281  * Used to interpret other filesystem-specific
282  * per-partition information.
283  */
284 #define	FS_UNUSED	0		/* unused */
285 #define	FS_SWAP		1		/* swap */
286 #define	FS_V6		2		/* Sixth Edition */
287 #define	FS_V7		3		/* Seventh Edition */
288 #define	FS_SYSV		4		/* System V */
289 #define	FS_V71K		5		/* V7 with 1K blocks (4.1, 2.9) */
290 #define	FS_V8		6		/* Eighth Edition, 4K blocks */
291 #define	FS_BSDFFS	7		/* 4.2BSD fast file system */
292 #define	FS_LVM		8		/* Partition in use by LVM */
293 
294 #define	FS_VENDOR1	16		/* Reserved for vendor use */
295 #define	FS_VENDOR2	17		/* Reserved for vendor use */
296 #define	FS_VENDOR3	18		/* Reserved for vendor use */
297 #define	FS_VENDOR4	19		/* Reserved for vendor use */
298 #define	FS_VENDOR5	20		/* Reserved for vendor use */
299 #define	FS_VENDOR6	21		/* Reserved for vendor use */
300 #define	FS_VENDOR7	22		/* Reserved for vendor use */
301 #define	FS_VENDOR8	23		/* Reserved for vendor use */
302 #define	FS_VENDOR9	24		/* Reserved for vendor use */
303 #define	FS_VENDOR10	25		/* Reserved for vendor use */
304 #define	FS_VENDOR11	26		/* Reserved for vendor use */
305 #define	FS_VENDOR12	27		/* Reserved for vendor use */
306 #define	FS_VENDOR13	28		/* Reserved for vendor use */
307 #define	FS_VENDOR14	29		/* Reserved for vendor use */
308 #define	FS_VENDOR15	30		/* Reserved for vendor use */
309 #define	FS_VENDOR16	31		/* Reserved for vendor use */
310 
311 #ifdef	DKTYPENAMES
312 static char *fstypenames[] = {
313 	"unused",
314 	"swap",
315 	"Version 6",
316 	"Version 7",
317 	"System V",
318 	"4.1BSD",
319 	"Eighth Edition",
320 	"4.2BSD",
321 	"LVM",
322 	"???",
323 	"???",
324 	"???",
325 	"???",
326 	"???",
327 	"???",
328 	"???",
329 	"vendor 1",
330 	"vendor 2",
331 	"vendor 3",
332 	"vendor 4",
333 	"vendor 5",
334 	"vendor 6",
335 	"vendor 7",
336 	"vendor 8",
337 	"vendor 9",
338 	"vendor 10",
339 	"vendor 11",
340 	"vendor 12",
341 	"vendor 13",
342 	"vendor 14",
343 	"vendor 15",
344 	"vendor 16",
345 	0
346 };
347 #define FSMAXTYPES	(sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
348 #endif
349 
350 /*
351  * flags shared by various drives:
352  */
353 #define		D_REMOVABLE	0x01		/* removable media */
354 #define		D_ECC		0x02		/* supports ECC */
355 #define		D_BADSECT	0x04		/* supports bad sector forw. */
356 #define		D_RAMDISK	0x08		/* disk emulator */
357 #define		D_CHAIN		0x10		/* can do back-back transfers */
358 
359 /*
360  * Drive data for SMD.
361  */
362 #define	d_smdflags	d_drivedata[0]
363 #define		D_SSE		0x1		/* supports skip sectoring */
364 #define	d_mindist	d_drivedata[1]
365 #define	d_maxdist	d_drivedata[2]
366 #define	d_sdist		d_drivedata[3]
367 
368 /*
369  * Drive data for ST506.
370  */
371 #define d_precompcyl	d_drivedata[0]
372 #define d_gap3		d_drivedata[1]		/* used only when formatting */
373 
374 /*
375  * IBM controller info (d_precompcyl used, too)
376  */
377 #define	d_step		d_drivedata[2]
378 
379 #ifndef LOCORE
380 /*
381  * Structure used to perform a format
382  * or other raw operation, returning data
383  * and/or register values.
384  * Register identification and format
385  * are device- and driver-dependent.
386  */
387 struct format_op {
388 	char	*df_buf;
389 	int	df_count;		/* value-result */
390 	daddr_t	df_startblk;
391 	int	df_reg[8];		/* result */
392 };
393 
394 /*
395  * Structure used internally to retrieve
396  * information about a partition on a disk.
397  */
398 struct partinfo {
399 	struct disklabel *disklab;
400 	struct label_partition *part;
401 };
402 
403 /*
404  * Disk-specific ioctls.
405  */
406 		/* get and set disklabel; DIOCGPART used internally */
407 #define DIOCGDINFO	_IOR('d', 101, struct disklabel)/* get */
408 #define DIOCSDINFO	_IOW('d', 102, struct disklabel)/* set */
409 #define DIOCWDINFO	_IOW('d', 103, struct disklabel)/* set, update disk */
410 #define DIOCGPART	_IOW('d', 104, struct partinfo)	/* get partition */
411 
412 /* do format operation, read or write */
413 #define DIOCRFORMAT	_IOWR('d', 105, struct format_op)
414 #define DIOCWFORMAT	_IOWR('d', 106, struct format_op)
415 
416 #define DIOCSSTEP	_IOW('d', 107, int)	/* set step rate */
417 #define DIOCSRETRIES	_IOW('d', 108, int)	/* set # of retries */
418 #define DIOCWLABEL	_IOW('d', 109, int)	/* write en/disable label */
419 
420 #define DIOCSBAD	_IOW('d', 110, struct dkbad)	/* set kernel dkbad */
421 
422 /*
423  * These are really generic SCSI ioctls and structures
424  * but will probably be used with disks most often
425  */
426 /*
427  * Structure used to perform SCSI pass-through commands
428  */
429 struct scsi_io {
430 #define SCSI_CDB_LENGTH 12
431 	unsigned char	cdb[SCSI_CDB_LENGTH];
432 	unsigned long	cmd_count;
433 #define SCSI_NONE	(0 << 0)
434 #define MEM_TO_SCSI	(1 << 0)
435 #define SCSI_TO_MEM	(1 << 1)
436 	unsigned long	direction;
437 #define SCSI_GOOD			0x00
438 #define SCSI_CHECK_CONDITION		0x01
439 #define SCSI_CONDITION_MET		0x02
440 #define SCSI_BUSY			0x03
441 #define SCSI_INTERMEDIATE		0x04
442 #define SCSI_INTERMEDIATE_CONDITION_MET	0x05
443 #define SCSI_RESERVATION_CONFLICT	0x06
444 #define SCSI_COMMAND_TERMINATED		0x07
445 #define SCSI_QUEUE_FULL			0x08
446 	unsigned long	status;
447 	unsigned long	buf_len;
448 #define SCSI_BUF_MAX	(2 * 1024)
449 	unsigned char	scsi_buff[SCSI_BUF_MAX];
450 };
451 
452 /* SCSI pass-through command */
453 #define DIOCSCSI	_IOWR('d', 111, struct scsi_io)
454 
455 /*
456  * Structure used to get SCSI device physical information
457  */
458 struct scsi_phys {
459 	unsigned long	slot;
460 	unsigned char	controller;
461 	unsigned char	target_id;
462 	unsigned char	lun;
463 };
464 
465 /* Get SCSI device physical information */
466 #define DIOCGPHYS	_IOR('d', 112, struct scsi_phys)
467 /* Just get partition information.  Used interally in unix server. */
468 #define DIOCGPINFO	_IOR('d', 113, struct label_partition)
469 /* Get the mach record size. */
470 #define DIOMRINFO	_IOR('d', 114, int)
471 
472 #endif	/* LOCORE */
473 
474 #endif	/* _DISK_STATUS_H_ */
475