aboutsummaryrefslogtreecommitdiffstats
path: root/com32/gpllib
diff options
context:
space:
mode:
authorPierre-Alexandre Meyer <pierre@mouraf.org>2009-08-23 10:20:06 -0700
committerPierre-Alexandre Meyer <pierre@mouraf.org>2009-08-23 10:20:06 -0700
commit9f42921795542e310b54c5679083c8251d469617 (patch)
tree9a2a4ba7e4a0fe13f86ee461550931ae0975fc17 /com32/gpllib
parent80726ee72df67c2c27ee8a58561e08a9cac30e9c (diff)
downloadsyslinux-9f42921795542e310b54c5679083c8251d469617.tar.gz
syslinux-9f42921795542e310b54c5679083c8251d469617.tar.xz
syslinux-9f42921795542e310b54c5679083c8251d469617.zip
gpllib: add bootloader detection
The first two bytes of the hard drive can help identifying the boot code installed in the MBR. Values from the boot_info_script: http://sourceforge.net/projects/bootinfoscript/ Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Diffstat (limited to 'com32/gpllib')
-rw-r--r--com32/gpllib/disk/bootloaders.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/com32/gpllib/disk/bootloaders.c b/com32/gpllib/disk/bootloaders.c
new file mode 100644
index 00000000..5c6082c2
--- /dev/null
+++ b/com32/gpllib/disk/bootloaders.c
@@ -0,0 +1,68 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2009 Pierre-Alexandre Meyer
+ *
+ * This file is part of Syslinux, and is made available under
+ * the terms of the GNU General Public License version 2.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include <disk/common.h>
+#include <disk/geom.h>
+#include <disk/read.h>
+#include <stdlib.h>
+#include <string.h>
+
+/**
+ * get_bootloader_string - return a string describing the boot code
+ * @label: first two bytes of the MBR
+ * @buffer: pre-allocated buffer
+ * @buffer_size: @buffer size
+ **/
+void get_bootloader_string(const int label, char* buffer, const int buffer_size)
+{
+ switch (label) {
+ case 0x0000:
+ case 0xfa33:
+ case 0xfab8:
+ case 0xfabe:
+ strncpy(buffer, "No bootloader", buffer_size - 1); break;
+ case 0x0ebe: strncpy(buffer, "ThinkPad", buffer_size - 1); break;
+ case 0x31c0: strncpy(buffer, "Acer 3", buffer_size - 1); break;
+ case 0x33c0: strncpy(buffer, "Windows", buffer_size - 1); break;
+ case 0x33ff: strncpy(buffer, "HP/Gateway", buffer_size - 1); break;
+ case 0xb800: strncpy(buffer, "Plop", buffer_size - 1); break;
+ case 0xea1e: strncpy(buffer, "Truecrypt Boot Loader", buffer_size - 1); break;
+ case 0xeb04: strncpy(buffer, "Solaris", buffer_size - 1); break;
+ case 0xeb48: strncpy(buffer, "Grub", buffer_size - 1); break;
+ case 0xeb4c: strncpy(buffer, "Grub2", buffer_size - 1); break;
+ case 0xeb5e: strncpy(buffer, "Grub4Dos", buffer_size - 1); break;
+ case 0xfa31: strncpy(buffer, "Syslinux or Master Boot LoaDeR", buffer_size - 1); break;
+ case 0xfaeb: strncpy(buffer, "Lilo", buffer_size - 1); break;
+ case 0xfc31: strncpy(buffer, "Testdisk", buffer_size - 1); break;
+ case 0xfc33: strncpy(buffer, "Gag", buffer_size - 1); break;
+ case 0xfceb: strncpy(buffer, "BootIT NG", buffer_size - 1); break;
+ default: strncpy(buffer, "Unknown bootloader", buffer_size - 1); break;
+ }
+
+ buffer[buffer_size - 1] = '\0';
+}
+
+/**
+ * get_bootloader_id - return the first two bytes of the MBR
+ * @d: driveinfo struct describing the drive
+ **/
+int get_bootloader_id(const struct driveinfo *d)
+{
+ char mbr[SECTOR * sizeof(char)];
+
+ if (read_mbr(d->disk, &mbr) == -1)
+ return -1;
+ else {
+ uint16_t bootloader_id;
+ /* Reverse the opcodes */
+ bootloader_id = *(uint8_t *) (mbr + 1);
+ bootloader_id += (*(uint8_t *) mbr << 8);
+ return bootloader_id;
+ }
+}