From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1K5Elo-0004Oa-Ag for mharc-grub-devel@gnu.org; Sun, 08 Jun 2008 02:52:52 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K5Elm-0004Ll-Rf for grub-devel@gnu.org; Sun, 08 Jun 2008 02:52:50 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K5Ell-0004It-Cb for grub-devel@gnu.org; Sun, 08 Jun 2008 02:52:50 -0400 Received: from [199.232.76.173] (port=40515 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K5Ell-0004Ij-A7 for grub-devel@gnu.org; Sun, 08 Jun 2008 02:52:49 -0400 Received: from c60.cesmail.net ([216.154.195.49]:32670) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.60) (envelope-from ) id 1K5Elk-0006we-LY for grub-devel@gnu.org; Sun, 08 Jun 2008 02:52:48 -0400 Received: from unknown (HELO relay.cesmail.net) ([192.168.1.81]) by c60.cesmail.net with ESMTP; 08 Jun 2008 02:52:36 -0400 Received: from [192.168.1.46] (pool-71-185-129-251.phlapa.east.verizon.net [71.185.129.251]) by relay.cesmail.net (Postfix) with ESMTP id 5944C619058 for ; Sun, 8 Jun 2008 02:52:35 -0400 (EDT) From: Pavel Roskin To: The development of GRUB 2 In-Reply-To: References: <20080604233536.GA21711@thorin> <20080606155649.GA13255@thorin> <1212792832.1893.17.camel@dv> <20080606233843.GB7956@thorin> <20080607023314.kftgc01au2o4c8sw-cebfxv@webmail.spamcop.net> <1212904845.3071.52.camel@rd> Content-Type: text/plain Date: Sun, 08 Jun 2008 02:52:32 -0400 Message-Id: <1212907952.31548.2.camel@rd> Mime-Version: 1.0 X-Mailer: Evolution 2.22.2 (2.22.2-2.fc9) Content-Transfer-Encoding: 7bit X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. Subject: Re: [PATCH] biosdisk / open_device() messing up offsets X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Jun 2008 06:52:51 -0000 On Sun, 2008-06-08 at 14:44 +0800, Bean wrote: > On Sun, Jun 8, 2008 at 2:00 PM, Pavel Roskin 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