aboutsummaryrefslogtreecommitdiffstats
path: root/com32/gpllib
diff options
context:
space:
mode:
authorPierre-Alexandre Meyer <pierre@mouraf.org>2009-09-07 16:12:59 -0700
committerPierre-Alexandre Meyer <pierre@mouraf.org>2009-09-07 16:22:36 -0700
commite9069caefc1460ec7f4d058796005474c125fc61 (patch)
tree25cd847439fb004798251a63fa8886073134009f /com32/gpllib
parentc93e27af183de1cdf591706448d42887d0fbc0eb (diff)
parent03b2384b6e9f54d9697e87d2a19c321e6fd96ed5 (diff)
downloadsyslinux-e9069caefc1460ec7f4d058796005474c125fc61.tar.gz
syslinux-e9069caefc1460ec7f4d058796005474c125fc61.tar.xz
syslinux-e9069caefc1460ec7f4d058796005474c125fc61.zip
Merge branch 'bootloader-detection' into hdt-next
Conflicts: com32/hdt/hdt-cli-disk.c com32/hdt/hdt-common.h com32/hdt/hdt-menu-disk.c Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Diffstat (limited to 'com32/gpllib')
-rw-r--r--com32/gpllib/disk/bootloaders.c46
-rw-r--r--com32/gpllib/disk/mbrs.c82
2 files changed, 128 insertions, 0 deletions
diff --git a/com32/gpllib/disk/bootloaders.c b/com32/gpllib/disk/bootloaders.c
new file mode 100644
index 00000000..4b3962ae
--- /dev/null
+++ b/com32/gpllib/disk/bootloaders.c
@@ -0,0 +1,46 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * 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/bootloaders.h>
+#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 in a
+ * bootsector
+ * @d: driveinfo struct describing the drive
+ * @p: partition to scan (usually the active one)
+ * @buffer: pre-allocated buffer
+ * @buffer_size: @buffer size
+ **/
+int get_bootloader_string(const struct driveinfo *d, const struct part_entry *p,
+ char* buffer, const int buffer_size)
+{
+ char boot_sector[SECTOR * sizeof(char)];
+
+ if (read_sectors(d, &boot_sector, p->start_lba, 1) == -1)
+ return -1;
+ else {
+ if (!strncmp(boot_sector + 3, "SYSLINUX", 8))
+ strncpy(buffer, "SYSLINUX", buffer_size - 1);
+ else if (!strncmp(boot_sector + 3, "EXTLINUX", 8))
+ strncpy(buffer, "EXTLINUX", buffer_size - 1);
+ else if (!strncmp(boot_sector + 3, "MSWIN4.1", 8))
+ strncpy(buffer, "MSWIN4.1", buffer_size - 1);
+ else
+ return -1;
+ /* Add more... */
+
+ buffer[buffer_size - 1] = '\0';
+ return 0;
+ }
+}
diff --git a/com32/gpllib/disk/mbrs.c b/com32/gpllib/disk/mbrs.c
new file mode 100644
index 00000000..b5e271b7
--- /dev/null
+++ b/com32/gpllib/disk/mbrs.c
@@ -0,0 +1,82 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * 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>
+#include <stdio.h>
+
+/**
+ * get_mbr_string - return a string describing the boot code
+ * @label: first four bytes of the MBR
+ * @buffer: pre-allocated buffer
+ * @buffer_size: @buffer size
+ **/
+void get_mbr_string(const uint32_t label, char* buffer, const int buffer_size)
+{
+ /* 2 bytes are usually enough to identify the MBR */
+ uint16_t s_label = label >> 16;
+
+ switch (s_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:
+ /* We need more than 2 bytes */
+ if ((label >> 8) & 0xff == 0xc9)
+ strncpy(buffer, "Master Boot LoaDeR", buffer_size - 1);
+ else if ((label >> 8) & 0xff == 0xc0)
+ strncpy(buffer, "Syslinux", buffer_size - 1);
+ else
+ strncpy(buffer, "Unknown mbr", buffer_size - 1); break;
+ 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 mbr", buffer_size - 1); break;
+ }
+
+ buffer[buffer_size - 1] = '\0';
+}
+
+/**
+ * get_mbr_id - return the first four bytes of the MBR
+ * @d: driveinfo struct describing the drive
+ **/
+uint32_t get_mbr_id(const struct driveinfo *d)
+{
+ char mbr[SECTOR * sizeof(char)];
+
+ if (read_mbr(d->disk, &mbr) == -1)
+ return -1;
+ else {
+ uint32_t mbr_id;
+ /* Reverse the opcodes */
+ mbr_id = (*(uint8_t *) (mbr + 3));
+ mbr_id += (*(uint8_t *) (mbr + 2) << 8);
+ mbr_id += (*(uint8_t *) (mbr + 1) << 16);
+ mbr_id += (*(uint8_t *) mbr) << 24;
+ return mbr_id;
+ }
+}