From d7076627ee03a2945dc6c6a217a24cc943f2abe2 Mon Sep 17 00:00:00 2001 From: Pierre-Alexandre Meyer Date: Wed, 26 Aug 2009 21:21:38 -0700 Subject: [PATCH] gpllib: add bootloader detection MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Given an (active) partition, look for a bootloader ID. Syslinux prints a string (SYSLINUX or EXTLINUX) between bytes 3 and 10. After some random tests, it seems that Windows™98/98SE and Windows™ME put MSWIN4.1 at the same place. Internet seems to confirm it: http://www.geocities.com/thestarman3/asm/mbr/MSWin41BRinHexEd.htm Signed-off-by: Pierre-Alexandre Meyer --- com32/gplinclude/disk/bootloaders.h | 18 +++++++++++++++ com32/gpllib/disk/bootloaders.c | 46 +++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 com32/gplinclude/disk/bootloaders.h create mode 100644 com32/gpllib/disk/bootloaders.c diff --git a/com32/gplinclude/disk/bootloaders.h b/com32/gplinclude/disk/bootloaders.h new file mode 100644 index 0000000..6aec9b3 --- /dev/null +++ b/com32/gplinclude/disk/bootloaders.h @@ -0,0 +1,18 @@ +/* ----------------------------------------------------------------------- * + * + * 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. + * + * ----------------------------------------------------------------------- */ + +#ifndef __BOOTLOADERS_H_ +#define __BOOTLOADERS_H_ + +#include +#include +#include + +int get_bootloader_string(const struct driveinfo *, const struct part_entry *, char*, const int); +#endif /* __BOOTLOADERS_H_ */ diff --git a/com32/gpllib/disk/bootloaders.c b/com32/gpllib/disk/bootloaders.c new file mode 100644 index 0000000..4b3962a --- /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 +#include +#include +#include +#include +#include + +/** + * 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; + } +} -- 2.7.4