xref: /titanic_52/usr/src/grub/grub-0.97/stage2/pc_slice.h (revision 44bc9120699af80bb18366ca474cb2c618608ca9)
1 /*
2  *  GRUB  --  GRand Unified Bootloader
3  *  Copyright (C) 1999,2000,2001,2003   Free Software Foundation, Inc.
4  *
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.
9  *
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.
14  *
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.
18  */
19 
20 #ifndef _PC_SLICE_H
21 #define _PC_SLICE_H
22 
23 /*
24  *  These define the basic PC MBR sector characteristics
25  */
26 
27 #define PC_MBR_SECTOR  0
28 
29 #define PC_MBR_SIG_OFFSET  510
30 #define PC_MBR_SIGNATURE   0xaa55
31 
32 #define PC_SLICE_OFFSET 446
33 #define PC_SLICE_MAX    4
34 
35 
36 /*
37  *  Defines to guarantee structural alignment.
38  */
39 
40 #define PC_MBR_CHECK_SIG(mbr_ptr) \
41   ( *( (unsigned short *) (((int) mbr_ptr) + PC_MBR_SIG_OFFSET) ) \
42    == PC_MBR_SIGNATURE )
43 
44 #define PC_MBR_SIG(mbr_ptr) \
45   ( *( (unsigned short *) (((int) mbr_ptr) + PC_MBR_SIG_OFFSET) ) )
46 
47 #define PC_SLICE_FLAG(mbr_ptr, part) \
48   ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET \
49 			  + (part << 4)) ) )
50 
51 #define PC_SLICE_HEAD(mbr_ptr, part) \
52   ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 1 \
53 			  + (part << 4)) ) )
54 
55 #define PC_SLICE_SEC(mbr_ptr, part) \
56   ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 2 \
57 			  + (part << 4)) ) )
58 
59 #define PC_SLICE_CYL(mbr_ptr, part) \
60   ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 3 \
61 			  + (part << 4)) ) )
62 
63 #define PC_SLICE_TYPE(mbr_ptr, part) \
64   ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 4 \
65 			  + (part << 4)) ) )
66 
67 #define PC_SLICE_EHEAD(mbr_ptr, part) \
68   ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 5 \
69 			  + (part << 4)) ) )
70 
71 #define PC_SLICE_ESEC(mbr_ptr, part) \
72   ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 6 \
73 			  + (part << 4)) ) )
74 
75 #define PC_SLICE_ECYL(mbr_ptr, part) \
76   ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 7 \
77 			  + (part << 4)) ) )
78 
79 #define PC_SLICE_START(mbr_ptr, part) \
80   ( *( (unsigned long *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 8 \
81 			  + (part << 4)) ) )
82 
83 #define PC_SLICE_LENGTH(mbr_ptr, part) \
84   ( *( (unsigned long *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 12 \
85 			  + (part << 4)) ) )
86 
87 
88 /*
89  *  PC flag types are defined here.
90  */
91 
92 #define PC_SLICE_FLAG_NONE      0
93 #define PC_SLICE_FLAG_BOOTABLE  0x80
94 
95 /*
96  *  Known PC partition types are defined here.
97  */
98 
99 /* This is not a flag actually, but used as if it were a flag.  */
100 #define PC_SLICE_TYPE_HIDDEN_FLAG	0x10
101 
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
123 
124 
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; })
138 
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))
143 
144 #define IS_PC_SLICE_TYPE_MINIX(type) \
145   (((type) == PC_SLICE_TYPE_MINIX)	\
146    || ((type) == PC_SLICE_TYPE_LINUX_MINIX))
147 
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
153 
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))
159 
160 #define IS_PC_SLICE_TYPE_BSD(type)	IS_PC_SLICE_TYPE_BSD_WITH_FS(type,0)
161 
162 #define IS_PC_SLICE_TYPE_SOLARIS(type)	\
163   (((type) == PC_SLICE_TYPE_SOLARIS) || ((type) == PC_SLICE_TYPE_SOLARIS2))
164 
165 /*
166  *  *BSD-style disklabel & partition definitions.
167  *
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.
170  */
171 
172 #define BSD_LABEL_SECTOR 1
173 #define BSD_LABEL_MAGIC  0x82564557
174 
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
179 
180 #define BSD_PART_OFFSET 148
181 
182 
183 /*
184  *  Defines to guarantee structural alignment.
185  */
186 
187 #define BSD_LABEL_CHECK_MAG(l_ptr) \
188   ( *( (unsigned long *) (((int) l_ptr) + BSD_LABEL_MAG_OFFSET) ) \
189    == ( (unsigned long) BSD_LABEL_MAGIC ) )
190 
191 #define BSD_LABEL_MAG(l_ptr) \
192   ( *( (unsigned long *) (((int) l_ptr) + BSD_LABEL_MAG_OFFSET) ) )
193 
194 #define BSD_LABEL_DTYPE(l_ptr) \
195   ( *( (unsigned short *) (((int) l_ptr) + BSD_LABEL_MAG_OFFSET + 4) ) )
196 
197 #define BSD_LABEL_NPARTS(l_ptr) \
198   ( *( (unsigned short *) (((int) l_ptr) + BSD_LABEL_NPARTS_OFFSET) ) )
199 
200 #define BSD_PART_LENGTH(l_ptr, part) \
201   ( *( (unsigned long *) (((int) l_ptr) + BSD_PART_OFFSET \
202 			  + (part << 4)) ) )
203 
204 #define BSD_PART_START(l_ptr, part) \
205   ( *( (unsigned long *) (((int) l_ptr) + BSD_PART_OFFSET + 4 \
206 			  + (part << 4)) ) )
207 
208 #define BSD_PART_FRAG_SIZE(l_ptr, part) \
209   ( *( (unsigned long *) (((int) l_ptr) + BSD_PART_OFFSET + 8 \
210 			  + (part << 4)) ) )
211 
212 #define BSD_PART_TYPE(l_ptr, part) \
213   ( *( (unsigned char *) (((int) l_ptr) + BSD_PART_OFFSET + 12 \
214 			  + (part << 4)) ) )
215 
216 #define BSD_PART_FRAGS_PER_BLOCK(l_ptr, part) \
217   ( *( (unsigned char *) (((int) l_ptr) + BSD_PART_OFFSET + 13 \
218 			  + (part << 4)) ) )
219 
220 #define BSD_PART_EXTRA(l_ptr, part) \
221   ( *( (unsigned short *) (((int) l_ptr) + BSD_PART_OFFSET + 14 \
222 			  + (part << 4)) ) )
223 
224 
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 */
236 
237 
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 */
257 
258 
259 /*
260  *  Solaris LABEL definitions. All definitions are relative to the
261  *  current PC_SLICE.
262  */
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
268 
269 #define SOL_PART_OFFSET 0x48
270 
271 #define SOL_LABEL_CHECK_MAG(l_ptr) \
272   (*((unsigned short *) (((int) l_ptr) + SOL_LABEL_MAGIC_OFFSET)) \
273    == ((unsigned short) SOL_LABEL_MAGIC ))
274 
275 #define SOL_PART_START(l_ptr, p) \
276   (*((unsigned long *) (((int) l_ptr) + SOL_PART_OFFSET + (p) * 0xc + 4)))
277 
278 #define SOL_PART_LENGTH(l_ptr, p) \
279   (*((unsigned long *) (((int) l_ptr) + SOL_PART_OFFSET + (p) * 0xc + 8)))
280 
281 #define SOL_PART_EXISTS(l_ptr, p) (SOL_PART_LENGTH(l_ptr, p) != 0)
282 
283 
284 #endif /* _PC_SLICE_H */
285