]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: fdisk_read_firstsector should seek to offset 0
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 9 Nov 2014 02:19:01 +0000 (03:19 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 10 Nov 2014 10:57:50 +0000 (11:57 +0100)
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

index 732b0adeb3098b638e590b9c771f9d42f86ad965..7b62bf0adaabae61e055b3a0ccaa65f8b3d4e959 100644 (file)
@@ -50,6 +50,13 @@ int fdisk_read_firstsector(struct fdisk_context *cxt)
        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) {