summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fdisks/fdisk.h18
-rw-r--r--fdisks/fdiskdoslabel.c14
2 files changed, 23 insertions, 9 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)
diff --git a/fdisks/fdiskdoslabel.c b/fdisks/fdiskdoslabel.c
index 3e56e3885..0ace7f846 100644
--- a/fdisks/fdiskdoslabel.c
+++ b/fdisks/fdiskdoslabel.c
@@ -69,7 +69,10 @@ static void read_pte(struct fdisk_context *cxt, int pno, sector_t offset)
pe->offset = offset;
pe->sectorbuffer = xmalloc(cxt->sector_size);
- read_sector(cxt, offset, pe->sectorbuffer);
+
+ if (read_sector(cxt, offset, pe->sectorbuffer) != 0)
+ fprintf(stderr, _("Failed to read extended partition table (offset=%jd)\n"),
+ (uintmax_t) offset);
pe->changed = 0;
pe->part_table = pe->ext_pointer = NULL;
}
@@ -790,7 +793,14 @@ static void dos_add_partition(
static int write_sector(struct fdisk_context *cxt, sector_t secno,
unsigned char *buf)
{
- seek_sector(cxt, secno);
+ int rc;
+
+ rc = seek_sector(cxt, secno);
+ if (rc != 0) {
+ fprintf(stderr, _("write sector %jd failed: seek failed"),
+ (uintmax_t) secno);
+ return rc;
+ }
if (write(cxt->dev_fd, buf, cxt->sector_size) != (ssize_t) cxt->sector_size)
return -errno;
return 0;