On Tue, Jun 30, 2009 at 06:42:11PM +0200, Robert Millan wrote:
> On Tue, Jun 30, 2009 at 04:42:50PM +0100, Colin Watson wrote:
> > The simple fix is to call the BLKFLSBUF ioctl on any cached file
> > descriptor open on the disk device after writing to the partition
> > device. The attached patch (to be installed in
> > debian/patches/cache_coherency.diff, with the obvious additional entry
> > at the end of debian/patches/00list) does this.
> 
> Hi Colin,
> 
> You forgot to attach it.

D'oh. Really attached now.

-- 
Colin Watson                                       [[email protected]]
Description: Flush buffer cache on disk devices after writing to any
 partition devices they contain, otherwise we may read old data back.
Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=362028
Ubuntu: https://bugs.launchpad.net/bugs/185878

Index: b/stage2/disk_io.c
===================================================================
--- a/stage2/disk_io.c
+++ b/stage2/disk_io.c
@@ -31,6 +31,11 @@
 # include <device.h>
 #endif
 
+#if defined(GRUB_UTIL) && defined(__linux__)
+# include <sys/ioctl.h>		/* ioctl */
+# include <linux/fs.h>		/* BLKFLSBUF */
+#endif
+
 /* instrumentation variables */
 void (*disk_read_hook) (int, int, int) = NULL;
 void (*disk_read_func) (int, int, int) = NULL;
@@ -366,6 +371,8 @@
 devwrite (unsigned int sector, int sector_count, char *buf)
 {
 #if defined(GRUB_UTIL) && defined(__linux__)
+  int ret;
+
   if (current_partition != 0xFFFFFF
       && is_disk_device (device_map, current_drive))
     {
@@ -373,8 +380,11 @@
 	 embed a Stage 1.5 into a partition instead of a MBR, use system
 	 calls directly instead of biosdisk, because of the bug in
 	 Linux. *sigh*  */
-      return write_to_partition (device_map, current_drive, current_partition,
-				 sector, sector_count, buf);
+      ret = write_to_partition (device_map, current_drive, current_partition,
+				sector, sector_count, buf);
+      if (ret && disks[current_drive].flags != -1)
+	ioctl (disks[current_drive].flags, BLKFLSBUF, 0);
+      return ret;
     }
   else
 #endif /* GRUB_UTIL && __linux__ */

Reply via email to