1 /* ----------------------------------------------------------------------- *
2 *
3 * Copyright 2009 Pierre-Alexandre Meyer
4 *
5 * This file is part of Syslinux, and is made available under
6 * the terms of the GNU General Public License version 2.
7 *
8 * ----------------------------------------------------------------------- */
9
10 #include <disk/common.h>
11 #include <disk/geom.h>
12 #include <disk/read.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <stdio.h>
16
17 /**
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
22 **/
get_mbr_string(const uint32_t label,char * buffer,const int buffer_size)23 void get_mbr_string(const uint32_t label, char *buffer, const int buffer_size)
24 {
25 /* 2 bytes are usually enough to identify the MBR */
26 uint16_t s_label = label >> 16;
27
28 switch (s_label) {
29 case 0x0000:
30 case 0xfabe:
31 strlcpy(buffer, "No bootloader", buffer_size - 1);
32 break;
33 case 0x0ebe:
34 strlcpy(buffer, "ThinkPad", buffer_size - 1);
35 break;
36 case 0x31c0:
37 strlcpy(buffer, "Acer 3", buffer_size - 1);
38 break;
39 case 0x33c0:
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);
47 else
48 strlcpy(buffer, "Unknown mbr", buffer_size - 1);
49 break;
50 case 0x33ed:
51 strlcpy(buffer, "Syslinux ISOhybrid", buffer_size - 1);
52 break;
53 case 0x33ff:
54 strlcpy(buffer, "HP/Gateway", buffer_size - 1);
55 break;
56 case 0xb800:
57 strlcpy(buffer, "PloP", buffer_size - 1);
58 break;
59 case 0xea05:
60 strlcpy(buffer, "XOSL", buffer_size - 1);
61 break;
62 case 0xea1e:
63 strlcpy(buffer, "Truecrypt Boot Loader", buffer_size - 1);
64 break;
65 case 0xeb04:
66 strlcpy(buffer, "Solaris", buffer_size - 1);
67 break;
68 case 0xeb31:
69 strlcpy(buffer, "Paragon", buffer_size - 1);
70 break;
71 case 0xeb48:
72 strlcpy(buffer, "Grub", buffer_size - 1);
73 break;
74 case 0xeb4c:
75 strlcpy(buffer, "Grub2 (v1.96)", buffer_size - 1);
76 break;
77 case 0xeb63:
78 strlcpy(buffer, "Grub2 (v1.97)", buffer_size - 1);
79 break;
80 case 0xeb5e:
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);
88 else
89 strlcpy(buffer, "Unknown mbr", buffer_size - 1);
90 break;
91 case 0xfa31:
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);
97 else
98 strlcpy(buffer, "Unknown mbr", buffer_size - 1);
99 break;
100 case 0xfa33:
101 strlcpy(buffer, "MS-DOS 3.30 through Windows 95 (A)", buffer_size - 1);
102 break;
103 case 0xfab8:
104 strlcpy(buffer, "FreeDOS (eXtended FDisk)", buffer_size - 1);
105 break;
106 case 0xfaeb:
107 strlcpy(buffer, "Lilo", buffer_size - 1);
108 break;
109 case 0xfc31:
110 strlcpy(buffer, "Testdisk", buffer_size - 1);
111 break;
112 case 0xfc33:
113 strlcpy(buffer, "GAG", buffer_size - 1);
114 break;
115 case 0xfceb:
116 strlcpy(buffer, "BootIT NG", buffer_size - 1);
117 break;
118 default:
119 strlcpy(buffer, "Unknown mbr", buffer_size - 1);
120 break;
121 }
122
123 buffer[buffer_size - 1] = '\0';
124 }
125
126 /**
127 * get_mbr_id - return the first four bytes of the MBR
128 * @d: driveinfo struct describing the drive
129 **/
get_mbr_id(const struct driveinfo * d)130 uint32_t get_mbr_id(const struct driveinfo *d)
131 {
132 char mbr[SECTOR * sizeof(char)];
133
134 if (read_mbr(d->disk, &mbr) == -1)
135 return -1;
136 else {
137 uint32_t mbr_id;
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;
143 return mbr_id;
144 }
145 }
146