From c37ebc12a5d7fd9c824a727215ceeb7f0243d9c3 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 25 Jun 2013 15:58:36 +0200 Subject: fdisk: cleanup header file Signed-off-by: Karel Zak --- fdisks/fdiskdoslabel.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'fdisks/fdiskdoslabel.c') diff --git a/fdisks/fdiskdoslabel.c b/fdisks/fdiskdoslabel.c index 84c4a3431..67199eaea 100644 --- a/fdisks/fdiskdoslabel.c +++ b/fdisks/fdiskdoslabel.c @@ -175,6 +175,24 @@ static int get_partition_unused_primary(struct fdisk_context *cxt) } } +static int seek_sector(struct fdisk_context *cxt, sector_t secno) +{ + off_t offset = (off_t) secno * cxt->sector_size; + + return lseek(cxt->dev_fd, offset, SEEK_SET) == (off_t) -1 ? -errno : 0; +} + +static int read_sector(struct fdisk_context *cxt, sector_t secno, + unsigned char *buf) +{ + 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; +} /* Allocate a buffer and read a partition table sector */ static int read_pte(struct fdisk_context *cxt, int pno, sector_t offset) -- cgit v1.2.3-55-g7522