2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 1999,2000,2001,2002,2004,2007 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef GRUB_PC_PARTITION_HEADER
20 #define GRUB_PC_PARTITION_HEADER 1
22 #include <grub/symbol.h>
23 #include <grub/types.h>
27 #define GRUB_PC_PARTITION_SIGNATURE 0xaa55
29 /* This is not a flag actually, but used as if it were a flag. */
30 #define GRUB_PC_PARTITION_TYPE_HIDDEN_FLAG 0x10
32 /* DOS partition types. */
33 #define GRUB_PC_PARTITION_TYPE_NONE 0
34 #define GRUB_PC_PARTITION_TYPE_FAT12 1
35 #define GRUB_PC_PARTITION_TYPE_FAT16_LT32M 4
36 #define GRUB_PC_PARTITION_TYPE_EXTENDED 5
37 #define GRUB_PC_PARTITION_TYPE_FAT16_GT32M 6
38 #define GRUB_PC_PARTITION_TYPE_NTFS 7
39 #define GRUB_PC_PARTITION_TYPE_FAT32 0xb
40 #define GRUB_PC_PARTITION_TYPE_FAT32_LBA 0xc
41 #define GRUB_PC_PARTITION_TYPE_FAT16_LBA 0xe
42 #define GRUB_PC_PARTITION_TYPE_WIN95_EXTENDED 0xf
43 #define GRUB_PC_PARTITION_TYPE_EZD 0x55
44 #define GRUB_PC_PARTITION_TYPE_MINIX 0x80
45 #define GRUB_PC_PARTITION_TYPE_LINUX_MINIX 0x81
46 #define GRUB_PC_PARTITION_TYPE_EXT2FS 0x83
47 #define GRUB_PC_PARTITION_TYPE_LINUX_EXTENDED 0x85
48 #define GRUB_PC_PARTITION_TYPE_VSTAFS 0x9e
49 #define GRUB_PC_PARTITION_TYPE_FREEBSD 0xa5
50 #define GRUB_PC_PARTITION_TYPE_OPENBSD 0xa6
51 #define GRUB_PC_PARTITION_TYPE_NETBSD 0xa9
52 #define GRUB_PC_PARTITION_TYPE_HFS 0xaf
53 #define GRUB_PC_PARTITION_TYPE_GPT_DISK 0xee
54 #define GRUB_PC_PARTITION_TYPE_LINUX_RAID 0xfd
56 /* Constants for BSD disk label. */
57 #define GRUB_PC_PARTITION_BSD_LABEL_SECTOR 1
58 #define GRUB_PC_PARTITION_BSD_LABEL_MAGIC 0x82564557
59 #define GRUB_PC_PARTITION_BSD_MAX_ENTRIES 8
61 /* BSD partition types. */
62 #define GRUB_PC_PARTITION_BSD_TYPE_UNUSED 0
63 #define GRUB_PC_PARTITION_BSD_TYPE_SWAP 1
64 #define GRUB_PC_PARTITION_BSD_TYPE_V6 2
65 #define GRUB_PC_PARTITION_BSD_TYPE_V7 3
66 #define GRUB_PC_PARTITION_BSD_TYPE_SYSV 4
67 #define GRUB_PC_PARTITION_BSD_TYPE_V71K 5
68 #define GRUB_PC_PARTITION_BSD_TYPE_V8 6
69 #define GRUB_PC_PARTITION_BSD_TYPE_BSDFFS 7
70 #define GRUB_PC_PARTITION_BSD_TYPE_MSDOS 8
71 #define GRUB_PC_PARTITION_BSD_TYPE_BSDLFS 9
72 #define GRUB_PC_PARTITION_BSD_TYPE_OTHER 10
73 #define GRUB_PC_PARTITION_BSD_TYPE_HPFS 11
74 #define GRUB_PC_PARTITION_BSD_TYPE_ISO9660 12
75 #define GRUB_PC_PARTITION_BSD_TYPE_BOOT 13
77 /* FreeBSD-specific types. */
78 #define GRUB_PC_PARTITION_FREEBSD_TYPE_VINUM 14
79 #define GRUB_PC_PARTITION_FREEBSD_TYPE_RAID 15
80 #define GRUB_PC_PARTITION_FREEBSD_TYPE_JFS2 21
82 /* NetBSD-specific types. */
83 #define GRUB_PC_PARTITION_NETBSD_TYPE_ADOS 14
84 #define GRUB_PC_PARTITION_NETBSD_TYPE_HFS 15
85 #define GRUB_PC_PARTITION_NETBSD_TYPE_FILECORE 16
86 #define GRUB_PC_PARTITION_NETBSD_TYPE_EXT2FS 17
87 #define GRUB_PC_PARTITION_NETBSD_TYPE_NTFS 18
88 #define GRUB_PC_PARTITION_NETBSD_TYPE_RAID 19
89 #define GRUB_PC_PARTITION_NETBSD_TYPE_CCD 20
90 #define GRUB_PC_PARTITION_NETBSD_TYPE_JFS2 21
91 #define GRUB_PC_PARTITION_NETBSD_TYPE_APPLEUFS 22
93 /* OpenBSD-specific types. */
94 #define GRUB_PC_PARTITION_OPENBSD_TYPE_ADOS 14
95 #define GRUB_PC_PARTITION_OPENBSD_TYPE_HFS 15
96 #define GRUB_PC_PARTITION_OPENBSD_TYPE_FILECORE 16
97 #define GRUB_PC_PARTITION_OPENBSD_TYPE_EXT2FS 17
98 #define GRUB_PC_PARTITION_OPENBSD_TYPE_NTFS 18
99 #define GRUB_PC_PARTITION_OPENBSD_TYPE_RAID 19
101 /* The BSD partition entry. */
102 struct grub_msdos_partition_bsd_entry
105 grub_uint32_t offset
;
106 grub_uint32_t fragment_size
;
107 grub_uint8_t fs_type
;
108 grub_uint8_t fs_fragments
;
109 grub_uint16_t fs_cylinders
;
110 } __attribute__ ((packed
));
112 /* The BSD disk label. Only define members useful for GRUB. */
113 struct grub_msdos_partition_disk_label
116 grub_uint8_t padding
[128];
117 grub_uint32_t magic2
;
118 grub_uint16_t checksum
;
119 grub_uint16_t num_partitions
;
120 grub_uint32_t boot_size
;
121 grub_uint32_t superblock_size
;
122 struct grub_msdos_partition_bsd_entry entries
[GRUB_PC_PARTITION_BSD_MAX_ENTRIES
];
123 } __attribute__ ((packed
));
125 /* The partition entry. */
126 struct grub_msdos_partition_entry
128 /* If active, 0x80, otherwise, 0x00. */
131 /* The head of the start. */
132 grub_uint8_t start_head
;
134 /* (S | ((C >> 2) & 0xC0)) where S is the sector of the start and C
135 is the cylinder of the start. Note that S is counted from one. */
136 grub_uint8_t start_sector
;
138 /* (C & 0xFF) where C is the cylinder of the start. */
139 grub_uint8_t start_cylinder
;
141 /* The partition type. */
144 /* The end versions of start_head, start_sector and start_cylinder,
146 grub_uint8_t end_head
;
147 grub_uint8_t end_sector
;
148 grub_uint8_t end_cylinder
;
150 /* The start sector. Note that this is counted from zero. */
153 /* The length in sector units. */
154 grub_uint32_t length
;
155 } __attribute__ ((packed
));
157 /* The structure of MBR. */
158 struct grub_msdos_partition_mbr
160 /* The code area (actually, including BPB). */
161 grub_uint8_t code
[446];
163 /* Four partition entries. */
164 struct grub_msdos_partition_entry entries
[4];
166 /* The signature 0xaa55. */
167 grub_uint16_t signature
;
168 } __attribute__ ((packed
));
171 struct grub_msdos_partition
173 /* The DOS partition number. */
176 /* The BSD partition number (a == 0). */
179 /* The DOS partition type. */
182 /* The BSD partition type. */
185 /* The offset of the extended partition. */
186 unsigned long ext_offset
;
190 grub_msdos_partition_is_empty (int type
)
192 return (type
== GRUB_PC_PARTITION_TYPE_NONE
);
196 grub_msdos_partition_is_extended (int type
)
198 return (type
== GRUB_PC_PARTITION_TYPE_EXTENDED
199 || type
== GRUB_PC_PARTITION_TYPE_WIN95_EXTENDED
200 || type
== GRUB_PC_PARTITION_TYPE_LINUX_EXTENDED
);
204 grub_msdos_partition_is_bsd (int type
)
206 return (type
== GRUB_PC_PARTITION_TYPE_FREEBSD
207 || type
== GRUB_PC_PARTITION_TYPE_OPENBSD
208 || type
== GRUB_PC_PARTITION_TYPE_NETBSD
);
211 #endif /* ! GRUB_PC_PARTITION_HEADER */