blob: 1279e3cf2290440ffe31a226d256b3dffbbf42a8 [file] [log] [blame]
bigbiff7b4c7a62015-01-01 19:44:14 -05001#ifndef UTIL_LINUX_PT_MBR_H
2#define UTIL_LINUX_PT_MBR_H
3
4struct dos_partition {
5 unsigned char boot_ind; /* 0x80 - active */
6 unsigned char bh, bs, bc; /* begin CHS */
7 unsigned char sys_ind;
8 unsigned char eh, es, ec; /* end CHS */
9 unsigned char start_sect[4];
10 unsigned char nr_sects[4];
11} __attribute__((packed));
12
13#define MBR_PT_OFFSET 0x1be
14
15static inline struct dos_partition *mbr_get_partition(unsigned char *mbr, int i)
16{
17 return (struct dos_partition *)
18 (mbr + MBR_PT_OFFSET + (i * sizeof(struct dos_partition)));
19}
20
21/* assemble badly aligned little endian integer */
22static inline unsigned int __dos_assemble_4le(const unsigned char *p)
23{
24 return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
25}
26
27static inline void __dos_store_4le(unsigned char *p, unsigned int val)
28{
29 p[0] = (val & 0xff);
30 p[1] = ((val >> 8) & 0xff);
31 p[2] = ((val >> 16) & 0xff);
32 p[3] = ((val >> 24) & 0xff);
33}
34
35static inline unsigned int dos_partition_get_start(struct dos_partition *p)
36{
37 return __dos_assemble_4le(&(p->start_sect[0]));
38}
39
40static inline void dos_partition_set_start(struct dos_partition *p, unsigned int n)
41{
42 __dos_store_4le(p->start_sect, n);
43}
44
45static inline unsigned int dos_partition_get_size(struct dos_partition *p)
46{
47 return __dos_assemble_4le(&(p->nr_sects[0]));
48}
49
50static inline void dos_partition_set_size(struct dos_partition *p, unsigned int n)
51{
52 __dos_store_4le(p->nr_sects, n);
53}
54
55static inline int mbr_is_valid_magic(const unsigned char *mbr)
56{
57 return mbr[510] == 0x55 && mbr[511] == 0xaa ? 1 : 0;
58}
59
60static inline void mbr_set_magic(unsigned char *b)
61{
62 b[510] = 0x55;
63 b[511] = 0xaa;
64}
65
66static inline unsigned int mbr_get_id(const unsigned char *mbr)
67{
68 return __dos_assemble_4le(&mbr[440]);
69}
70
71static inline void mbr_set_id(unsigned char *b, unsigned int id)
72{
73 __dos_store_4le(&b[440], id);
74}
75
76enum {
77 MBR_EMPTY_PARTITION = 0x00,
78 MBR_FAT12_PARTITION = 0x01,
79 MBR_XENIX_ROOT_PARTITION = 0x02,
80 MBR_XENIX_USR_PARTITION = 0x03,
81 MBR_FAT16_LESS32M_PARTITION = 0x04,
82 MBR_DOS_EXTENDED_PARTITION = 0x05,
83 MBR_FAT16_PARTITION = 0x06, /* DOS 16-bit >=32M */
84 MBR_HPFS_NTFS_PARTITION = 0x07, /* OS/2 IFS, eg, HPFS or NTFS or QNX */
85 MBR_AIX_PARTITION = 0x08, /* AIX boot (AIX -- PS/2 port) or SplitDrive */
86 MBR_AIX_BOOTABLE_PARTITION = 0x09, /* AIX data or Coherent */
87 MBR_OS2_BOOTMNGR_PARTITION = 0x0a, /* OS/2 Boot Manager */
88 MBR_W95_FAT32_PARTITION = 0x0b,
89 MBR_W95_FAT32_LBA_PARTITION = 0x0c, /* LBA really is `Extended Int 13h' */
90 MBR_W95_FAT16_LBA_PARTITION = 0x0e,
91 MBR_W95_EXTENDED_PARTITION = 0x0f,
92 MBR_OPUS_PARTITION = 0x10,
93 MBR_HIDDEN_FAT12_PARTITION = 0x11,
94 MBR_COMPAQ_DIAGNOSTICS_PARTITION = 0x12,
95 MBR_HIDDEN_FAT16_L32M_PARTITION = 0x14,
96 MBR_HIDDEN_FAT16_PARTITION = 0x16,
97 MBR_HIDDEN_HPFS_NTFS_PARTITION = 0x17,
98 MBR_AST_SMARTSLEEP_PARTITION = 0x18,
99 MBR_HIDDEN_W95_FAT32_PARTITION = 0x1b,
100 MBR_HIDDEN_W95_FAT32LBA_PARTITION = 0x1c,
101 MBR_HIDDEN_W95_FAT16LBA_PARTITION = 0x1e,
102 MBR_NEC_DOS_PARTITION = 0x24,
103 MBR_PLAN9_PARTITION = 0x39,
104 MBR_PARTITIONMAGIC_PARTITION = 0x3c,
105 MBR_VENIX80286_PARTITION = 0x40,
106 MBR_PPC_PREP_BOOT_PARTITION = 0x41,
107 MBR_SFS_PARTITION = 0x42,
108 MBR_QNX_4X_PARTITION = 0x4d,
109 MBR_QNX_4X_2ND_PARTITION = 0x4e,
110 MBR_QNX_4X_3RD_PARTITION = 0x4f,
111 MBR_DM_PARTITION = 0x50,
112 MBR_DM6_AUX1_PARTITION = 0x51, /* (or Novell) */
113 MBR_CPM_PARTITION = 0x52, /* CP/M or Microport SysV/AT */
114 MBR_DM6_AUX3_PARTITION = 0x53,
115 MBR_DM6_PARTITION = 0x54,
116 MBR_EZ_DRIVE_PARTITION = 0x55,
117 MBR_GOLDEN_BOW_PARTITION = 0x56,
118 MBR_PRIAM_EDISK_PARTITION = 0x5c,
119 MBR_SPEEDSTOR_PARTITION = 0x61,
120 MBR_GNU_HURD_PARTITION = 0x63, /* GNU HURD or Mach or Sys V/386 (such as ISC UNIX) */
121 MBR_UNIXWARE_PARTITION = MBR_GNU_HURD_PARTITION,
122 MBR_NETWARE_286_PARTITION = 0x64,
123 MBR_NETWARE_386_PARTITION = 0x65,
124 MBR_DISKSECURE_MULTIBOOT_PARTITION = 0x70,
125 MBR_PC_IX_PARTITION = 0x75,
126 MBR_OLD_MINIX_PARTITION = 0x80, /* Minix 1.4a and earlier */
127 MBR_MINIX_PARTITION = 0x81, /* Minix 1.4b and later */
128 MBR_LINUX_SWAP_PARTITION = 0x82,
129 MBR_SOLARIS_X86_PARTITION = MBR_LINUX_SWAP_PARTITION,
130 MBR_LINUX_DATA_PARTITION = 0x83,
131 MBR_OS2_HIDDEN_DRIVE_PARTITION = 0x84,
132 MBR_LINUX_EXTENDED_PARTITION = 0x85,
133 MBR_NTFS_VOL_SET1_PARTITION = 0x86,
134 MBR_NTFS_VOL_SET2_PARTITION = 0x87,
135 MBR_LINUX_PLAINTEXT_PARTITION = 0x88,
136 MBR_LINUX_LVM_PARTITION = 0x8e,
137 MBR_AMOEBA_PARTITION = 0x93,
138 MBR_AMOEBA_BBT_PARTITION = 0x94, /* (bad block table) */
139 MBR_BSD_OS_PARTITION = 0x9f, /* BSDI */
140 MBR_THINKPAD_HIBERNATION_PARTITION = 0xa0,
141 MBR_FREEBSD_PARTITION = 0xa5, /* various BSD flavours */
142 MBR_OPENBSD_PARTITION = 0xa6,
143 MBR_NEXTSTEP_PARTITION = 0xa7,
144 MBR_DARWIN_UFS_PARTITION = 0xa8,
145 MBR_NETBSD_PARTITION = 0xa9,
146 MBR_DARWIN_BOOT_PARTITION = 0xab,
147 MBR_HFS_HFS_PARTITION = 0xaf,
148 MBR_BSDI_FS_PARTITION = 0xb7,
149 MBR_BSDI_SWAP_PARTITION = 0xb8,
150 MBR_BOOTWIZARD_HIDDEN_PARTITION = 0xbb,
151 MBR_SOLARIS_BOOT_PARTITION = 0xbe,
152 MBR_SOLARIS_PARTITION = 0xbf,
153 MBR_DRDOS_FAT12_PARTITION = 0xc1,
154 MBR_DRDOS_FAT16_L32M_PARTITION = 0xc4,
155 MBR_DRDOS_FAT16_PARTITION = 0xc6,
156 MBR_SYRINX_PARTITION = 0xc7,
157 MBR_NONFS_DATA_PARTITION = 0xda,
158 MBR_CPM_CTOS_PARTITION = 0xdb, /* CP/M or Concurrent CP/M or Concurrent DOS or CTOS */
159 MBR_DELL_UTILITY_PARTITION = 0xde, /* Dell PowerEdge Server utilities */
160 MBR_BOOTIT_PARTITION = 0xdf, /* BootIt EMBRM */
161 MBR_DOS_ACCESS_PARTITION = 0xe1, /* DOS access or SpeedStor 12-bit FAT extended partition */
162 MBR_DOS_RO_PARTITION = 0xe3, /* DOS R/O or SpeedStor */
163 MBR_SPEEDSTOR_EXTENDED_PARTITION = 0xe4, /* SpeedStor 16-bit FAT extended partition < 1024 cyl. */
164 MBR_BEOS_FS_PARTITION = 0xeb,
165 MBR_GPT_PARTITION = 0xee, /* Intel EFI GUID Partition Table */
166 MBR_EFI_SYSTEM_PARTITION = 0xef, /* Intel EFI System Partition */
167 MBR_LINUX_PARISC_BOOT_PARTITION = 0xf0, /* Linux/PA-RISC boot loader */
168 MBR_SPEEDSTOR1_PARTITION = 0xf1,
169 MBR_SPEEDSTOR2_PARTITION = 0xf4, /* SpeedStor large partition */
170 MBR_DOS_SECONDARY_PARTITION = 0xf2, /* DOS 3.3+ secondary */
171 MBR_VMWARE_VMFS_PARTITION = 0xfb,
172 MBR_VMWARE_VMKCORE_PARTITION = 0xfc, /* VMware kernel dump partition */
173 MBR_LINUX_RAID_PARTITION = 0xfd, /* New (2.2.x) raid partition with autodetect using persistent superblock */
174 MBR_LANSTEP_PARTITION = 0xfe, /* SpeedStor >1024 cyl. or LANstep */
175 MBR_XENIX_BBT_PARTITION = 0xff, /* Xenix Bad Block Table */
176};
177
178#endif /* UTIL_LINUX_PT_MBR_H */