public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* libfdisk: fdisk_read_firstsector should seek to offset 0
@ 2014-11-09  2:19 Samuel Thibault
  2014-11-10 10:59 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Samuel Thibault @ 2014-11-09  2:19 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

The current offset of cxt->dev_fd may not be still 0, notably when
blkdev_get_size has to resort to using blkdev_find_size

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org

--- libfdisk/src/utils.c.original	2014-11-09 02:06:55.000000000 +0000
+++ libfdisk/src/utils.c	2014-11-09 02:07:58.000000000 +0000
@@ -49,6 +49,13 @@ int fdisk_read_firstsector(struct fdisk_
 	DBG(CXT, ul_debugobj(cxt, "reading first sector "
 				"buffer [sector_size=%lu]", cxt->sector_size));
 
+	r = lseek(cxt->dev_fd, 0, SEEK_SET);
+	if (r == -1)
+	{
+		DBG(CXT, ul_debugobj(cxt, "failed to seek to first sector %m"));
+		return -errno;
+	}
+
 	r = read(cxt->dev_fd, cxt->firstsector, cxt->sector_size);
 
 	if (r != cxt->sector_size) {

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

* Re: libfdisk: fdisk_read_firstsector should seek to offset 0
  2014-11-09  2:19 libfdisk: fdisk_read_firstsector should seek to offset 0 Samuel Thibault
@ 2014-11-10 10:59 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2014-11-10 10:59 UTC (permalink / raw)
  To: Samuel Thibault, util-linux

On Sun, Nov 09, 2014 at 03:19:01AM +0100, Samuel Thibault wrote:
> The current offset of cxt->dev_fd may not be still 0, notably when
> blkdev_get_size has to resort to using blkdev_find_size

 Oh.. this is stupid bug. Applied, thanks.

    Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

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

end of thread, other threads:[~2014-11-10 10:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-09  2:19 libfdisk: fdisk_read_firstsector should seek to offset 0 Samuel Thibault
2014-11-10 10:59 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox