Adding upstream version 3.86+dfsg.
[syslinux-debian/hramrach.git] / com32 / gpllib / disk / bootloaders.c
blob188dd64b1ec9dc50364f27c557d670f959fbdd6c
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/bootloaders.h>
11 #include <disk/common.h>
12 #include <disk/geom.h>
13 #include <disk/read.h>
14 #include <stdlib.h>
15 #include <string.h>
17 /**
18 * get_bootloader_string - return a string describing the boot code in a
19 * bootsector
20 * @d: driveinfo struct describing the drive
21 * @p: partition to scan (usually the active one)
22 * @buffer: pre-allocated buffer
23 * @buffer_size: @buffer size
24 **/
25 int get_bootloader_string(struct driveinfo *d, const struct part_entry *p,
26 char *buffer, const int buffer_size)
28 char boot_sector[SECTOR * sizeof(char)];
30 if (read_sectors(d, &boot_sector, p->start_lba, 1) == -1)
31 return -1;
32 else {
33 if (!strncmp(boot_sector + 3, "SYSLINUX", 8))
34 strncpy(buffer, "SYSLINUX", buffer_size - 1);
35 else if (!strncmp(boot_sector + 3, "EXTLINUX", 8))
36 strncpy(buffer, "EXTLINUX", buffer_size - 1);
37 else if (!strncmp(boot_sector + 3, "MSWIN4.1", 8))
38 strncpy(buffer, "MSWIN4.1", buffer_size - 1);
39 else
40 return -1;
41 /* Add more... */
43 buffer[buffer_size - 1] = '\0';
44 return 0;