diff options
author | Karel Zak | 2012-11-30 11:54:10 +0100 |
---|---|---|
committer | Karel Zak | 2012-11-30 11:54:10 +0100 |
commit | 21770662c3ddc0655831312067e2d2b9e5281eec (patch) | |
tree | 9d179379dda5ae27ebde76d1a03f1ba1cae3b90e /fdisks/fdisk.h | |
parent | libblkid: cleanup blkid_strconcat (diff) | |
download | kernel-qcow2-util-linux-21770662c3ddc0655831312067e2d2b9e5281eec.tar.gz kernel-qcow2-util-linux-21770662c3ddc0655831312067e2d2b9e5281eec.tar.xz kernel-qcow2-util-linux-21770662c3ddc0655831312067e2d2b9e5281eec.zip |
fdisk: don't fails silently if EBR is outside of disk
Reported-by: Phillip Susi <psusi@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisks/fdisk.h')
-rw-r--r-- | fdisks/fdisk.h | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/fdisks/fdisk.h b/fdisks/fdisk.h index 90ebb6209..f8e2c5d6f 100644 --- a/fdisks/fdisk.h +++ b/fdisks/fdisk.h @@ -311,18 +311,22 @@ static inline void set_start_sect(struct partition *p, unsigned int start_sect) store4_little_endian(p->start4, start_sect); } -static inline void seek_sector(struct fdisk_context *cxt, sector_t secno) +static inline int seek_sector(struct fdisk_context *cxt, sector_t secno) { off_t offset = (off_t) secno * cxt->sector_size; - if (lseek(cxt->dev_fd, offset, SEEK_SET) == (off_t) -1) - fatal(cxt, unable_to_seek); + + return lseek(cxt->dev_fd, offset, SEEK_SET) == (off_t) -1 ? -errno : 0; } -static inline void read_sector(struct fdisk_context *cxt, sector_t secno, unsigned char *buf) +static inline int read_sector(struct fdisk_context *cxt, sector_t secno, unsigned char *buf) { - seek_sector(cxt, secno); - if (read(cxt->dev_fd, buf, cxt->sector_size) != (ssize_t) cxt->sector_size) - fatal(cxt, unable_to_read); + int rc = seek_sector(cxt, secno); + + if (rc < 0) + return rc; + + return read(cxt->dev_fd, buf, cxt->sector_size) != + (ssize_t) cxt->sector_size ? -errno : 0; } static inline sector_t get_start_sect(struct partition *p) |