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