1 /* ----------------------------------------------------------------------- *
3 * Copyright 2009 Pierre-Alexandre Meyer
5 * This file is part of Syslinux, and is made available under
6 * the terms of the GNU General Public License version 2.
8 * ----------------------------------------------------------------------- */
10 #include <disk/common.h>
11 #include <disk/geom.h>
12 #include <disk/read.h>
18 * get_mbr_string - return a string describing the boot code
19 * @label: first four bytes of the MBR
20 * @buffer: pre-allocated buffer
21 * @buffer_size: @buffer size
23 void get_mbr_string(const uint32_t label
, char *buffer
, const int buffer_size
)
25 /* 2 bytes are usually enough to identify the MBR */
26 uint16_t s_label
= label
>> 16;
31 strlcpy(buffer
, "No bootloader", buffer_size
- 1);
34 strlcpy(buffer
, "ThinkPad", buffer_size
- 1);
37 strlcpy(buffer
, "Acer 3", buffer_size
- 1);
40 /* We need more than 2 bytes */
41 if (((label
>> 8) & 0xff) == 0x8e)
42 strlcpy(buffer
, "Windows", buffer_size
- 1);
43 else if (((label
>> 8) & 0xff) == 0x90)
44 strlcpy(buffer
, "DiskCryptor", buffer_size
- 1);
45 else if (((label
>> 8) & 0xff) == 0xfa)
46 strlcpy(buffer
, "Syslinux", buffer_size
- 1);
48 strlcpy(buffer
, "Unknown mbr", buffer_size
- 1);
51 strlcpy(buffer
, "Syslinux ISOhybrid", buffer_size
- 1);
54 strlcpy(buffer
, "HP/Gateway", buffer_size
- 1);
57 strlcpy(buffer
, "PloP", buffer_size
- 1);
60 strlcpy(buffer
, "XOSL", buffer_size
- 1);
63 strlcpy(buffer
, "Truecrypt Boot Loader", buffer_size
- 1);
66 strlcpy(buffer
, "Solaris", buffer_size
- 1);
69 strlcpy(buffer
, "Paragon", buffer_size
- 1);
72 strlcpy(buffer
, "Grub", buffer_size
- 1);
75 strlcpy(buffer
, "Grub2 (v1.96)", buffer_size
- 1);
78 strlcpy(buffer
, "Grub2 (v1.97)", buffer_size
- 1);
81 /* We need more than 2 bytes */
82 if (((label
>> 8) & 0xff) == 0x00)
83 strlcpy(buffer
, "fbinst", buffer_size
- 1);
84 else if (((label
>> 8) & 0xff) == 0x80)
85 strlcpy(buffer
, "Grub4Dos", buffer_size
- 1);
86 else if (((label
>> 8) & 0xff) == 0x90)
87 strlcpy(buffer
, "WEE", buffer_size
- 1);
89 strlcpy(buffer
, "Unknown mbr", buffer_size
- 1);
92 /* We need more than 2 bytes */
93 if (((label
>> 8) & 0xff) == 0xc0)
94 strlcpy(buffer
, "Syslinux", buffer_size
- 1);
95 else if (((label
>> 8) & 0xff) == 0xc9)
96 strlcpy(buffer
, "Master Boot LoaDeR", buffer_size
- 1);
98 strlcpy(buffer
, "Unknown mbr", buffer_size
- 1);
101 strlcpy(buffer
, "MS-DOS 3.30 through Windows 95 (A)", buffer_size
- 1);
104 strlcpy(buffer
, "FreeDOS (eXtended FDisk)", buffer_size
- 1);
107 strlcpy(buffer
, "Lilo", buffer_size
- 1);
110 strlcpy(buffer
, "Testdisk", buffer_size
- 1);
113 strlcpy(buffer
, "GAG", buffer_size
- 1);
116 strlcpy(buffer
, "BootIT NG", buffer_size
- 1);
119 strlcpy(buffer
, "Unknown mbr", buffer_size
- 1);
123 buffer
[buffer_size
- 1] = '\0';
127 * get_mbr_id - return the first four bytes of the MBR
128 * @d: driveinfo struct describing the drive
130 uint32_t get_mbr_id(const struct driveinfo
*d
)
132 char mbr
[SECTOR
* sizeof(char)];
134 if (read_mbr(d
->disk
, &mbr
) == -1)
138 /* Reverse the opcodes */
139 mbr_id
= (*(uint8_t *) (mbr
+ 3));
140 mbr_id
+= (*(uint8_t *) (mbr
+ 2) << 8);
141 mbr_id
+= (*(uint8_t *) (mbr
+ 1) << 16);
142 mbr_id
+= (*(uint8_t *) mbr
) << 24;