xref: /titanic_51/usr/src/uts/common/sys/dklabel.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1990-2002 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _SYS_DKLABEL_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_DKLABEL_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/types32.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
37*7c478bd9Sstevel@tonic-gate extern "C" {
38*7c478bd9Sstevel@tonic-gate #endif
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate /*
41*7c478bd9Sstevel@tonic-gate  * Miscellaneous defines
42*7c478bd9Sstevel@tonic-gate  */
43*7c478bd9Sstevel@tonic-gate #define	DKL_MAGIC	0xDABE		/* magic number */
44*7c478bd9Sstevel@tonic-gate #define	FKL_MAGIC	0xff		/* magic number for DOS floppies */
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate #if defined(_SUNOS_VTOC_16)
47*7c478bd9Sstevel@tonic-gate #define	NDKMAP		16		/* # of logical partitions */
48*7c478bd9Sstevel@tonic-gate #define	DK_LABEL_LOC	1		/* location of disk label */
49*7c478bd9Sstevel@tonic-gate #elif defined(_SUNOS_VTOC_8)
50*7c478bd9Sstevel@tonic-gate #define	NDKMAP		8		/* # of logical partitions */
51*7c478bd9Sstevel@tonic-gate #define	DK_LABEL_LOC	0		/* location of disk label */
52*7c478bd9Sstevel@tonic-gate #else
53*7c478bd9Sstevel@tonic-gate #error "No VTOC format defined."
54*7c478bd9Sstevel@tonic-gate #endif
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate #define	LEN_DKL_ASCII	128		/* length of dkl_asciilabel */
57*7c478bd9Sstevel@tonic-gate #define	LEN_DKL_VVOL	8		/* length of v_volume */
58*7c478bd9Sstevel@tonic-gate #define	DK_LABEL_SIZE	512		/* size of disk label */
59*7c478bd9Sstevel@tonic-gate #define	DK_MAX_BLOCKS	0x7fffffff	/* max # of blocks handled */
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate /*
62*7c478bd9Sstevel@tonic-gate  * Reserve two cylinders on SCSI disks.
63*7c478bd9Sstevel@tonic-gate  * One is for the backup disk label and the other is for the deviceid.
64*7c478bd9Sstevel@tonic-gate  *
65*7c478bd9Sstevel@tonic-gate  * IPI disks only reserve one cylinder, but they will go away soon.
66*7c478bd9Sstevel@tonic-gate  * CDROMs do not reserve any cylinders.
67*7c478bd9Sstevel@tonic-gate  */
68*7c478bd9Sstevel@tonic-gate #define	DK_ACYL		2
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate /*
71*7c478bd9Sstevel@tonic-gate  * Format of a Sun disk label.
72*7c478bd9Sstevel@tonic-gate  * Resides in cylinder 0, head 0, sector 0.
73*7c478bd9Sstevel@tonic-gate  *
74*7c478bd9Sstevel@tonic-gate  * sizeof (struct dk_label) should be 512 (the current sector size),
75*7c478bd9Sstevel@tonic-gate  * but should the sector size increase, this structure should remain
76*7c478bd9Sstevel@tonic-gate  * at the beginning of the sector.
77*7c478bd9Sstevel@tonic-gate  */
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate /*
80*7c478bd9Sstevel@tonic-gate  * partition headers:  section 1
81*7c478bd9Sstevel@tonic-gate  * Returned in struct dk_allmap by ioctl DKIOC[SG]APART (dkio(7I))
82*7c478bd9Sstevel@tonic-gate  */
83*7c478bd9Sstevel@tonic-gate struct dk_map {
84*7c478bd9Sstevel@tonic-gate 	daddr_t	dkl_cylno;		/* starting cylinder */
85*7c478bd9Sstevel@tonic-gate 	daddr_t	dkl_nblk;		/* number of blocks;  if == 0, */
86*7c478bd9Sstevel@tonic-gate 					/* partition is undefined */
87*7c478bd9Sstevel@tonic-gate };
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate /*
90*7c478bd9Sstevel@tonic-gate  * partition headers:  section 1
91*7c478bd9Sstevel@tonic-gate  * Fixed size for on-disk dk_label
92*7c478bd9Sstevel@tonic-gate  */
93*7c478bd9Sstevel@tonic-gate struct dk_map32 {
94*7c478bd9Sstevel@tonic-gate 	daddr32_t	dkl_cylno;	/* starting cylinder */
95*7c478bd9Sstevel@tonic-gate 	daddr32_t	dkl_nblk;	/* number of blocks;  if == 0, */
96*7c478bd9Sstevel@tonic-gate 					/* partition is undefined */
97*7c478bd9Sstevel@tonic-gate };
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate /*
100*7c478bd9Sstevel@tonic-gate  * partition headers:  section 2,
101*7c478bd9Sstevel@tonic-gate  * brought over from AT&T SVr4 vtoc structure.
102*7c478bd9Sstevel@tonic-gate  */
103*7c478bd9Sstevel@tonic-gate struct dk_map2 {
104*7c478bd9Sstevel@tonic-gate 	uint16_t	p_tag;		/* ID tag of partition */
105*7c478bd9Sstevel@tonic-gate 	uint16_t	p_flag;		/* permission flag */
106*7c478bd9Sstevel@tonic-gate };
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate struct dkl_partition    {
109*7c478bd9Sstevel@tonic-gate 	uint16_t	p_tag;		/* ID tag of partition */
110*7c478bd9Sstevel@tonic-gate 	uint16_t	p_flag;		/* permision flags */
111*7c478bd9Sstevel@tonic-gate 	daddr32_t	p_start;	/* start sector no of partition */
112*7c478bd9Sstevel@tonic-gate 	int32_t		p_size;		/* # of blocks in partition */
113*7c478bd9Sstevel@tonic-gate };
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate /*
117*7c478bd9Sstevel@tonic-gate  * VTOC inclusions from AT&T SVr4
118*7c478bd9Sstevel@tonic-gate  * Fixed sized types for on-disk VTOC
119*7c478bd9Sstevel@tonic-gate  */
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate struct dk_vtoc {
122*7c478bd9Sstevel@tonic-gate #if defined(_SUNOS_VTOC_16)
123*7c478bd9Sstevel@tonic-gate 	uint32_t v_bootinfo[3];		/* info for mboot (unsupported) */
124*7c478bd9Sstevel@tonic-gate 	uint32_t v_sanity;		/* to verify vtoc sanity */
125*7c478bd9Sstevel@tonic-gate 	uint32_t v_version;		/* layout version */
126*7c478bd9Sstevel@tonic-gate 	char    v_volume[LEN_DKL_VVOL];	/* volume name */
127*7c478bd9Sstevel@tonic-gate 	uint16_t v_sectorsz;		/* sector size in bytes */
128*7c478bd9Sstevel@tonic-gate 	uint16_t v_nparts;		/* number of partitions */
129*7c478bd9Sstevel@tonic-gate 	uint32_t v_reserved[10];	/* free space */
130*7c478bd9Sstevel@tonic-gate 	struct dkl_partition v_part[NDKMAP];	/* partition headers */
131*7c478bd9Sstevel@tonic-gate 	time32_t timestamp[NDKMAP];	/* partition timestamp (unsupported) */
132*7c478bd9Sstevel@tonic-gate 	char    v_asciilabel[LEN_DKL_ASCII];	/* for compatibility    */
133*7c478bd9Sstevel@tonic-gate #elif defined(_SUNOS_VTOC_8)
134*7c478bd9Sstevel@tonic-gate 	uint32_t	v_version;		/* layout version */
135*7c478bd9Sstevel@tonic-gate 	char		v_volume[LEN_DKL_VVOL];	/* volume name */
136*7c478bd9Sstevel@tonic-gate 	uint16_t	v_nparts;		/* number of partitions  */
137*7c478bd9Sstevel@tonic-gate 	struct dk_map2	v_part[NDKMAP];		/* partition hdrs, sec 2 */
138*7c478bd9Sstevel@tonic-gate 	uint32_t	v_bootinfo[3];		/* info needed by mboot */
139*7c478bd9Sstevel@tonic-gate 	uint32_t	v_sanity;		/* to verify vtoc sanity */
140*7c478bd9Sstevel@tonic-gate 	uint32_t	v_reserved[10];		/* free space */
141*7c478bd9Sstevel@tonic-gate 	time32_t	v_timestamp[NDKMAP];	/* partition timestamp */
142*7c478bd9Sstevel@tonic-gate #else
143*7c478bd9Sstevel@tonic-gate #error "No VTOC format defined."
144*7c478bd9Sstevel@tonic-gate #endif
145*7c478bd9Sstevel@tonic-gate };
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate /*
148*7c478bd9Sstevel@tonic-gate  * define the amount of disk label padding needed to make
149*7c478bd9Sstevel@tonic-gate  * the entire structure occupy 512 bytes.
150*7c478bd9Sstevel@tonic-gate  */
151*7c478bd9Sstevel@tonic-gate #if defined(_SUNOS_VTOC_16)
152*7c478bd9Sstevel@tonic-gate #define	LEN_DKL_PAD	(DK_LABEL_SIZE - \
153*7c478bd9Sstevel@tonic-gate 			    ((sizeof (struct dk_vtoc) + \
154*7c478bd9Sstevel@tonic-gate 			    (4 * sizeof (uint32_t)) + \
155*7c478bd9Sstevel@tonic-gate 			    (12 * sizeof (uint16_t)) + \
156*7c478bd9Sstevel@tonic-gate 			    (2 * (sizeof (uint16_t))))))
157*7c478bd9Sstevel@tonic-gate #elif defined(_SUNOS_VTOC_8)
158*7c478bd9Sstevel@tonic-gate #define	LEN_DKL_PAD	(DK_LABEL_SIZE \
159*7c478bd9Sstevel@tonic-gate 			    - ((LEN_DKL_ASCII) + \
160*7c478bd9Sstevel@tonic-gate 			    (sizeof (struct dk_vtoc)) + \
161*7c478bd9Sstevel@tonic-gate 			    (sizeof (struct dk_map32)  * NDKMAP) + \
162*7c478bd9Sstevel@tonic-gate 			    (14 * (sizeof (uint16_t))) + \
163*7c478bd9Sstevel@tonic-gate 			    (2 * (sizeof (uint16_t)))))
164*7c478bd9Sstevel@tonic-gate #else
165*7c478bd9Sstevel@tonic-gate #error "No VTOC format defined."
166*7c478bd9Sstevel@tonic-gate #endif
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate struct dk_label {
170*7c478bd9Sstevel@tonic-gate #if defined(_SUNOS_VTOC_16)
171*7c478bd9Sstevel@tonic-gate 	struct  dk_vtoc dkl_vtoc;	/* vtoc inclusions from AT&T SVr4 */
172*7c478bd9Sstevel@tonic-gate 	uint32_t	dkl_pcyl;	/* # of physical cylinders */
173*7c478bd9Sstevel@tonic-gate 	uint32_t	dkl_ncyl;	/* # of data cylinders */
174*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_acyl;	/* # of alternate cylinders */
175*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_bcyl;	/* cyl offset (for fixed head area) */
176*7c478bd9Sstevel@tonic-gate 	uint32_t	dkl_nhead;	/* # of heads */
177*7c478bd9Sstevel@tonic-gate 	uint32_t	dkl_nsect;	/* # of data sectors per track */
178*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_intrlv;	/* interleave factor */
179*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_skew;	/* skew factor */
180*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_apc;	/* alternates per cyl (SCSI only)   */
181*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_rpm;	/* revolutions per minute */
182*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_write_reinstruct;	/* # sectors to skip, writes */
183*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_read_reinstruct;	/* # sectors to skip, reads  */
184*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_extra[4];	/* for compatible expansion */
185*7c478bd9Sstevel@tonic-gate 	char		dkl_pad[LEN_DKL_PAD];	/* unused part of 512 bytes */
186*7c478bd9Sstevel@tonic-gate #elif defined(_SUNOS_VTOC_8)
187*7c478bd9Sstevel@tonic-gate 	char		dkl_asciilabel[LEN_DKL_ASCII]; /* for compatibility */
188*7c478bd9Sstevel@tonic-gate 	struct dk_vtoc	dkl_vtoc;	/* vtoc inclusions from AT&T SVr4 */
189*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_write_reinstruct;	/* # sectors to skip, writes */
190*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_read_reinstruct;	/* # sectors to skip, reads */
191*7c478bd9Sstevel@tonic-gate 	char		dkl_pad[LEN_DKL_PAD]; /* unused part of 512 bytes */
192*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_rpm;	/* rotations per minute */
193*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_pcyl;	/* # physical cylinders */
194*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_apc;	/* alternates per cylinder */
195*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_obs1;	/* obsolete */
196*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_obs2;	/* obsolete */
197*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_intrlv;	/* interleave factor */
198*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_ncyl;	/* # of data cylinders */
199*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_acyl;	/* # of alternate cylinders */
200*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_nhead;	/* # of heads in this partition */
201*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_nsect;	/* # of 512 byte sectors per track */
202*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_obs3;	/* obsolete */
203*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_obs4;	/* obsolete */
204*7c478bd9Sstevel@tonic-gate 	struct dk_map32	dkl_map[NDKMAP]; /* logical partition headers */
205*7c478bd9Sstevel@tonic-gate #else
206*7c478bd9Sstevel@tonic-gate #error "No VTOC format defined."
207*7c478bd9Sstevel@tonic-gate #endif
208*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_magic;	/* identifies this label format */
209*7c478bd9Sstevel@tonic-gate 	uint16_t	dkl_cksum;	/* xor checksum of sector */
210*7c478bd9Sstevel@tonic-gate };
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate #if defined(_SUNOS_VTOC_16)
213*7c478bd9Sstevel@tonic-gate #define	dkl_asciilabel	dkl_vtoc.v_asciilabel
214*7c478bd9Sstevel@tonic-gate #define	v_timestamp	timestamp
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate #elif defined(_SUNOS_VTOC_8)
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate /*
219*7c478bd9Sstevel@tonic-gate  * These defines are for historic compatibility with old drivers.
220*7c478bd9Sstevel@tonic-gate  */
221*7c478bd9Sstevel@tonic-gate #define	dkl_gap1	dkl_obs1	/* used to be gap1 */
222*7c478bd9Sstevel@tonic-gate #define	dkl_gap2	dkl_obs2	/* used to be gap2 */
223*7c478bd9Sstevel@tonic-gate #define	dkl_bhead	dkl_obs3	/* used to be label head offset */
224*7c478bd9Sstevel@tonic-gate #define	dkl_ppart	dkl_obs4	/* used to by physical partition */
225*7c478bd9Sstevel@tonic-gate #else
226*7c478bd9Sstevel@tonic-gate #error "No VTOC format defined."
227*7c478bd9Sstevel@tonic-gate #endif
228*7c478bd9Sstevel@tonic-gate 
229*7c478bd9Sstevel@tonic-gate struct fk_label {			/* DOS floppy label */
230*7c478bd9Sstevel@tonic-gate 	uchar_t  fkl_type;
231*7c478bd9Sstevel@tonic-gate 	uchar_t  fkl_magich;
232*7c478bd9Sstevel@tonic-gate 	uchar_t  fkl_magicl;
233*7c478bd9Sstevel@tonic-gate 	uchar_t  filler;
234*7c478bd9Sstevel@tonic-gate };
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate /*
237*7c478bd9Sstevel@tonic-gate  * Layout of stored fabricated device id  (on-disk)
238*7c478bd9Sstevel@tonic-gate  */
239*7c478bd9Sstevel@tonic-gate #define	DK_DEVID_BLKSIZE	(512)
240*7c478bd9Sstevel@tonic-gate #define	DK_DEVID_SIZE		(DK_DEVID_BLKSIZE - ((sizeof (uchar_t) * 7)))
241*7c478bd9Sstevel@tonic-gate #define	DK_DEVID_REV_MSB	(0)
242*7c478bd9Sstevel@tonic-gate #define	DK_DEVID_REV_LSB	(1)
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate struct dk_devid {
245*7c478bd9Sstevel@tonic-gate 	uchar_t	dkd_rev_hi;			/* revision (MSB) */
246*7c478bd9Sstevel@tonic-gate 	uchar_t	dkd_rev_lo;			/* revision (LSB) */
247*7c478bd9Sstevel@tonic-gate 	uchar_t	dkd_flags;			/* flags (not used yet) */
248*7c478bd9Sstevel@tonic-gate 	uchar_t	dkd_devid[DK_DEVID_SIZE];	/* devid stored here */
249*7c478bd9Sstevel@tonic-gate 	uchar_t	dkd_checksum3;			/* checksum (MSB) */
250*7c478bd9Sstevel@tonic-gate 	uchar_t	dkd_checksum2;
251*7c478bd9Sstevel@tonic-gate 	uchar_t	dkd_checksum1;
252*7c478bd9Sstevel@tonic-gate 	uchar_t	dkd_checksum0;			/* checksum (LSB) */
253*7c478bd9Sstevel@tonic-gate };
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate #define	DKD_GETCHKSUM(dkd)	((dkd)->dkd_checksum3 << 24) + \
256*7c478bd9Sstevel@tonic-gate 				((dkd)->dkd_checksum2 << 16) + \
257*7c478bd9Sstevel@tonic-gate 				((dkd)->dkd_checksum1 << 8)  + \
258*7c478bd9Sstevel@tonic-gate 				((dkd)->dkd_checksum0)
259*7c478bd9Sstevel@tonic-gate 
260*7c478bd9Sstevel@tonic-gate #define	DKD_FORMCHKSUM(c, dkd)	(dkd)->dkd_checksum3 = hibyte(hiword((c))); \
261*7c478bd9Sstevel@tonic-gate 				(dkd)->dkd_checksum2 = lobyte(hiword((c))); \
262*7c478bd9Sstevel@tonic-gate 				(dkd)->dkd_checksum1 = hibyte(loword((c))); \
263*7c478bd9Sstevel@tonic-gate 				(dkd)->dkd_checksum0 = lobyte(loword((c)));
264*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
265*7c478bd9Sstevel@tonic-gate }
266*7c478bd9Sstevel@tonic-gate #endif
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_DKLABEL_H */
269