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