Adding upstream version 3.86+dfsg.
[syslinux-debian/hramrach.git] / com32 / gpllib / disk / mbrs.c
blobb468f791c3e937ed778bb8dde91c81a65fda33fa
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>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <stdio.h>
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 **/
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;
28 switch (s_label) {
29 case 0x0000:
30 case 0xfa33:
31 case 0xfab8:
32 case 0xfabe:
33 strncpy(buffer, "No bootloader", buffer_size - 1);
34 break;
35 case 0x0ebe:
36 strncpy(buffer, "ThinkPad", buffer_size - 1);
37 break;
38 case 0x31c0:
39 strncpy(buffer, "Acer 3", buffer_size - 1);
40 break;
41 case 0x33c0:
42 strncpy(buffer, "Windows", buffer_size - 1);
43 break;
44 case 0x33ff:
45 strncpy(buffer, "HP/Gateway", buffer_size - 1);
46 break;
47 case 0xb800:
48 strncpy(buffer, "PloP", buffer_size - 1);
49 break;
50 case 0xea05:
51 strncpy(buffer, "XOSL", buffer_size - 1);
52 break;
53 case 0xea1e:
54 strncpy(buffer, "Truecrypt Boot Loader", buffer_size - 1);
55 break;
56 case 0xeb04:
57 strncpy(buffer, "Solaris", buffer_size - 1);
58 break;
59 case 0xeb48:
60 strncpy(buffer, "Grub", buffer_size - 1);
61 break;
62 case 0xeb4c:
63 strncpy(buffer, "Grub2 (v1.96)", buffer_size - 1);
64 break;
65 case 0xeb63:
66 strncpy(buffer, "Grub2 (v1.97)", buffer_size - 1);
67 break;
68 case 0xeb5e:
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);
74 else
75 strncpy(buffer, "Unknown mbr", buffer_size - 1);
76 break;
77 case 0xfa31:
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);
83 else
84 strncpy(buffer, "Unknown mbr", buffer_size - 1);
85 break;
86 case 0xfaeb:
87 strncpy(buffer, "Lilo", buffer_size - 1);
88 break;
89 case 0xfc31:
90 strncpy(buffer, "Testdisk", buffer_size - 1);
91 break;
92 case 0xfc33:
93 strncpy(buffer, "GAG", buffer_size - 1);
94 break;
95 case 0xfceb:
96 strncpy(buffer, "BootIT NG", buffer_size - 1);
97 break;
98 default:
99 strncpy(buffer, "Unknown mbr", buffer_size - 1);
100 break;
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)
115 return -1;
116 else {
117 uint32_t mbr_id;
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;
123 return mbr_id;