All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix a special case when accessing partition on linux
@ 2010-01-31 20:00 Vladimir 'φ-coder/phcoder' Serbinenko
  2010-01-31 20:22 ` Bruce Dubbs
  0 siblings, 1 reply; 2+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2010-01-31 20:00 UTC (permalink / raw)
  To: The development of GRUB 2


[-- Attachment #1.1: Type: text/plain, Size: 393 bytes --]

Because of cache coherency problem grub accesses partitions on linux by
hdaX device and not by hda with correct offset. The problem is that
because of 4K cache blocks disk.c may read sectors before the partition
and hence making hostdisk.c try to read from negative offset. I'm sad
that we need such workarounds for free systems.

-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: hostpart.diff --]
[-- Type: text/x-diff; name="hostpart.diff", Size: 1939 bytes --]

=== modified file 'util/hostdisk.c'
--- util/hostdisk.c	2010-01-25 17:04:22 +0000
+++ util/hostdisk.c	2010-01-31 11:52:27 +0000
@@ -336,7 +336,8 @@
     char dev[PATH_MAX];
 
     strcpy (dev, map[disk->id].device);
-    if (disk->partition && strncmp (map[disk->id].device, "/dev/", 5) == 0)
+    if (disk->partition && sector >= disk->partition->start
+	&& strncmp (map[disk->id].device, "/dev/", 5) == 0)
       is_partition = linux_find_partition (dev, disk->partition->start);
 
     /* Open the partition.  */
@@ -490,6 +491,23 @@
 {
   int fd;
 
+  /* Split pre-partition and partition reads.  */
+  if (disk->partition && sector < disk->partition->start
+      && sector + size > disk->partition->start)
+    {
+      grub_err_t err;
+      err = grub_util_biosdisk_read (disk, sector,
+				     disk->partition->start - sector,
+				     buf);
+      if (err)
+	return err;
+
+      return grub_util_biosdisk_read (disk, disk->partition->start,
+				      size - (disk->partition->start - sector),
+				      buf + ((disk->partition->start - sector)
+					     << GRUB_DISK_SECTOR_BITS));
+    }
+
   fd = open_device (disk, sector, O_RDONLY);
   if (fd < 0)
     return grub_errno;
@@ -527,6 +545,23 @@
 {
   int fd;
 
+  /* Split pre-partition and partition writes.  */
+  if (disk->partition && sector < disk->partition->start
+      && sector + size > disk->partition->start)
+    {
+      grub_err_t err;
+      err = grub_util_biosdisk_write (disk, sector,
+				      disk->partition->start - sector,
+				      buf);
+      if (err)
+	return err;
+
+      return grub_util_biosdisk_write (disk, disk->partition->start,
+				       size - (disk->partition->start - sector),
+				       buf + ((disk->partition->start - sector)
+					      << GRUB_DISK_SECTOR_BITS));
+    }
+
   fd = open_device (disk, sector, O_WRONLY);
   if (fd < 0)
     return grub_errno;


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 293 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix a special case when accessing partition on linux
  2010-01-31 20:00 [PATCH] Fix a special case when accessing partition on linux Vladimir 'φ-coder/phcoder' Serbinenko
@ 2010-01-31 20:22 ` Bruce Dubbs
  0 siblings, 0 replies; 2+ messages in thread
From: Bruce Dubbs @ 2010-01-31 20:22 UTC (permalink / raw)
  To: The development of GNU GRUB

Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> Because of cache coherency problem grub accesses partitions on linux by
> hdaX device and not by hda with correct offset. The problem is that
> because of 4K cache blocks disk.c may read sectors before the partition
> and hence making hostdisk.c try to read from negative offset. I'm sad
> that we need such workarounds for free systems.

I would think it beneficial for long term code maintenance to put
the above comments into the code itself.

// Because of a cache coherency problem grub accesses partitions
// on linux by an hdaX device and not by hda with the correct offset.
// The problem is that because of 4K cache blocks, disk.c may
// read sectors before the partition and hence make
// hostdisk.c try to read from a  negative offset.

   -- Bruce



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-01-31 20:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-31 20:00 [PATCH] Fix a special case when accessing partition on linux Vladimir 'φ-coder/phcoder' Serbinenko
2010-01-31 20:22 ` Bruce Dubbs

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.