diff options
author | Samuel Thibault | 2014-11-09 03:19:01 +0100 |
---|---|---|
committer | Karel Zak | 2014-11-10 11:57:50 +0100 |
commit | a56b70f8ffb658a5a722c47cf77ea04c143fa0d9 (patch) | |
tree | 91e17d5b7531fd2070347f213429f9e055bcb0b7 /libfdisk/src/utils.c | |
parent | tests: simplify and update swaplabel test (diff) | |
download | kernel-qcow2-util-linux-a56b70f8ffb658a5a722c47cf77ea04c143fa0d9.tar.gz kernel-qcow2-util-linux-a56b70f8ffb658a5a722c47cf77ea04c143fa0d9.tar.xz kernel-qcow2-util-linux-a56b70f8ffb658a5a722c47cf77ea04c143fa0d9.zip |
libfdisk: fdisk_read_firstsector should seek to offset 0
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
Diffstat (limited to 'libfdisk/src/utils.c')
-rw-r--r-- | libfdisk/src/utils.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/libfdisk/src/utils.c b/libfdisk/src/utils.c index 732b0adeb..7b62bf0ad 100644 --- a/libfdisk/src/utils.c +++ b/libfdisk/src/utils.c @@ -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) { |