xref: /titanic_51/usr/src/boot/sys/sys/vtoc.h (revision 4a5d661a82b942b6538acd26209d959ce98b593a)
1 /*-
2  * Copyright (c) 2008 Marcel Moolenaar
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef _SYS_VTOC_H_
30 #define	_SYS_VTOC_H_
31 
32 #define	VTOC_TAG_UNASSIGNED	0x00
33 #define	VTOC_TAG_BOOT		0x01
34 #define	VTOC_TAG_ROOT		0x02
35 #define	VTOC_TAG_SWAP		0x03
36 #define	VTOC_TAG_USR		0x04
37 #define	VTOC_TAG_BACKUP		0x05	/* "c" partition */
38 #define	VTOC_TAG_STAND		0x06
39 #define	VTOC_TAG_VAR		0x07
40 #define	VTOC_TAG_HOME		0x08
41 #define	VTOC_TAG_ALTSCTR	0x09	/* alternate sector partition */
42 #define	VTOC_TAG_CACHE		0x0a	/* Solaris cachefs partition */
43 #define	VTOC_TAG_VXVM_PUB	0x0e	/* VxVM public region */
44 #define	VTOC_TAG_VXVM_PRIV	0x0f	/* VxVM private region */
45 
46 /* NetBSD/mips defines this */
47 #define	VTOC_TAG_NETBSD_FFS	0xff
48 
49 /* FreeBSD tags: the high byte equals ELFOSABI_FREEBSD */
50 #define	VTOC_TAG_FREEBSD_SWAP	0x0901
51 #define	VTOC_TAG_FREEBSD_UFS	0x0902
52 #define	VTOC_TAG_FREEBSD_VINUM	0x0903
53 #define	VTOC_TAG_FREEBSD_ZFS	0x0904
54 #define	VTOC_TAG_FREEBSD_NANDFS	0x0905
55 
56 #define	VTOC_FLAG_UNMNT		0x01	/* unmountable partition */
57 #define	VTOC_FLAG_RDONLY	0x10    /* partition is read/only */
58 
59 #define	VTOC_ASCII_LEN	128
60 #define	VTOC_BOOTSIZE	8192		/* 16 sectors */
61 #define	VTOC_MAGIC	0xdabe
62 #define	VTOC_RAW_PART	2
63 #define	VTOC_SANITY	0x600ddeee
64 #define	VTOC_VERSION	1
65 #define	VTOC_VOLUME_LEN	8
66 
67 #define	VTOC8_NPARTS	8
68 
69 struct vtoc8 {
70 	char		ascii[VTOC_ASCII_LEN];
71 	uint32_t	version;
72 	char		volume[VTOC_VOLUME_LEN];
73 	uint16_t	nparts;
74 	struct {
75 		uint16_t	tag;
76 		uint16_t	flag;
77 	} part[VTOC8_NPARTS] __packed;
78 	uint16_t	__alignment;
79 	uint32_t	bootinfo[3];
80 	uint32_t	sanity;
81 	uint32_t	reserved[10];
82 	uint32_t	timestamp[VTOC8_NPARTS];
83 	uint16_t	wskip;
84 	uint16_t	rskip;
85 	char		padding[152];
86 	uint16_t	rpm;
87 	uint16_t	physcyls;
88 	uint16_t	sparesecs;
89 	uint16_t	spare1[2];
90 	uint16_t	interleave;
91 	uint16_t	ncyls;
92 	uint16_t	altcyls;
93 	uint16_t	nheads;
94 	uint16_t	nsecs;
95 	uint16_t	spare2[2];
96 	struct {
97 		uint32_t	cyl;
98 		uint32_t	nblks;
99 	} map[VTOC8_NPARTS];
100 	uint16_t	magic;
101 	uint16_t	cksum;
102 } __packed;
103 
104 #ifdef CTASSERT
105 CTASSERT(sizeof(struct vtoc8) == 512);
106 #endif
107 
108 #define NDKMAP          16              /* # of logical partitions */
109 #define DK_LABEL_LOC    1               /* location of disk label */
110 #define LEN_DKL_ASCII   128             /* length of dkl_asciilabel */
111 #define LEN_DKL_VVOL    8               /* length of v_volume */
112 #define DK_LABEL_SIZE   512             /* size of disk label */
113 #define DK_MAX_BLOCKS   0x7fffffff      /* max # of blocks handled */
114 
115 struct dk_vtoc {
116 	uint32_t	v_bootinfo[3];	/* info needed by mboot (unsupported) */
117 	uint32_t	v_sanity;	/* to verify vtoc sanity */
118 	uint32_t	v_version;	/* layout version */
119 	char	v_volume[LEN_DKL_VVOL];	/* volume name */
120 	uint16_t	v_sectorsz;	/* sector size in bytes */
121 	uint16_t	v_nparts;	/* number of partitions */
122 	uint32_t	v_reserved[10];	/* free space */
123 	struct {
124 		uint16_t	p_tag;	/* ID tag of partition */
125 		uint16_t	p_flag;	/* permission flags */
126 		uint32_t	p_start;/* start sector no of partition */
127 		int32_t		p_size;	/* # of blocks in partition */
128 	} v_part[NDKMAP];		/* partition headers */
129 	uint32_t timestamp[NDKMAP];	/* partition timestamp (unsupported) */
130 	char	v_asciilabel[LEN_DKL_ASCII];	/* for compatibility */
131 };
132 
133 #define	LEN_DKL_PAD	(DK_LABEL_SIZE - \
134 			    ((sizeof (struct dk_vtoc) + \
135 			    (4 * sizeof (uint32_t)) + \
136 			    (12 * sizeof (uint16_t)) + \
137 			    (2 * (sizeof (uint16_t))))))
138 
139 struct dk_label {
140         struct  dk_vtoc dkl_vtoc;       /* vtoc inclusions from AT&T SVr4 */
141         uint32_t        dkl_pcyl;       /* # of physical cylinders */
142         uint32_t        dkl_ncyl;       /* # of data cylinders */
143         uint16_t        dkl_acyl;       /* # of alternate cylinders */
144         uint16_t        dkl_bcyl;       /* cyl offset (for fixed head area) */
145         uint32_t        dkl_nhead;      /* # of heads */
146         uint32_t        dkl_nsect;      /* # of data sectors per track */
147         uint16_t        dkl_intrlv;     /* interleave factor */
148         uint16_t        dkl_skew;       /* skew factor */
149         uint16_t        dkl_apc;        /* alternates per cyl (SCSI only)   */
150         uint16_t        dkl_rpm;        /* revolutions per minute */
151         uint16_t        dkl_write_reinstruct;   /* # sectors to skip, writes */
152         uint16_t        dkl_read_reinstruct;    /* # sectors to skip, reads  */
153         uint16_t        dkl_extra[4];   /* for compatible expansion */
154         char            dkl_pad[LEN_DKL_PAD];   /* unused part of 512 bytes */
155         uint16_t        dkl_magic;      /* identifies this label format */
156         uint16_t        dkl_cksum;      /* xor checksum of sector */
157 };
158 
159 #ifdef CTASSERT
160 CTASSERT(sizeof(struct dk_label) == 512);
161 #endif
162 
163 #endif /* _SYS_VTOC_H_ */
164