All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Roskin <proski@gnu.org>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCH] biosdisk / open_device() messing up offsets
Date: Sun, 08 Jun 2008 02:52:32 -0400	[thread overview]
Message-ID: <1212907952.31548.2.camel@rd> (raw)
In-Reply-To: <ca0f59980806072344mccc9ac6l7a3dcd0d41a6ba0e@mail.gmail.com>

On Sun, 2008-06-08 at 14:44 +0800, Bean wrote:
> On Sun, Jun 8, 2008 at 2:00 PM, Pavel Roskin <proski@gnu.org> wrote:
> > On Sat, 2008-06-07 at 15:48 +0800, Bean wrote:
> >
> >> I believe the problem is with hexdump. It open the device with
> >> grub_disk_open, which returns the disk object related to the beginning
> >> of partition. However, it read it using disk->dev->read, which is a
> >> low level api that use absolute address. It should be using
> >> grub_disk_read instead.
> >
> > Nice catch!  Indeed, hexdump has special handling for the whole
> > partitions.  And it actually tries to satisfy the low level API by
> > converting offset to the sector number and skipping the remainder.  I
> > guess it could be simplified if grub_disk_read() is used.
> 
> The reason I add device support for hexdump is to debug the nand
> driver. I need to go around the disk cache and call the underlying
> disk driver directly, so I use disk->dev->read. For (nand), there is
> just one partition, so I didn't notice the problem then.

Here's the patch.  Everything seems to be OK.  "--skip=N" is not
recognized, but it's something in the option parsing code.  "-s N" is
working.

Please feel free to apply.

diff --git a/commands/hexdump.c b/commands/hexdump.c
index 6d97fe4..e459b88 100644
--- a/commands/hexdump.c
+++ b/commands/hexdump.c
@@ -99,35 +99,27 @@ grub_cmd_hexdump (struct grub_arg_list *state, int argc, char **args)
   else if ((args[0][0] == '(') && (args[0][namelen - 1] == ')'))
     {
       grub_disk_t disk;
-      grub_disk_addr_t sector;
-      grub_size_t ofs;
 
       args[0][namelen - 1] = 0;
       disk = grub_disk_open (&args[0][1]);
       if (! disk)
         return 0;
 
-      sector = (skip >> (GRUB_DISK_SECTOR_BITS + 2)) * 4;
-      ofs = skip & (GRUB_DISK_SECTOR_SIZE * 4 - 1);
       while (length)
         {
-          grub_size_t len, n;
+          grub_size_t len;
 
           len = length;
-          if (ofs + len > sizeof (buf))
-            len = sizeof (buf) - ofs;
+          if (len > sizeof (buf))
+            len = sizeof (buf);
 
-          n = ((ofs + len + GRUB_DISK_SECTOR_SIZE - 1)
-               >> GRUB_DISK_SECTOR_BITS);
-          if (disk->dev->read (disk, sector, n, buf))
+          if (grub_disk_read (disk, 0, skip, len, buf))
             break;
 
-          hexdump (skip, &buf[ofs], len);
+          hexdump (skip, buf, len);
 
-          ofs = 0;
           skip += len;
           length -= len;
-          sector += 4;
         }
 
       grub_disk_close (disk);


-- 
Regards,
Pavel Roskin



  reply	other threads:[~2008-06-08  6:52 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-04 23:35 [PATCH] biosdisk / open_device() messing up offsets Robert Millan
2008-06-05  1:47 ` Pavel Roskin
2008-06-05 21:12   ` Robert Millan
2008-06-06 15:56 ` Robert Millan
2008-06-06 22:53   ` Pavel Roskin
2008-06-06 23:38     ` Robert Millan
2008-06-07  2:58       ` Pavel Roskin
2008-06-08 19:29         ` Robert Millan
2008-06-07  6:33       ` Pavel Roskin
2008-06-07  7:48         ` Bean
2008-06-08  6:00           ` Pavel Roskin
2008-06-08  6:44             ` Bean
2008-06-08  6:52               ` Pavel Roskin [this message]
2008-06-08  7:11                 ` Bean
2008-06-08  7:29                   ` Pavel Roskin
2008-06-08 11:49                     ` Bean
2008-06-08 18:42                       ` Pavel Roskin
2008-06-08 18:57                         ` Bean
2008-06-09  1:43                           ` Pavel Roskin
2008-06-09 18:30                             ` Bean
2008-06-10  7:16                               ` Bean
2008-06-10 18:26                                 ` Pavel Roskin
2008-06-10 18:51                                   ` Bean
2008-06-10 20:19                                     ` Pavel Roskin
2008-06-10 22:58                                     ` Pavel Roskin
2008-06-10 23:18                                       ` [RFC PATCH] " Pavel Roskin
2008-06-11  5:25                                       ` Bean
2008-06-12  4:01                                         ` Pavel Roskin
2008-06-12  6:22                                         ` Pavel Roskin
2008-06-12  9:51                                           ` Bean
2008-06-12 16:25                                             ` Pavel Roskin
2008-06-13  3:48                                               ` Bean
2008-06-13  4:31                                                 ` Pavel Roskin
2008-06-13  4:39                                                   ` Bean
2008-06-13  5:00                                                     ` Pavel Roskin
2008-06-13  5:18                                                       ` Bean
2008-06-07  8:37     ` Bean
2008-06-08  5:41       ` Pavel Roskin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1212907952.31548.2.camel@rd \
    --to=proski@gnu.org \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.