public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org
Subject: libfdisk: fdisk_read_firstsector should seek to offset 0
Date: Sun, 9 Nov 2014 03:19:01 +0100	[thread overview]
Message-ID: <20141109021901.GA2799@type.youpi.perso.aquilenet.fr> (raw)

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) {

             reply	other threads:[~2014-11-09  2:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-09  2:19 Samuel Thibault [this message]
2014-11-10 10:59 ` libfdisk: fdisk_read_firstsector should seek to offset 0 Karel Zak

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=20141109021901.GA2799@type.youpi.perso.aquilenet.fr \
    --to=samuel.thibault@ens-lyon.org \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox