summaryrefslogtreecommitdiff
path: root/usr.sbin/installboot/i386_installboot.c
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2015-12-28 23:00:30 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2015-12-28 23:00:30 +0000
commita6bb008fcbef217b4ac5070e4e0e9a68a3cf9cbc (patch)
treea2122779843cffd22de6b9abaf6f05c89986d761 /usr.sbin/installboot/i386_installboot.c
parent80b98c8b13fd23d28de350b5ce887030eca71f13 (diff)
Replace lseek/[read|write] with pread|pwrite.
ok millert@ a while ago.
Diffstat (limited to 'usr.sbin/installboot/i386_installboot.c')
-rw-r--r--usr.sbin/installboot/i386_installboot.c41
1 files changed, 17 insertions, 24 deletions
diff --git a/usr.sbin/installboot/i386_installboot.c b/usr.sbin/installboot/i386_installboot.c
index ed6199a97f0..793a0937531 100644
--- a/usr.sbin/installboot/i386_installboot.c
+++ b/usr.sbin/installboot/i386_installboot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: i386_installboot.c,v 1.25 2015/12/24 20:14:07 krw Exp $ */
+/* $OpenBSD: i386_installboot.c,v 1.26 2015/12/28 23:00:29 krw Exp $ */
/* $NetBSD: installboot.c,v 1.5 1995/11/17 23:23:50 gwr Exp $ */
/*
@@ -204,16 +204,14 @@ write_bootblocks(int devfd, char *dev, struct disklabel *dl)
stage1, BOOTBIOS_MAXSEC);
if (!nowrite) {
- if (lseek(devfd, (off_t)start * dl->d_secsize, SEEK_SET) < 0)
- err(1, "seek boot sector");
secbuf = calloc(1, dl->d_secsize);
- if (read(devfd, secbuf, dl->d_secsize) != dl->d_secsize)
- err(1, "read boot sector");
+ if (pread(devfd, secbuf, dl->d_secsize, (off_t)start *
+ dl->d_secsize) != dl->d_secsize)
+ err(1, "pread boot sector");
bcopy(blkstore, secbuf, blksize);
- if (lseek(devfd, (off_t)start * dl->d_secsize, SEEK_SET) < 0)
- err(1, "seek bootstrap");
- if (write(devfd, secbuf, dl->d_secsize) != dl->d_secsize)
- err(1, "write bootstrap");
+ if (pwrite(devfd, secbuf, dl->d_secsize, (off_t)start *
+ dl->d_secsize) != dl->d_secsize)
+ err(1, "pwrite bootstrap");
free(secbuf);
}
}
@@ -402,9 +400,9 @@ again:
if ((secbuf = malloc(dl->d_secsize)) == NULL)
err(1, NULL);
- if (lseek(devfd, (off_t)mbroff * dl->d_secsize, SEEK_SET) < 0 ||
- read(devfd, secbuf, dl->d_secsize) < (ssize_t)sizeof(mbr))
- err(4, "can't read boot record");
+ if (pread(devfd, secbuf, dl->d_secsize, (off_t)mbroff * dl->d_secsize)
+ < (ssize_t)sizeof(mbr))
+ err(4, "can't pread boot record");
bcopy(secbuf, &mbr, sizeof(mbr));
free(secbuf);
@@ -518,7 +516,7 @@ findgptefisys(int devfd, struct disklabel *dl)
off = dl->d_secsize; /* Read header from sector 1. */
len = pread(devfd, secbuf, dl->d_secsize, off);
if (len != dl->d_secsize)
- err(4, "can't read gpt header");
+ err(4, "can't pread gpt header");
memcpy(&gh, secbuf, sizeof(gh));
free(secbuf);
@@ -620,10 +618,9 @@ loadproto(char *fname, long *size)
if (ph == NULL)
err(1, NULL);
phsize = eh.e_phnum * sizeof(Elf_Phdr);
- lseek(fd, eh.e_phoff, SEEK_SET);
- if (read(fd, ph, phsize) != phsize)
- errx(1, "%s: can't read header", fname);
+ if (pread(fd, ph, phsize, eh.e_phoff) != phsize)
+ errx(1, "%s: can't pread header", fname);
tdsize = ph->p_filesz;
@@ -636,9 +633,8 @@ loadproto(char *fname, long *size)
err(1, NULL);
/* Read the rest of the file. */
- lseek(fd, ph->p_offset, SEEK_SET);
- if (read(fd, bp, tdsize) != (ssize_t)tdsize)
- errx(1, "%s: read failed", fname);
+ if (pread(fd, bp, tdsize, ph->p_offset) != (ssize_t)tdsize)
+ errx(1, "%s: pread failed", fname);
*size = tdsize; /* not aligned to DEV_BSIZE */
@@ -649,11 +645,8 @@ loadproto(char *fname, long *size)
static void
devread(int fd, void *buf, daddr_t blk, size_t size, char *msg)
{
- if (lseek(fd, dbtob((off_t)blk), SEEK_SET) != dbtob((off_t)blk))
- err(1, "%s: devread: lseek", msg);
-
- if (read(fd, buf, size) != (ssize_t)size)
- err(1, "%s: devread: read", msg);
+ if (pread(fd, buf, size, dbtob((off_t)blk)) != (ssize_t)size)
+ err(1, "%s: devread: pread", msg);
}
static char sblock[SBSIZE];