From f00478b7196526bfd3370c3d3acf8fdff7e92b78 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 15 Sep 2010 15:30:43 +0200 Subject: [PATCH] * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_is_floppy): New function. * include/grub/emu/hostdisk.h (grub_util_biosdisk_is_floppy): New proto. * util/grub-setup.c (setup): Use grub_util_biosdisk_is_floppy. --- ChangeLog | 7 +++++++ grub-core/kern/emu/hostdisk.c | 26 ++++++++++++++++++++++++++ include/grub/emu/hostdisk.h | 1 + util/grub-setup.c | 4 ++-- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1113b8157..b3f3c0e51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-09-15 Vladimir Serbinenko + + * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_is_floppy): New + function. + * include/grub/emu/hostdisk.h (grub_util_biosdisk_is_floppy): New proto. + * util/grub-setup.c (setup): Use grub_util_biosdisk_is_floppy. + 2010-09-15 Yves Blusseau Add function to get completions from usage. diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 142e93fe2..edf8dc219 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -1575,3 +1575,29 @@ grub_util_biosdisk_get_osdev (grub_disk_t disk) { return map[disk->id].device; } + +int +grub_util_biosdisk_is_floppy (grub_disk_t disk) +{ + struct stat st; + int fd; + + fd = open (map[disk->id].device, O_RDONLY); + /* Shouldn't happen. */ + if (fd == -1) + return 0; + + /* Shouldn't happen either. */ + if (fstat (fd, &st) < 0) + return 0; + +#if defined(__NetBSD__) + if (major(st.st_rdev) == RAW_FLOPPY_MAJOR) + return 1; +#endif + + if (major(st.st_rdev) == FLOPPY_MAJOR) + return 1; + + return 0; +} diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h index 5873aa440..d8cc02e14 100644 --- a/include/grub/emu/hostdisk.h +++ b/include/grub/emu/hostdisk.h @@ -27,5 +27,6 @@ void grub_util_biosdisk_fini (void); char *grub_util_biosdisk_get_grub_dev (const char *os_dev); const char *grub_util_biosdisk_get_osdev (grub_disk_t disk); int grub_util_biosdisk_is_present (const char *name); +int grub_util_biosdisk_is_floppy (grub_disk_t disk); #endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */ diff --git a/util/grub-setup.c b/util/grub-setup.c index 55d740f09..a95f9b9d5 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -339,8 +339,8 @@ setup (const char *dir, /* If DEST_DRIVE is a hard disk, enable the workaround, which is for buggy BIOSes which don't pass boot drive correctly. Instead, they pass 0x00 or 0x01 even when booted from 0x80. */ - if (dest_dev->disk->id & 0x80) - /* Replace the jmp (2 bytes) with double nop's. */ + if (!grub_util_biosdisk_is_floppy (dest_dev->disk)) + /* Replace the jmp (2 bytes) with double nop's. */ *boot_drive_check = 0x9090; } #endif -- 2.39.5