1 /*
2  *  GRUB  --  GRand Unified Bootloader
3  *  Copyright (C) 1999,2000,2001,2002,2004,2007  Free Software Foundation, Inc.
4  *
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.
9  *
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.
14  *
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/>.
17  */
18 
19 #ifndef GRUB_PC_PARTITION_HEADER
20 #define GRUB_PC_PARTITION_HEADER	1
21 
22 #include <grub/symbol.h>
23 #include <grub/types.h>
24 #include <grub/err.h>
25 #include "r_types.h"
26 /* The signature.  */
27 #define GRUB_PC_PARTITION_SIGNATURE		0xaa55
28 
29 /* This is not a flag actually, but used as if it were a flag.  */
30 #define GRUB_PC_PARTITION_TYPE_HIDDEN_FLAG	0x10
31 
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
55 
56 /* The partition entry.  */
57 R_PACKED(
58 struct grub_msdos_partition_entry
59 {
60   /* If active, 0x80, otherwise, 0x00.  */
61   grub_uint8_t flag;
62 
63   /* The head of the start.  */
64   grub_uint8_t start_head;
65 
66   /* (S | ((C >> 2) & 0xC0)) where S is the sector of the start and C
67      is the cylinder of the start. Note that S is counted from one.  */
68   grub_uint8_t start_sector;
69 
70   /* (C & 0xFF) where C is the cylinder of the start.  */
71   grub_uint8_t start_cylinder;
72 
73   /* The partition type.  */
74   grub_uint8_t type;
75 
76   /* The end versions of start_head, start_sector and start_cylinder,
77      respectively.  */
78   grub_uint8_t end_head;
79   grub_uint8_t end_sector;
80   grub_uint8_t end_cylinder;
81 
82   /* The start sector. Note that this is counted from zero.  */
83   grub_uint32_t start;
84 
85   /* The length in sector units.  */
86   grub_uint32_t length;
87 });
88 
89 /* The structure of MBR.  */
90 R_PACKED (
91 struct grub_msdos_partition_mbr
92 {
93   /* The code area (actually, including BPB).  */
94   grub_uint8_t code[446];
95 
96   /* Four partition entries.  */
97   struct grub_msdos_partition_entry entries[4];
98 
99   /* The signature 0xaa55.  */
100   grub_uint16_t signature;
101 });
102 
103 
104 
105 static inline int
grub_msdos_partition_is_empty(int type)106 grub_msdos_partition_is_empty (int type)
107 {
108   return (type == GRUB_PC_PARTITION_TYPE_NONE);
109 }
110 
111 static inline int
grub_msdos_partition_is_extended(int type)112 grub_msdos_partition_is_extended (int type)
113 {
114   return (type == GRUB_PC_PARTITION_TYPE_EXTENDED
115 	  || type == GRUB_PC_PARTITION_TYPE_WIN95_EXTENDED
116 	  || type == GRUB_PC_PARTITION_TYPE_LINUX_EXTENDED);
117 }
118 
119 #endif /* ! GRUB_PC_PARTITION_HEADER */
120