xref: /dragonfly/sys/sys/diskmbr.h (revision 34328c98)
1 /*
2  * Copyright (c) 1987, 1988, 1993
3  *	The Regents of the University of California.  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  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  *	@(#)disklabel.h	8.2 (Berkeley) 7/10/94
30  */
31 
32 #ifndef _SYS_DISKMBR_H_
33 #define	_SYS_DISKMBR_H_
34 
35 #include <sys/types.h>
36 
37 #define	DOSBBSECTOR	0	/* DOS boot block relative sector number */
38 #define	DOSPARTOFF	446
39 #define	DOSPARTSIZE	16
40 #define	NDOSPART	4
41 #define	NEXTDOSPART	32
42 #define	DOSMAGICOFF	510
43 #define	DOSMAGIC	0xAA55
44 
45 /*
46  * NOTE: DragonFly BSD had been using 0xA5 forever but after many years
47  *	 we're finally shifting to our own as A5 causes conflicts in grub.
48  */
49 #define	DOSPTYP_DFLYBSD	0x6c	/* DragonFly BSD partition type */
50 #define	DOSPTYP_386BSD	0xa5	/* 386BSD partition type */
51 #define	DOSPTYP_OPENBSD	0xa6	/* OpenBSD partition type */
52 #define	DOSPTYP_NETBSD	0xa9	/* NetBSD partition type */
53 #define	DOSPTYP_LINSWP	0x82	/* Linux swap partition */
54 #define	DOSPTYP_LINUX	0x83	/* Linux partition */
55 #define	DOSPTYP_PMBR	0xee	/* GPT Protective MBR */
56 #define	DOSPTYP_EFI	0xef	/* EFI system partition */
57 #define	DOSPTYP_EXT	0x05	/* DOS extended partition */
58 #define	DOSPTYP_EXTLBA	0x0f	/* DOS extended partition */
59 
60 #ifndef _STANDALONE
61 static const struct dos_ptype
62 {
63 	unsigned char type;
64 	const char *name;
65 } dos_ptypes[] = {
66 	{ 0x00, "unused" },
67 	{ 0x01, "Primary DOS with 12 bit FAT" },
68 	{ 0x02, "XENIX / filesystem" },
69 	{ 0x03, "XENIX /usr filesystem" },
70 	{ 0x04, "Primary DOS with 16 bit FAT (<= 32MB)" },
71 	{ DOSPTYP_EXT, "Extended DOS" },
72 	{ 0x06, "Primary 'big' DOS (> 32MB)" },
73 	{ 0x07, "OS/2 HPFS, NTFS, QNX-2 (16 bit) or Advanced UNIX" },
74 	{ 0x08, "AIX filesystem" },
75 	{ 0x09, "AIX boot partition or Coherent" },
76 	{ 0x0A, "OS/2 Boot Manager or OPUS" },
77 	{ 0x0B, "DOS or Windows 95 with 32 bit FAT" },
78 	{ 0x0C, "DOS or Windows 95 with 32 bit FAT, LBA" },
79 	{ 0x0E, "Primary 'big' DOS (> 32MB, LBA)" },
80 	{ DOSPTYP_EXTLBA, "Extended DOS, LBA" },
81 	{ 0x10, "OPUS" },
82 	{ 0x11, "OS/2 BM: hidden DOS with 12-bit FAT" },
83 	{ 0x12, "Compaq diagnostics" },
84 	{ 0x14, "OS/2 BM: hidden DOS with 16-bit FAT (< 32MB)" },
85 	{ 0x16, "OS/2 BM: hidden DOS with 16-bit FAT (>= 32MB)" },
86 	{ 0x17, "OS/2 BM: hidden IFS (e.g. HPFS)" },
87 	{ 0x18, "AST Windows swapfile" },
88 	{ 0x24, "NEC DOS" },
89 	{ 0x39, "plan9" },
90 	{ 0x3C, "PartitionMagic recovery" },
91 	{ 0x40, "VENIX 286" },
92 	{ 0x41, "Linux/MINIX (sharing disk with DRDOS)" },
93 	{ 0x42, "SFS or Linux swap (sharing disk with DRDOS)" },
94 	{ 0x43, "Linux native (sharing disk with DRDOS)" },
95 	{ 0x4D, "QNX 4.2 Primary" },
96 	{ 0x4E, "QNX 4.2 Secondary" },
97 	{ 0x4F, "QNX 4.2 Tertiary" },
98 	{ 0x50, "DM" },
99 	{ 0x51, "DM" },
100 	{ 0x52, "CP/M or Microport SysV/AT" },
101 	{ 0x53, "DM6 Aux3" },
102 	{ 0x54, "DM6" },
103 	{ 0x55, "EZ-Drive (disk manager)" },
104 	{ 0x56, "GB" },
105 	{ 0x5C, "Priam Edisk (disk manager)" }, /* according to S. Widlake */
106 	{ 0x61, "Speed" },
107 	{ 0x63, "ISC UNIX, other System V/386, GNU HURD or Mach" },
108 	{ 0x64, "Novell Netware 2.xx" },
109 	{ 0x65, "Novell Netware 3.xx" },
110 	{ DOSPTYP_DFLYBSD, "DragonFly BSD" },
111 	{ 0x70, "DiskSecure Multi-Boot" },
112 	{ 0x75, "PCIX" },
113 	{ 0x77, "QNX4.x" },
114 	{ 0x78, "QNX4.x 2nd part" },
115 	{ 0x79, "QNX4.x 3rd part" },
116 	{ 0x80, "Minix 1.1 ... 1.4a" },
117 	{ 0x81, "Minix 1.4b ... 1.5.10" },
118 	{ DOSPTYP_LINSWP, "Linux swap or Solaris x86" },
119 	{ DOSPTYP_LINUX, "Linux filesystem" },
120 	{ 0x84, "OS/2 hidden C: drive" },
121 	{ 0x85, "Linux extended" },
122 	{ 0x86, "NTFS volume set??" },
123 	{ 0x87, "NTFS volume set??" },
124 	{ 0x93, "Amoeba filesystem" },
125 	{ 0x94, "Amoeba bad block table" },
126 	{ 0x9F, "BSD/OS" },
127 	{ 0xA0, "Suspend to Disk" },
128 	{ DOSPTYP_386BSD, "DragonFly/FreeBSD/NetBSD/386BSD" },
129 	{ DOSPTYP_OPENBSD, "OpenBSD" },
130 	{ 0xA7, "NEXTSTEP" },
131 	{ DOSPTYP_NETBSD, "NetBSD" },
132 	{ 0xAC, "IBM JFS" },
133 	{ 0xB7, "BSDI BSD/386 filesystem" },
134 	{ 0xB8, "BSDI BSD/386 swap" },
135 	{ 0xBE, "Solaris x86 boot" },
136 	{ 0xC1, "DRDOS/sec with 12-bit FAT" },
137 	{ 0xC4, "DRDOS/sec with 16-bit FAT (< 32MB)" },
138 	{ 0xC6, "DRDOS/sec with 16-bit FAT (>= 32MB)" },
139 	{ 0xC7, "Syrinx" },
140 	{ 0xDB, "Concurrent CPM or C.DOS or CTOS" },
141 	{ 0xE1, "Speed" },
142 	{ 0xE3, "Speed" },
143 	{ 0xE4, "Speed" },
144 	{ 0xEB, "BeOS file system" },
145 	{ DOSPTYP_PMBR, "EFI GPT" },
146 	{ DOSPTYP_EFI, "EFI System Partition" },
147 	{ 0xF1, "Speed" },
148 	{ 0xF2, "DOS 3.3+ Secondary" },
149 	{ 0xF4, "Speed" },
150 	{ 0xFE, "SpeedStor >1024 cyl. or LANstep" },
151 	{ 0xFF, "BBT (Bad Blocks Table)" }
152 };
153 #endif /* !_STANDALONE */
154 
155 /*
156  * Note that sector numbers in a legacy MBR DOS partition start at 1 instead
157  * of 0, so the first sector of the disk would be cyl 0, head 0, sector 1
158  * and translate to block 0 in the actual disk I/O.
159  */
160 struct dos_partition {
161 	unsigned char	dp_flag;	/* bootstrap flags */
162 	unsigned char	dp_shd;		/* starting head */
163 	unsigned char	dp_ssect;	/* starting sector */
164 	unsigned char	dp_scyl;	/* starting cylinder */
165 	unsigned char	dp_typ;		/* partition type */
166 	unsigned char	dp_ehd;		/* end head */
167 	unsigned char	dp_esect;	/* end sector */
168 	unsigned char	dp_ecyl;	/* end cylinder */
169 	uint32_t	dp_start;	/* absolute starting sector number */
170 	uint32_t	dp_size;	/* partition size in sectors */
171 };
172 
173 #ifndef CTASSERT
174 #define CTASSERT(x)		_CTASSERT(x, __LINE__)
175 #define _CTASSERT(x, y)		__CTASSERT(x, y)
176 #define __CTASSERT(x, y)	typedef char __assert_ ## y [(x) ? 1 : -1]
177 #endif
178 
179 CTASSERT(sizeof (struct dos_partition) == DOSPARTSIZE);
180 
181 #define	DPSECT(s) ((s) & 0x3f)		/* isolate relevant bits of sector */
182 #define	DPCYL(c, s) ((c) + (((s) & 0xc0)<<2)) /* and those that are cylinder */
183 
184 #endif /* !_SYS_DISKMBR_H_ */
185