1/* ----------------------------------------------------------------------- * 2 * 3 * Copyright 2009 Pierre-Alexandre Meyer 4 * 5 * This file is part of Syslinux, and is made available under 6 * the terms of the GNU General Public License version 2. 7 * 8 * ----------------------------------------------------------------------- */ 9 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> 16 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 **/ 25int get_bootloader_string(struct driveinfo *d, const struct part_entry *p, 26 char *buffer, const int buffer_size) 27{ 28 char boot_sector[SECTOR * sizeof(char)]; 29 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 strlcpy(buffer, "SYSLINUX", buffer_size - 1); 35 else if (!strncmp(boot_sector + 3, "EXTLINUX", 8)) 36 strlcpy(buffer, "EXTLINUX", buffer_size - 1); 37 else if (!strncmp(boot_sector + 3, "MSWIN4.1", 8)) 38 strlcpy(buffer, "MSWIN4.1", buffer_size - 1); 39 else 40 return -1; 41 /* Add more... */ 42 43 buffer[buffer_size - 1] = '\0'; 44 return 0; 45 } 46} 47