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;
33 strncpy(buffer
, "No bootloader", buffer_size
- 1);
36 strncpy(buffer
, "ThinkPad", buffer_size
- 1);
39 strncpy(buffer
, "Acer 3", buffer_size
- 1);
42 strncpy(buffer
, "Windows", buffer_size
- 1);
45 strncpy(buffer
, "HP/Gateway", buffer_size
- 1);
48 strncpy(buffer
, "PloP", buffer_size
- 1);
51 strncpy(buffer
, "XOSL", buffer_size
- 1);
54 strncpy(buffer
, "Truecrypt Boot Loader", buffer_size
- 1);
57 strncpy(buffer
, "Solaris", buffer_size
- 1);
60 strncpy(buffer
, "Grub", buffer_size
- 1);
63 strncpy(buffer
, "Grub2 (v1.96)", buffer_size
- 1);
66 strncpy(buffer
, "Grub2 (v1.97)", buffer_size
- 1);
69 /* We need more than 2 bytes */
70 if (((label
>> 8) & 0xff) == 0x00)
71 strncpy(buffer
, "fbinst", buffer_size
- 1);
72 else if (((label
>> 8) & 0xff) == 0x80)
73 strncpy(buffer
, "Grub4Dos", buffer_size
- 1);
75 strncpy(buffer
, "Unknown mbr", buffer_size
- 1);
78 /* We need more than 2 bytes */
79 if (((label
>> 8) & 0xff) == 0xc9)
80 strncpy(buffer
, "Master Boot LoaDeR", buffer_size
- 1);
81 else if (((label
>> 8) & 0xff) == 0xc0)
82 strncpy(buffer
, "Syslinux", buffer_size
- 1);
84 strncpy(buffer
, "Unknown mbr", buffer_size
- 1);
87 strncpy(buffer
, "Lilo", buffer_size
- 1);
90 strncpy(buffer
, "Testdisk", buffer_size
- 1);
93 strncpy(buffer
, "GAG", buffer_size
- 1);
96 strncpy(buffer
, "BootIT NG", buffer_size
- 1);
99 strncpy(buffer
, "Unknown mbr", buffer_size
- 1);
103 buffer
[buffer_size
- 1] = '\0';
107 * get_mbr_id - return the first four bytes of the MBR
108 * @d: driveinfo struct describing the drive
110 uint32_t get_mbr_id(const struct driveinfo
*d
)
112 char mbr
[SECTOR
* sizeof(char)];
114 if (read_mbr(d
->disk
, &mbr
) == -1)
118 /* Reverse the opcodes */
119 mbr_id
= (*(uint8_t *) (mbr
+ 3));
120 mbr_id
+= (*(uint8_t *) (mbr
+ 2) << 8);
121 mbr_id
+= (*(uint8_t *) (mbr
+ 1) << 16);
122 mbr_id
+= (*(uint8_t *) mbr
) << 24;