summaryrefslogtreecommitdiff
path: root/com32/gpllib/disk/bootloaders.c
blob: 4b3962aeab5c64c92149de5a290a8af06bde76ff (plain)
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(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;
	}
}