xref: /onnv-gate/usr/src/uts/common/sys/vtoc.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 1997-1998,2002 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate 
28*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
29*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #ifndef _SYS_VTOC_H
33*0Sstevel@tonic-gate #define	_SYS_VTOC_H
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #include <sys/dklabel.h>
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate #ifdef	__cplusplus
40*0Sstevel@tonic-gate extern "C" {
41*0Sstevel@tonic-gate #endif
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate /*
44*0Sstevel@tonic-gate  *	Note:  the VTOC is not implemented fully, nor in the manner
45*0Sstevel@tonic-gate  *	that AT&T implements it.  AT&T puts the vtoc structure
46*0Sstevel@tonic-gate  *	into a sector, usually the second sector (pdsector is first).
47*0Sstevel@tonic-gate  *
48*0Sstevel@tonic-gate  *	Sun incorporates the tag, flag, version, and volume vtoc fields into
49*0Sstevel@tonic-gate  *	its Disk Label, which already has some vtoc-equivalent fields.
50*0Sstevel@tonic-gate  *	Upon reading the vtoc with read_vtoc(), the following exceptions
51*0Sstevel@tonic-gate  *	occur:
52*0Sstevel@tonic-gate  *		v_bootinfo [all]	returned as zero
53*0Sstevel@tonic-gate  *		v_sanity		returned as VTOC_SANE
54*0Sstevel@tonic-gate  *						if Disk Label was sane
55*0Sstevel@tonic-gate  *		v_sectorsz		returned as 512
56*0Sstevel@tonic-gate  *		v_reserved [all]	retunred as zero
57*0Sstevel@tonic-gate  *		timestamp [all]		returned as zero
58*0Sstevel@tonic-gate  *
59*0Sstevel@tonic-gate  *	See  dklabel.h, read_vtoc(), and write_vtoc().
60*0Sstevel@tonic-gate  */
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate #define	V_NUMPAR 	NDKMAP		/* The number of partitions */
63*0Sstevel@tonic-gate 					/* (from dkio.h) */
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate #define	VTOC_SANE	0x600DDEEE	/* Indicates a sane VTOC */
66*0Sstevel@tonic-gate #define	V_VERSION	0x01		/* layout version number */
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate /*
69*0Sstevel@tonic-gate  * Partition identification tags
70*0Sstevel@tonic-gate  */
71*0Sstevel@tonic-gate #define	V_UNASSIGNED	0x00		/* unassigned partition */
72*0Sstevel@tonic-gate #define	V_BOOT		0x01		/* Boot partition */
73*0Sstevel@tonic-gate #define	V_ROOT		0x02		/* Root filesystem */
74*0Sstevel@tonic-gate #define	V_SWAP		0x03		/* Swap filesystem */
75*0Sstevel@tonic-gate #define	V_USR		0x04		/* Usr filesystem */
76*0Sstevel@tonic-gate #define	V_BACKUP	0x05		/* full disk */
77*0Sstevel@tonic-gate #define	V_STAND		0x06		/* Stand partition */
78*0Sstevel@tonic-gate #define	V_VAR		0x07		/* Var partition */
79*0Sstevel@tonic-gate #define	V_HOME		0x08		/* Home partition */
80*0Sstevel@tonic-gate #define	V_ALTSCTR	0x09		/* Alternate sector partition */
81*0Sstevel@tonic-gate #define	V_CACHE		0x0a		/* Cache (cachefs) partition */
82*0Sstevel@tonic-gate #define	V_RESERVED	0x0b		/* SMI reserved data */
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate /*
85*0Sstevel@tonic-gate  * Partition permission flags
86*0Sstevel@tonic-gate  */
87*0Sstevel@tonic-gate #define	V_UNMNT		0x01		/* Unmountable partition */
88*0Sstevel@tonic-gate #define	V_RONLY		0x10		/* Read only */
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate /*
91*0Sstevel@tonic-gate  * error codes for reading & writing vtoc
92*0Sstevel@tonic-gate  */
93*0Sstevel@tonic-gate #define	VT_ERROR	(-2)		/* errno supplies specific error */
94*0Sstevel@tonic-gate #define	VT_EIO		(-3)		/* I/O error accessing vtoc */
95*0Sstevel@tonic-gate #define	VT_EINVAL	(-4)		/* illegal value in vtoc or request */
96*0Sstevel@tonic-gate #define	VT_ENOTSUP	(-5)		/* VTOC op. not supported */
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate struct partition	{
99*0Sstevel@tonic-gate 	ushort_t p_tag;			/* ID tag of partition */
100*0Sstevel@tonic-gate 	ushort_t p_flag;			/* permision flags */
101*0Sstevel@tonic-gate 	daddr_t	p_start;		/* start sector no of partition */
102*0Sstevel@tonic-gate 	long	p_size;			/* # of blocks in partition */
103*0Sstevel@tonic-gate };
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate struct vtoc {
106*0Sstevel@tonic-gate 	unsigned long	v_bootinfo[3];	/* info needed by mboot (unsupported) */
107*0Sstevel@tonic-gate 	unsigned long	v_sanity;	/* to verify vtoc sanity */
108*0Sstevel@tonic-gate 	unsigned long	v_version;	/* layout version */
109*0Sstevel@tonic-gate 	char	v_volume[LEN_DKL_VVOL];	/* volume name */
110*0Sstevel@tonic-gate 	ushort_t	v_sectorsz;	/* sector size in bytes */
111*0Sstevel@tonic-gate 	ushort_t	v_nparts;	/* number of partitions */
112*0Sstevel@tonic-gate 	unsigned long	v_reserved[10];	/* free space */
113*0Sstevel@tonic-gate 	struct partition v_part[V_NUMPAR]; /* partition headers */
114*0Sstevel@tonic-gate 	time_t	timestamp[V_NUMPAR];	/* partition timestamp (unsupported) */
115*0Sstevel@tonic-gate 	char	v_asciilabel[LEN_DKL_ASCII];	/* for compatibility */
116*0Sstevel@tonic-gate };
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate #if defined(_SYSCALL32)
119*0Sstevel@tonic-gate struct partition32	{
120*0Sstevel@tonic-gate 	uint16_t	p_tag;		/* ID tag of partition */
121*0Sstevel@tonic-gate 	uint16_t	p_flag;		/* permision flags */
122*0Sstevel@tonic-gate 	daddr32_t	p_start;	/* start sector no of partition */
123*0Sstevel@tonic-gate 	int32_t		p_size;		/* # of blocks in partition */
124*0Sstevel@tonic-gate };
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate struct vtoc32 {
127*0Sstevel@tonic-gate 	uint32_t	v_bootinfo[3];	/* info needed by mboot (unsupported) */
128*0Sstevel@tonic-gate 	uint32_t	v_sanity;	/* to verify vtoc sanity */
129*0Sstevel@tonic-gate 	uint32_t	v_version;	/* layout version */
130*0Sstevel@tonic-gate 	char	v_volume[LEN_DKL_VVOL];	/* volume name */
131*0Sstevel@tonic-gate 	uint16_t	v_sectorsz;	/* sector size in bytes */
132*0Sstevel@tonic-gate 	uint16_t	v_nparts;	/* number of partitions */
133*0Sstevel@tonic-gate 	uint32_t	v_reserved[10];	/* free space */
134*0Sstevel@tonic-gate 	struct partition32 v_part[V_NUMPAR]; /* partition headers */
135*0Sstevel@tonic-gate 	time32_t timestamp[V_NUMPAR];	/* partition timestamp (unsupported) */
136*0Sstevel@tonic-gate 	char	v_asciilabel[LEN_DKL_ASCII];	/* for compatibility */
137*0Sstevel@tonic-gate };
138*0Sstevel@tonic-gate 
139*0Sstevel@tonic-gate #define	vtoc32tovtoc(v32, v)				\
140*0Sstevel@tonic-gate 	{						\
141*0Sstevel@tonic-gate 	int i;						\
142*0Sstevel@tonic-gate 	v.v_bootinfo[0]		= v32.v_bootinfo[0];	\
143*0Sstevel@tonic-gate 	v.v_bootinfo[1]		= v32.v_bootinfo[1];	\
144*0Sstevel@tonic-gate 	v.v_bootinfo[2]		= v32.v_bootinfo[2];	\
145*0Sstevel@tonic-gate 	v.v_sanity		= v32.v_sanity;		\
146*0Sstevel@tonic-gate 	v.v_version		= v32.v_version;	\
147*0Sstevel@tonic-gate 	bcopy(v32.v_volume, v.v_volume, LEN_DKL_VVOL);	\
148*0Sstevel@tonic-gate 	v.v_sectorsz		= v32.v_sectorsz;	\
149*0Sstevel@tonic-gate 	v.v_nparts		= v32.v_nparts;		\
150*0Sstevel@tonic-gate 	v.v_version		= v32.v_version;	\
151*0Sstevel@tonic-gate 	for (i = 0; i < 10; i++)			\
152*0Sstevel@tonic-gate 		v.v_reserved[i] = v32.v_reserved[i];	\
153*0Sstevel@tonic-gate 	for (i = 0; i < V_NUMPAR; i++) {		\
154*0Sstevel@tonic-gate 		v.v_part[i].p_tag = (ushort_t)v32.v_part[i].p_tag;	\
155*0Sstevel@tonic-gate 		v.v_part[i].p_flag = (ushort_t)v32.v_part[i].p_flag;	\
156*0Sstevel@tonic-gate 		v.v_part[i].p_start = (daddr_t)v32.v_part[i].p_start;	\
157*0Sstevel@tonic-gate 		v.v_part[i].p_size = (long)v32.v_part[i].p_size;	\
158*0Sstevel@tonic-gate 	}						\
159*0Sstevel@tonic-gate 	for (i = 0; i < V_NUMPAR; i++)			\
160*0Sstevel@tonic-gate 		v.timestamp[i] = (time_t)v32.timestamp[i];		\
161*0Sstevel@tonic-gate 	bcopy(v32.v_asciilabel, v.v_asciilabel, LEN_DKL_ASCII);		\
162*0Sstevel@tonic-gate 	}
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate #define	vtoctovtoc32(v, v32)				\
165*0Sstevel@tonic-gate 	{						\
166*0Sstevel@tonic-gate 	int i;						\
167*0Sstevel@tonic-gate 	v32.v_bootinfo[0]	= v.v_bootinfo[0];	\
168*0Sstevel@tonic-gate 	v32.v_bootinfo[1]	= v.v_bootinfo[1];	\
169*0Sstevel@tonic-gate 	v32.v_bootinfo[2]	= v.v_bootinfo[2];	\
170*0Sstevel@tonic-gate 	v32.v_sanity		= v.v_sanity;		\
171*0Sstevel@tonic-gate 	v32.v_version		= v.v_version;		\
172*0Sstevel@tonic-gate 	bcopy(v.v_volume, v32.v_volume, LEN_DKL_VVOL);	\
173*0Sstevel@tonic-gate 	v32.v_sectorsz		= v.v_sectorsz;		\
174*0Sstevel@tonic-gate 	v32.v_nparts		= v.v_nparts;		\
175*0Sstevel@tonic-gate 	v32.v_version		= v.v_version;		\
176*0Sstevel@tonic-gate 	for (i = 0; i < 10; i++)			\
177*0Sstevel@tonic-gate 		v32.v_reserved[i] = v.v_reserved[i];	\
178*0Sstevel@tonic-gate 	for (i = 0; i < V_NUMPAR; i++) {		\
179*0Sstevel@tonic-gate 		v32.v_part[i].p_tag = (ushort_t)v.v_part[i].p_tag;	\
180*0Sstevel@tonic-gate 		v32.v_part[i].p_flag = (ushort_t)v.v_part[i].p_flag;	\
181*0Sstevel@tonic-gate 		v32.v_part[i].p_start = (daddr32_t)v.v_part[i].p_start;	\
182*0Sstevel@tonic-gate 		v32.v_part[i].p_size = (int32_t)v.v_part[i].p_size;	\
183*0Sstevel@tonic-gate 	}						\
184*0Sstevel@tonic-gate 	for (i = 0; i < V_NUMPAR; i++) {		\
185*0Sstevel@tonic-gate 		if (v.timestamp[i] > TIME32_MAX)	\
186*0Sstevel@tonic-gate 			v32.timestamp[i] = TIME32_MAX;	\
187*0Sstevel@tonic-gate 		else 					\
188*0Sstevel@tonic-gate 			v32.timestamp[i] = (time32_t)v.timestamp[i];	\
189*0Sstevel@tonic-gate 	}						\
190*0Sstevel@tonic-gate 	bcopy(v.v_asciilabel, v32.v_asciilabel, LEN_DKL_ASCII);		\
191*0Sstevel@tonic-gate 	}
192*0Sstevel@tonic-gate 
193*0Sstevel@tonic-gate #endif /* _SYSCALL32 */
194*0Sstevel@tonic-gate 
195*0Sstevel@tonic-gate /*
196*0Sstevel@tonic-gate  * These defines are the mode parameter for the checksum routines.
197*0Sstevel@tonic-gate  */
198*0Sstevel@tonic-gate #define	CK_CHECKSUM	0	/* check checksum */
199*0Sstevel@tonic-gate #define	CK_MAKESUM	1	/* generate checksum */
200*0Sstevel@tonic-gate 
201*0Sstevel@tonic-gate #if defined(__STDC__)
202*0Sstevel@tonic-gate 
203*0Sstevel@tonic-gate extern	int	read_vtoc(int, struct vtoc *);
204*0Sstevel@tonic-gate extern	int	write_vtoc(int, struct vtoc *);
205*0Sstevel@tonic-gate 
206*0Sstevel@tonic-gate #else
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate extern	int	read_vtoc();
209*0Sstevel@tonic-gate extern	int	write_vtoc();
210*0Sstevel@tonic-gate 
211*0Sstevel@tonic-gate #endif 	/* __STDC__ */
212*0Sstevel@tonic-gate 
213*0Sstevel@tonic-gate #ifdef	__cplusplus
214*0Sstevel@tonic-gate }
215*0Sstevel@tonic-gate #endif
216*0Sstevel@tonic-gate 
217*0Sstevel@tonic-gate #endif	/* _SYS_VTOC_H */
218