summaryrefslogtreecommitdiffstats
path: root/contrib/syslinux-4.02/com32/gpllib/disk/bootloaders.c
blob: e0340112f1d20231cb811c90b6ef8f9d8894c45e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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(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))
	    strlcpy(buffer, "SYSLINUX", buffer_size - 1);
	else if (!strncmp(boot_sector + 3, "EXTLINUX", 8))
	    strlcpy(buffer, "EXTLINUX", buffer_size - 1);
	else if (!strncmp(boot_sector + 3, "MSWIN4.1", 8))
	    strlcpy(buffer, "MSWIN4.1", buffer_size - 1);
	else
	    return -1;
	/* Add more... */

	buffer[buffer_size - 1] = '\0';
	return 0;
    }
}