• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_EXT2FS       	0x83
115 #define PC_SLICE_TYPE_LINUX_EXTENDED	0x85
116 #define PC_SLICE_TYPE_VSTAFS		0x9e
117 #define PC_SLICE_TYPE_DELL_UTIL		0xde
118 #define PC_SLICE_TYPE_LINUX_RAID	0xfd
119 
120 
121 /* For convinience.  */
122 /* Check if TYPE is a FAT partition type. Clear the hidden flag before
123    the check, to allow the user to mount a hidden partition in GRUB.  */
124 #define IS_PC_SLICE_TYPE_FAT(type)	\
125   ({ int _type = (type) & ~PC_SLICE_TYPE_HIDDEN_FLAG; \
126      _type == PC_SLICE_TYPE_FAT12 \
127      || _type == PC_SLICE_TYPE_FAT16_LT32M \
128      || _type == PC_SLICE_TYPE_FAT16_GT32M \
129      || _type == PC_SLICE_TYPE_FAT16_LBA \
130      || _type == PC_SLICE_TYPE_FAT32 \
131      || _type == PC_SLICE_TYPE_FAT32_LBA \
132      || _type == PC_SLICE_TYPE_DELL_UTIL; })
133 
134 #define IS_PC_SLICE_TYPE_EXTENDED(type)	\
135   (((type) == PC_SLICE_TYPE_EXTENDED)	\
136    || ((type) == PC_SLICE_TYPE_WIN95_EXTENDED)	\
137    || ((type) == PC_SLICE_TYPE_LINUX_EXTENDED))
138 
139 #define IS_PC_SLICE_TYPE_MINIX(type) \
140   (((type) == PC_SLICE_TYPE_MINIX)	\
141    || ((type) == PC_SLICE_TYPE_LINUX_MINIX))
142 
143 /* these ones are special, as they use their own partitioning scheme
144    to subdivide the PC partitions from there.  */
145 #define PC_SLICE_TYPE_FREEBSD		0xa5
146 #define PC_SLICE_TYPE_OPENBSD		0xa6
147 #define PC_SLICE_TYPE_NETBSD		0xa9
148 
149 /* For convenience.  */
150 #define IS_PC_SLICE_TYPE_BSD_WITH_FS(type,fs)	\
151   ((type) == (PC_SLICE_TYPE_FREEBSD | ((fs) << 8)) \
152    || (type) == (PC_SLICE_TYPE_OPENBSD | ((fs) << 8)) \
153    || (type) == (PC_SLICE_TYPE_NETBSD | (fs) << 8))
154 
155 #define IS_PC_SLICE_TYPE_BSD(type)	IS_PC_SLICE_TYPE_BSD_WITH_FS(type,0)
156 
157 /*
158  *  *BSD-style disklabel & partition definitions.
159  *
160  *  This is a subdivided slice of type 'PC_SLICE_TYPE_BSD', so all of
161  *  these, except where noted, are relative to the slice in question.
162  */
163 
164 #define BSD_LABEL_SECTOR 1
165 #define BSD_LABEL_MAGIC  0x82564557
166 
167 #define BSD_LABEL_MAG_OFFSET 0
168 #define BSD_LABEL_MAG2_OFFSET 132
169 #define BSD_LABEL_NPARTS_OFFSET 138
170 #define BSD_LABEL_NPARTS_MAX 8
171 
172 #define BSD_PART_OFFSET 148
173 
174 
175 /*
176  *  Defines to guarantee structural alignment.
177  */
178 
179 #define BSD_LABEL_CHECK_MAG(l_ptr) \
180   ( *( (unsigned long *) (((int) l_ptr) + BSD_LABEL_MAG_OFFSET) ) \
181    == ( (unsigned long) BSD_LABEL_MAGIC ) )
182 
183 #define BSD_LABEL_MAG(l_ptr) \
184   ( *( (unsigned long *) (((int) l_ptr) + BSD_LABEL_MAG_OFFSET) ) )
185 
186 #define BSD_LABEL_DTYPE(l_ptr) \
187   ( *( (unsigned short *) (((int) l_ptr) + BSD_LABEL_MAG_OFFSET + 4) ) )
188 
189 #define BSD_LABEL_NPARTS(l_ptr) \
190   ( *( (unsigned short *) (((int) l_ptr) + BSD_LABEL_NPARTS_OFFSET) ) )
191 
192 #define BSD_PART_LENGTH(l_ptr, part) \
193   ( *( (unsigned long *) (((int) l_ptr) + BSD_PART_OFFSET \
194 			  + (part << 4)) ) )
195 
196 #define BSD_PART_START(l_ptr, part) \
197   ( *( (unsigned long *) (((int) l_ptr) + BSD_PART_OFFSET + 4 \
198 			  + (part << 4)) ) )
199 
200 #define BSD_PART_FRAG_SIZE(l_ptr, part) \
201   ( *( (unsigned long *) (((int) l_ptr) + BSD_PART_OFFSET + 8 \
202 			  + (part << 4)) ) )
203 
204 #define BSD_PART_TYPE(l_ptr, part) \
205   ( *( (unsigned char *) (((int) l_ptr) + BSD_PART_OFFSET + 12 \
206 			  + (part << 4)) ) )
207 
208 #define BSD_PART_FRAGS_PER_BLOCK(l_ptr, part) \
209   ( *( (unsigned char *) (((int) l_ptr) + BSD_PART_OFFSET + 13 \
210 			  + (part << 4)) ) )
211 
212 #define BSD_PART_EXTRA(l_ptr, part) \
213   ( *( (unsigned short *) (((int) l_ptr) + BSD_PART_OFFSET + 14 \
214 			  + (part << 4)) ) )
215 
216 
217 /* possible values for the "DISKTYPE"... all essentially irrelevant
218    except for DTYPE_SCSI */
219 #define DTYPE_SMD               1	/* SMD, XSMD; VAX hp/up */
220 #define DTYPE_MSCP              2	/* MSCP */
221 #define DTYPE_DEC               3	/* other DEC (rk, rl) */
222 #define DTYPE_SCSI              4	/* SCSI */
223 #define DTYPE_ESDI              5	/* ESDI interface */
224 #define DTYPE_ST506             6	/* ST506 etc. */
225 #define DTYPE_HPIB              7	/* CS/80 on HP-IB */
226 #define DTYPE_HPFL              8	/* HP Fiber-link */
227 #define DTYPE_FLOPPY            10	/* floppy */
228 
229 
230 /* possible values for the *BSD-style partition type */
231 #define	FS_UNUSED	0	/* unused */
232 #define	FS_SWAP		1	/* swap */
233 #define	FS_V6		2	/* Sixth Edition */
234 #define	FS_V7		3	/* Seventh Edition */
235 #define	FS_SYSV		4	/* System V */
236 #define	FS_V71K		5	/* V7 with 1K blocks (4.1, 2.9) */
237 #define	FS_V8		6	/* Eighth Edition, 4K blocks */
238 #define	FS_BSDFFS	7	/* 4.2BSD fast file system */
239 #define	FS_MSDOS	8	/* MSDOS file system */
240 #define	FS_BSDLFS	9	/* 4.4BSD log-structured file system */
241 #define	FS_OTHER	10	/* in use, but unknown/unsupported */
242 #define	FS_HPFS		11	/* OS/2 high-performance file system */
243 #define	FS_ISO9660	12	/* ISO 9660, normally CD-ROM */
244 #define	FS_BOOT		13	/* partition contains bootstrap */
245 #define	FS_ADOS		14	/* AmigaDOS fast file system */
246 #define	FS_HFS		15	/* Macintosh HFS */
247 #define	FS_FILECORE	16	/* Acorn Filecore Filing System */
248 #define	FS_EXT2FS	17	/* Linux Extended 2 file system */
249 
250 
251 #endif /* _PC_SLICE_H */
252