Merge branch 'master' of git://github.com/illumos/illumos-gate
[unleashed.git] / usr / src / grub / grub-0.97 / stage2 / pc_slice.h
blob7e7171d5c426c6c956867466c4a7c38d118d4dc6
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 1999,2000,2001,2003 Free Software Foundation, Inc.
5 * This program 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 2 of the License, or
8 * (at your option) any later version.
10 * This program 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 this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef _PC_SLICE_H
21 #define _PC_SLICE_H
24 * These define the basic PC MBR sector characteristics
27 #define PC_MBR_SECTOR 0
29 #define PC_MBR_SIG_OFFSET 510
30 #define PC_MBR_SIGNATURE 0xaa55
32 #define PC_SLICE_OFFSET 446
33 #define PC_SLICE_MAX 4
37 * Defines to guarantee structural alignment.
40 #define PC_MBR_CHECK_SIG(mbr_ptr) \
41 ( *( (unsigned short *) (((int) mbr_ptr) + PC_MBR_SIG_OFFSET) ) \
42 == PC_MBR_SIGNATURE )
44 #define PC_MBR_SIG(mbr_ptr) \
45 ( *( (unsigned short *) (((int) mbr_ptr) + PC_MBR_SIG_OFFSET) ) )
47 #define PC_SLICE_FLAG(mbr_ptr, part) \
48 ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET \
49 + (part << 4)) ) )
51 #define PC_SLICE_HEAD(mbr_ptr, part) \
52 ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 1 \
53 + (part << 4)) ) )
55 #define PC_SLICE_SEC(mbr_ptr, part) \
56 ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 2 \
57 + (part << 4)) ) )
59 #define PC_SLICE_CYL(mbr_ptr, part) \
60 ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 3 \
61 + (part << 4)) ) )
63 #define PC_SLICE_TYPE(mbr_ptr, part) \
64 ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 4 \
65 + (part << 4)) ) )
67 #define PC_SLICE_EHEAD(mbr_ptr, part) \
68 ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 5 \
69 + (part << 4)) ) )
71 #define PC_SLICE_ESEC(mbr_ptr, part) \
72 ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 6 \
73 + (part << 4)) ) )
75 #define PC_SLICE_ECYL(mbr_ptr, part) \
76 ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 7 \
77 + (part << 4)) ) )
79 #define PC_SLICE_START(mbr_ptr, part) \
80 ( *( (unsigned long *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 8 \
81 + (part << 4)) ) )
83 #define PC_SLICE_LENGTH(mbr_ptr, part) \
84 ( *( (unsigned long *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 12 \
85 + (part << 4)) ) )
89 * PC flag types are defined here.
92 #define PC_SLICE_FLAG_NONE 0
93 #define PC_SLICE_FLAG_BOOTABLE 0x80
96 * Known PC partition types are defined here.
99 /* This is not a flag actually, but used as if it were a flag. */
100 #define PC_SLICE_TYPE_HIDDEN_FLAG 0x10
102 #define PC_SLICE_TYPE_NONE 0
103 #define PC_SLICE_TYPE_FAT12 1
104 #define PC_SLICE_TYPE_FAT16_LT32M 4
105 #define PC_SLICE_TYPE_EXTENDED 5
106 #define PC_SLICE_TYPE_FAT16_GT32M 6
107 #define PC_SLICE_TYPE_FAT32 0xb
108 #define PC_SLICE_TYPE_FAT32_LBA 0xc
109 #define PC_SLICE_TYPE_FAT16_LBA 0xe
110 #define PC_SLICE_TYPE_WIN95_EXTENDED 0xf
111 #define PC_SLICE_TYPE_EZD 0x55
112 #define PC_SLICE_TYPE_MINIX 0x80
113 #define PC_SLICE_TYPE_LINUX_MINIX 0x81
114 #define PC_SLICE_TYPE_SOLARIS 0x82 /* also Linux swap! */
115 #define PC_SLICE_TYPE_EXT2FS 0x83
116 #define PC_SLICE_TYPE_LINUX_EXTENDED 0x85
117 #define PC_SLICE_TYPE_VSTAFS 0x9e
118 #define PC_SLICE_TYPE_SOLARIS_BOOT 0xbe /* Solaris boot (fat) */
119 #define PC_SLICE_TYPE_SOLARIS2 0xbf /* new Solaris type */
120 #define PC_SLICE_TYPE_DELL_UTIL 0xde
121 #define PC_SLICE_TYPE_GPT 0xee
122 #define PC_SLICE_TYPE_LINUX_RAID 0xfd
125 /* For convinience. */
126 /* Check if TYPE is a FAT partition type. Clear the hidden flag before
127 the check, to allow the user to mount a hidden partition in GRUB. */
128 #define IS_PC_SLICE_TYPE_FAT(type) \
129 ({ int _type = (type) & ~PC_SLICE_TYPE_HIDDEN_FLAG; \
130 _type == PC_SLICE_TYPE_FAT12 \
131 || _type == PC_SLICE_TYPE_FAT16_LT32M \
132 || _type == PC_SLICE_TYPE_FAT16_GT32M \
133 || _type == PC_SLICE_TYPE_FAT16_LBA \
134 || _type == PC_SLICE_TYPE_FAT32 \
135 || _type == PC_SLICE_TYPE_FAT32_LBA \
136 || type == PC_SLICE_TYPE_SOLARIS_BOOT \
137 || type == PC_SLICE_TYPE_DELL_UTIL; })
139 #define IS_PC_SLICE_TYPE_EXTENDED(type) \
140 (((type) == PC_SLICE_TYPE_EXTENDED) \
141 || ((type) == PC_SLICE_TYPE_WIN95_EXTENDED) \
142 || ((type) == PC_SLICE_TYPE_LINUX_EXTENDED))
144 #define IS_PC_SLICE_TYPE_MINIX(type) \
145 (((type) == PC_SLICE_TYPE_MINIX) \
146 || ((type) == PC_SLICE_TYPE_LINUX_MINIX))
148 /* these ones are special, as they use their own partitioning scheme
149 to subdivide the PC partitions from there. */
150 #define PC_SLICE_TYPE_FREEBSD 0xa5
151 #define PC_SLICE_TYPE_OPENBSD 0xa6
152 #define PC_SLICE_TYPE_NETBSD 0xa9
154 /* For convenience. */
155 #define IS_PC_SLICE_TYPE_BSD_WITH_FS(type,fs) \
156 ((type) == (PC_SLICE_TYPE_FREEBSD | ((fs) << 8)) \
157 || (type) == (PC_SLICE_TYPE_OPENBSD | ((fs) << 8)) \
158 || (type) == (PC_SLICE_TYPE_NETBSD | (fs) << 8))
160 #define IS_PC_SLICE_TYPE_BSD(type) IS_PC_SLICE_TYPE_BSD_WITH_FS(type,0)
162 #define IS_PC_SLICE_TYPE_SOLARIS(type) \
163 (((type) == PC_SLICE_TYPE_SOLARIS) || ((type) == PC_SLICE_TYPE_SOLARIS2))
166 * *BSD-style disklabel & partition definitions.
168 * This is a subdivided slice of type 'PC_SLICE_TYPE_BSD', so all of
169 * these, except where noted, are relative to the slice in question.
172 #define BSD_LABEL_SECTOR 1
173 #define BSD_LABEL_MAGIC 0x82564557
175 #define BSD_LABEL_MAG_OFFSET 0
176 #define BSD_LABEL_MAG2_OFFSET 132
177 #define BSD_LABEL_NPARTS_OFFSET 138
178 #define BSD_LABEL_NPARTS_MAX 8
180 #define BSD_PART_OFFSET 148
184 * Defines to guarantee structural alignment.
187 #define BSD_LABEL_CHECK_MAG(l_ptr) \
188 ( *( (unsigned long *) (((int) l_ptr) + BSD_LABEL_MAG_OFFSET) ) \
189 == ( (unsigned long) BSD_LABEL_MAGIC ) )
191 #define BSD_LABEL_MAG(l_ptr) \
192 ( *( (unsigned long *) (((int) l_ptr) + BSD_LABEL_MAG_OFFSET) ) )
194 #define BSD_LABEL_DTYPE(l_ptr) \
195 ( *( (unsigned short *) (((int) l_ptr) + BSD_LABEL_MAG_OFFSET + 4) ) )
197 #define BSD_LABEL_NPARTS(l_ptr) \
198 ( *( (unsigned short *) (((int) l_ptr) + BSD_LABEL_NPARTS_OFFSET) ) )
200 #define BSD_PART_LENGTH(l_ptr, part) \
201 ( *( (unsigned long *) (((int) l_ptr) + BSD_PART_OFFSET \
202 + (part << 4)) ) )
204 #define BSD_PART_START(l_ptr, part) \
205 ( *( (unsigned long *) (((int) l_ptr) + BSD_PART_OFFSET + 4 \
206 + (part << 4)) ) )
208 #define BSD_PART_FRAG_SIZE(l_ptr, part) \
209 ( *( (unsigned long *) (((int) l_ptr) + BSD_PART_OFFSET + 8 \
210 + (part << 4)) ) )
212 #define BSD_PART_TYPE(l_ptr, part) \
213 ( *( (unsigned char *) (((int) l_ptr) + BSD_PART_OFFSET + 12 \
214 + (part << 4)) ) )
216 #define BSD_PART_FRAGS_PER_BLOCK(l_ptr, part) \
217 ( *( (unsigned char *) (((int) l_ptr) + BSD_PART_OFFSET + 13 \
218 + (part << 4)) ) )
220 #define BSD_PART_EXTRA(l_ptr, part) \
221 ( *( (unsigned short *) (((int) l_ptr) + BSD_PART_OFFSET + 14 \
222 + (part << 4)) ) )
225 /* possible values for the "DISKTYPE"... all essentially irrelevant
226 except for DTYPE_SCSI */
227 #define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */
228 #define DTYPE_MSCP 2 /* MSCP */
229 #define DTYPE_DEC 3 /* other DEC (rk, rl) */
230 #define DTYPE_SCSI 4 /* SCSI */
231 #define DTYPE_ESDI 5 /* ESDI interface */
232 #define DTYPE_ST506 6 /* ST506 etc. */
233 #define DTYPE_HPIB 7 /* CS/80 on HP-IB */
234 #define DTYPE_HPFL 8 /* HP Fiber-link */
235 #define DTYPE_FLOPPY 10 /* floppy */
238 /* possible values for the *BSD-style partition type */
239 #define FS_UNUSED 0 /* unused */
240 #define FS_SWAP 1 /* swap */
241 #define FS_V6 2 /* Sixth Edition */
242 #define FS_V7 3 /* Seventh Edition */
243 #define FS_SYSV 4 /* System V */
244 #define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */
245 #define FS_V8 6 /* Eighth Edition, 4K blocks */
246 #define FS_BSDFFS 7 /* 4.2BSD fast file system */
247 #define FS_MSDOS 8 /* MSDOS file system */
248 #define FS_BSDLFS 9 /* 4.4BSD log-structured file system */
249 #define FS_OTHER 10 /* in use, but unknown/unsupported */
250 #define FS_HPFS 11 /* OS/2 high-performance file system */
251 #define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */
252 #define FS_BOOT 13 /* partition contains bootstrap */
253 #define FS_ADOS 14 /* AmigaDOS fast file system */
254 #define FS_HFS 15 /* Macintosh HFS */
255 #define FS_FILECORE 16 /* Acorn Filecore Filing System */
256 #define FS_EXT2FS 17 /* Linux Extended 2 file system */
260 * Solaris LABEL definitions. All definitions are relative to the
261 * current PC_SLICE.
263 #define SOL_LABEL_LOC 1
264 #define SOL_LABEL_SIZE 512
265 #define SOL_LABEL_MAGIC 0xdabe
266 #define SOL_LABEL_MAGIC_OFFSET 0x1fc
267 #define SOL_LABEL_NPARTS 0x10
269 #define SOL_PART_OFFSET 0x48
271 #define SOL_LABEL_CHECK_MAG(l_ptr) \
272 (*((unsigned short *) (((int) l_ptr) + SOL_LABEL_MAGIC_OFFSET)) \
273 == ((unsigned short) SOL_LABEL_MAGIC ))
275 #define SOL_PART_START(l_ptr, p) \
276 (*((unsigned long *) (((int) l_ptr) + SOL_PART_OFFSET + (p) * 0xc + 4)))
278 #define SOL_PART_LENGTH(l_ptr, p) \
279 (*((unsigned long *) (((int) l_ptr) + SOL_PART_OFFSET + (p) * 0xc + 8)))
281 #define SOL_PART_EXISTS(l_ptr, p) (SOL_PART_LENGTH(l_ptr, p) != 0)
284 #endif /* _PC_SLICE_H */