xref: /freebsd/sys/contrib/openzfs/lib/libspl/include/sys/dktp/fdisk.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 /*	Copyright (c) 1984, 1986, 1987, 1988 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #ifndef _SYS_DKTP_FDISK_H
32 #define	_SYS_DKTP_FDISK_H
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * fdisk.h
40  * This file defines the structure of physical disk sector 0 for use on
41  * AT386 systems.  The format of this sector is constrained by the ROM
42  * BIOS and MS-DOS conventions.
43  * Note that this block does not define the partitions used by the unix
44  * driver.  The unix partitions are obtained from the VTOC.
45  */
46 
47 /*
48  * the MAX values are the maximum usable values for BIOS chs values
49  * The MAX_CYL value of 1022 is the maximum usable value
50  *   the value of 1023 is a fence value,
51  *   indicating no CHS geometry exists for the corresponding LBA value.
52  * HEAD range [ 0 .. MAX_HEAD ], so number of heads is (MAX_HEAD + 1)
53  * SECT range [ 1 .. MAX_SECT ], so number of sectors is (MAX_SECT)
54  */
55 #define	MAX_SECT	(63)
56 #define	MAX_CYL		(1022)
57 #define	MAX_HEAD	(254)
58 
59 /*
60  * BOOTSZ was reduced from 446 to 440 bytes to NOT overwrite the Windows
61  * Vista DISKID. Otherwise Vista won't boot from Solaris GRUB in a dual-boot
62  * setup.
63  * The actual size of mboot code is 425 bytes while that of GRUB stage1 is
64  * 423 bytes. So this changes does not harm them.
65  */
66 #define	BOOTSZ		440	/* size of boot code in master boot block */
67 #define	FD_NUMPART	4	/* number of 'partitions' in fdisk table */
68 #define	MBB_MAGIC	0xAA55	/* magic number for mboot.signature */
69 #define	DEFAULT_INTLV	4	/* default interleave for testing tracks */
70 #define	MINPSIZE	4	/* minimum number of cylinders in a partition */
71 #define	TSTPAT		0xE5	/* test pattern for verifying disk */
72 
73 /*
74  * structure to hold the fdisk partition table
75  */
76 struct ipart {
77 	unsigned char bootid;	/* bootable or not */
78 	unsigned char beghead;	/* beginning head, sector, cylinder */
79 	unsigned char begsect;	/* begcyl is a 10-bit number. High 2 bits */
80 	unsigned char begcyl;	/*	are in begsect. */
81 	unsigned char systid;	/* OS type */
82 	unsigned char endhead;	/* ending head, sector, cylinder */
83 	unsigned char endsect;	/* endcyl is a 10-bit number.  High 2 bits */
84 	unsigned char endcyl;	/*	are in endsect. */
85 	uint32_t relsect;	/* first sector relative to start of disk */
86 	uint32_t numsect;	/* number of sectors in partition */
87 };
88 /*
89  * Values for bootid.
90  */
91 #define	NOTACTIVE	0
92 #define	ACTIVE		128
93 /*
94  * Values for systid.
95  */
96 #define	UNUSED		0	/* Empty Partition */
97 #define	DOSOS12		1	/* DOS partition, 12-bit FAT */
98 #define	PCIXOS		2	/* PC/IX partition */
99 #define	DOSOS16		4	/* DOS partition, 16-bit FAT */
100 #define	EXTDOS		5	/* EXT-DOS partition */
101 #define	DOSHUGE		6	/* Huge DOS partition  > 32MB */
102 #define	FDISK_IFS	7	/* Installable File System (IFS): HPFS & NTFS */
103 #define	FDISK_AIXBOOT	8	/* AIX Boot */
104 #define	FDISK_AIXDATA	9	/* AIX Data */
105 #define	FDISK_OS2BOOT	10	/* OS/2 Boot Manager */
106 #define	FDISK_WINDOWS	11	/* Windows 95 FAT32 (up to 2047GB) */
107 #define	FDISK_EXT_WIN	12	/* Windows 95 FAT32 (extended-INT13) */
108 #define	FDISK_FAT95	14	/* DOS 16-bit FAT, LBA-mapped */
109 #define	FDISK_EXTLBA	15	/* Extended partition, LBA-mapped */
110 #define	DIAGPART	18	/* Diagnostic boot partition (OS independent) */
111 #define	FDISK_LINUX	65	/* Linux */
112 #define	FDISK_LINUXDSWAP	66	/* Linux swap (sharing disk w/ DRDOS) */
113 #define	FDISK_LINUXDNAT	67	/* Linux native (sharing disk with DRDOS) */
114 #define	FDISK_CPM	82	/* CP/M */
115 #define	DOSDATA		86	/* DOS data partition */
116 #define	OTHEROS		98	/* part. type for appl. (DB?) needs */
117 				/* raw partition.  ID was 0 but conflicted */
118 				/* with DOS 3.3 fdisk    */
119 #define	UNIXOS		99	/* UNIX V.x partition */
120 #define	FDISK_NOVELL2	100	/* Novell Netware 286 */
121 #define	FDISK_NOVELL3	101	/* Novell Netware 3.x and later */
122 #define	FDISK_QNX4	119	/* QNX 4.x */
123 #define	FDISK_QNX42	120	/* QNX 4.x 2nd part */
124 #define	FDISK_QNX43	121	/* QNX 4.x 3rd part */
125 #define	SUNIXOS		130	/* Solaris UNIX partition */
126 #define	FDISK_LINUXNAT	131	/* Linux native */
127 #define	FDISK_NTFSVOL1	134	/* NTFS volume set 1 */
128 #define	FDISK_NTFSVOL2	135	/* NTFS volume set 2 */
129 #define	FDISK_BSD	165	/* BSD/386, 386BSD, NetBSD, FreeBSD, OpenBSD */
130 #define	FDISK_NEXTSTEP	167	/* NeXTSTEP */
131 #define	FDISK_BSDIFS	183	/* BSDI file system */
132 #define	FDISK_BSDISWAP	184	/* BSDI swap */
133 #define	X86BOOT		190	/* x86 Solaris boot partition */
134 #define	SUNIXOS2	191	/* Solaris UNIX partition */
135 #define	EFI_PMBR	238	/* EFI PMBR */
136 #define	EFI_FS		239	/* EFI File System (System Partition) */
137 #define	MAXDOS		65535L	/* max size (sectors) for DOS partition */
138 
139 /*
140  * structure to hold master boot block in physical sector 0 of the disk.
141  * Note that partitions stuff can't be directly included in the structure
142  * because of lameo '386 compiler alignment design.
143  * Alignment issues also force us to have 2 16bit entities for a single
144  * 32bit win_volserno. It is not used anywhere anyway.
145  */
146 
147 struct mboot {	/* master boot block */
148 	char	bootinst[BOOTSZ];
149 	uint16_t win_volserno_lo;
150 	uint16_t win_volserno_hi;
151 	uint16_t reserved;
152 	char	parts[FD_NUMPART * sizeof (struct ipart)];
153 	ushort_t signature;
154 };
155 
156 #if defined(__i386) || defined(__amd64)
157 
158 /* Byte offset of the start of the partition table within the sector */
159 #define	FDISK_PART_TABLE_START	446
160 
161 /* Maximum number of valid partitions assumed as 32 */
162 #define	MAX_EXT_PARTS	32
163 
164 #else
165 
166 #define	MAX_EXT_PARTS	0
167 
168 #endif	/* if defined(__i386) || defined(__amd64) */
169 
170 #ifdef	__cplusplus
171 }
172 #endif
173 
174 #endif	/* _SYS_DKTP_FDISK_H */
175