|
|
7f44b9b |
From: Valdimir Serbinenko <phcoder@gmail.com>
|
|
|
7f44b9b |
Subject: Fix MBR remapping workaround.
|
|
|
7f44b9b |
|
|
|
7f44b9b |
upstream rev 4405
|
|
|
7f44b9b |
|
|
|
7f44b9b |
--- a/grub-core/kern/emu/hostdisk.c 2012-05-27 11:19:09 +0000
|
|
|
7f44b9b |
+++ b/grub-core/kern/emu/hostdisk.c 2012-06-02 11:48:44 +0000
|
|
|
7f44b9b |
@@ -1067,27 +1067,18 @@
|
|
|
7f44b9b |
if (fd < 0)
|
|
|
7f44b9b |
return grub_errno;
|
|
|
7f44b9b |
|
|
|
7f44b9b |
+#ifdef __linux__
|
|
|
7f44b9b |
+ if (sector == 0)
|
|
|
7f44b9b |
+ /* Work around a bug in Linux ez remapping. Linux remaps all
|
|
|
7f44b9b |
+ sectors that are read together with the MBR in one read. It
|
|
|
7f44b9b |
+ should only remap the MBR, so we split the read in two
|
|
|
7f44b9b |
+ parts. -jochen */
|
|
|
7f44b9b |
+ max = 1;
|
|
|
7f44b9b |
+#endif /* __linux__ */
|
|
|
7f44b9b |
+
|
|
|
7f44b9b |
if (max > size)
|
|
|
7f44b9b |
max = size;
|
|
|
7f44b9b |
|
|
|
7f44b9b |
-#ifdef __linux__
|
|
|
7f44b9b |
- if (sector == 0 && max > 1)
|
|
|
7f44b9b |
- {
|
|
|
7f44b9b |
- /* Work around a bug in Linux ez remapping. Linux remaps all
|
|
|
7f44b9b |
- sectors that are read together with the MBR in one read. It
|
|
|
7f44b9b |
- should only remap the MBR, so we split the read in two
|
|
|
7f44b9b |
- parts. -jochen */
|
|
|
7f44b9b |
- if (grub_util_fd_read (fd, buf, (1 << disk->log_sector_size))
|
|
|
7f44b9b |
- != (1 << disk->log_sector_size))
|
|
|
7f44b9b |
- return grub_error (GRUB_ERR_READ_ERROR, N_("cannot read `%s': %s"),
|
|
|
7f44b9b |
- map[disk->id].device, strerror (errno));
|
|
|
7f44b9b |
-
|
|
|
7f44b9b |
- buf += (1 << disk->log_sector_size);
|
|
|
7f44b9b |
- size--;
|
|
|
7f44b9b |
- max--;
|
|
|
7f44b9b |
- }
|
|
|
7f44b9b |
-#endif /* __linux__ */
|
|
|
7f44b9b |
-
|
|
|
7f44b9b |
if (grub_util_fd_read (fd, buf, max << disk->log_sector_size)
|
|
|
7f44b9b |
!= (ssize_t) (max << disk->log_sector_size))
|
|
|
7f44b9b |
return grub_error (GRUB_ERR_READ_ERROR, N_("cannot read `%s': %s"),
|
|
|
7f44b9b |
@@ -1111,28 +1102,18 @@
|
|
|
7f44b9b |
if (fd < 0)
|
|
|
7f44b9b |
return grub_errno;
|
|
|
7f44b9b |
|
|
|
7f44b9b |
+#ifdef __linux__
|
|
|
7f44b9b |
+ if (sector == 0)
|
|
|
7f44b9b |
+ /* Work around a bug in Linux ez remapping. Linux remaps all
|
|
|
7f44b9b |
+ sectors that are write together with the MBR in one write. It
|
|
|
7f44b9b |
+ should only remap the MBR, so we split the write in two
|
|
|
7f44b9b |
+ parts. -jochen */
|
|
|
7f44b9b |
+ max = 1;
|
|
|
7f44b9b |
+#endif /* __linux__ */
|
|
|
7f44b9b |
+
|
|
|
7f44b9b |
if (max > size)
|
|
|
7f44b9b |
max = size;
|
|
|
7f44b9b |
|
|
|
7f44b9b |
-#ifdef __linux__
|
|
|
7f44b9b |
- if (sector == 0 && max > 1)
|
|
|
7f44b9b |
- {
|
|
|
7f44b9b |
- /* Work around a bug in Linux ez remapping. Linux remaps all
|
|
|
7f44b9b |
- sectors that are write together with the MBR in one write. It
|
|
|
7f44b9b |
- should only remap the MBR, so we split the write in two
|
|
|
7f44b9b |
- parts. -jochen */
|
|
|
7f44b9b |
- if (grub_util_fd_write (fd, buf, (1 << disk->log_sector_size))
|
|
|
7f44b9b |
- != (1 << disk->log_sector_size))
|
|
|
7f44b9b |
- return grub_error (GRUB_ERR_WRITE_ERROR,
|
|
|
7f44b9b |
- N_("cannot write to `%s': %s"),
|
|
|
7f44b9b |
- map[disk->id].device, strerror (errno));
|
|
|
7f44b9b |
-
|
|
|
7f44b9b |
- buf += (1 << disk->log_sector_size);
|
|
|
7f44b9b |
- size--;
|
|
|
7f44b9b |
- max--;
|
|
|
7f44b9b |
- }
|
|
|
7f44b9b |
-#endif /* __linux__ */
|
|
|
7f44b9b |
-
|
|
|
7f44b9b |
if (grub_util_fd_write (fd, buf, max << disk->log_sector_size)
|
|
|
7f44b9b |
!= (ssize_t) (max << disk->log_sector_size))
|
|
|
7f44b9b |
return grub_error (GRUB_ERR_WRITE_ERROR, N_("cannot write to `%s': %s"),
|