-/* $OpenBSD: df.c,v 1.50 2009/10/27 23:59:21 deraadt Exp $ */
+/* $OpenBSD: df.c,v 1.51 2014/05/20 21:11:16 krw Exp $ */
/* $NetBSD: df.c,v 1.21.2.1 1995/11/01 00:06:11 jtc Exp $ */
/*
{
int nr;
- (void)lseek(rfd, off, SEEK_SET);
- if ((nr = read(rfd, buf, cnt)) != cnt) {
+ if ((nr = pread(rfd, buf, cnt, off)) != cnt) {
/* Probably a dismounted disk if errno == EIO. */
if (errno != EIO)
(void)fprintf(stderr, "\ndf: %qd: %s\n",
-/* $OpenBSD: traverse.c,v 1.28 2013/11/12 04:59:02 deraadt Exp $ */
+/* $OpenBSD: traverse.c,v 1.29 2014/05/20 21:11:16 krw Exp $ */
/* $NetBSD: traverse.c,v 1.17 1997/06/05 11:13:27 lukem Exp $ */
/*-
int cnt, i;
loop:
- if (lseek(diskfd, ((off_t)blkno << dev_bshift), SEEK_SET) < 0)
- msg("bread: lseek fails\n");
- if ((cnt = read(diskfd, buf, size)) == size)
+ if ((cnt = pread(diskfd, buf, size, (off_t)blkno << dev_bshift)) ==
+ size)
return;
if (blkno + (size / dev_bsize) > fsbtodb(sblock, sblock->fs_ffs1_size)) {
/*
*/
memset(buf, 0, size);
for (i = 0; i < size; i += dev_bsize, buf += dev_bsize, blkno++) {
- if (lseek(diskfd, ((off_t)blkno << dev_bshift), SEEK_SET) < 0)
- msg("bread: lseek2 fails!\n");
- if ((cnt = read(diskfd, buf, (int)dev_bsize)) == dev_bsize)
+ if ((cnt = pread(diskfd, buf, dev_bsize,
+ (off_t)blkno << dev_bshift)) == dev_bsize)
continue;
if (cnt == -1) {
msg("read error from %s: %s: [sector %lld]: count=%ld\n",
-/* $OpenBSD: utilities.c,v 1.19 2011/03/12 17:50:47 deraadt Exp $ */
+/* $OpenBSD: utilities.c,v 1.20 2014/05/20 21:11:16 krw Exp $ */
/* $NetBSD: utilities.c,v 1.6 2001/02/04 21:19:34 christos Exp $ */
/*
offset = blk;
offset *= dev_bsize;
- if (lseek(fd, offset, SEEK_SET) < 0)
- rwerror("SEEK", blk);
- else if (read(fd, buf, (int)size) == size)
+ if (pread(fd, buf, size, offset) == size)
return (0);
rwerror("READ", blk);
- if (lseek(fd, offset, SEEK_SET) < 0)
- rwerror("SEEK", blk);
errs = 0;
memset(buf, 0, (size_t)size);
printf("THE FOLLOWING DISK SECTORS COULD NOT BE READ:");
for (cp = buf, i = 0; i < size; i += secsize, cp += secsize) {
- if (read(fd, cp, (int)secsize) != secsize) {
- (void)lseek(fd, offset + i + secsize, SEEK_SET);
+ if (pread(fd, cp, secsize, offset + i) != secsize) {
if (secsize != dev_bsize && dev_bsize != 1)
printf(" %ld (%ld),",
(blk * dev_bsize + i) / secsize,
return;
offset = blk;
offset *= dev_bsize;
- if (lseek(fd, offset, SEEK_SET) < 0)
- rwerror("SEEK", blk);
- else if (write(fd, buf, (int)size) == size) {
+ if (pwrite(fd, buf, size, offset) == size) {
fsmodified = 1;
return;
}
rwerror("WRITE", blk);
- if (lseek(fd, offset, SEEK_SET) < 0)
- rwerror("SEEK", blk);
printf("THE FOLLOWING SECTORS COULD NOT BE WRITTEN:");
for (cp = buf, i = 0; i < size; i += dev_bsize, cp += dev_bsize)
- if (write(fd, cp, (int)dev_bsize) != dev_bsize) {
- (void)lseek(fd, offset + i + dev_bsize, SEEK_SET);
+ if (pwrite(fd, cp, dev_bsize, offset + i) != dev_bsize) {
printf(" %ld,", blk + i / dev_bsize);
}
printf("\n");
-/* $OpenBSD: utilities.c,v 1.43 2014/05/09 13:19:34 krw Exp $ */
+/* $OpenBSD: utilities.c,v 1.44 2014/05/20 21:11:16 krw Exp $ */
/* $NetBSD: utilities.c,v 1.18 1996/09/27 22:45:20 christos Exp $ */
/*
offset = blk;
offset *= DEV_BSIZE;
- if (lseek(fd, offset, SEEK_SET) < 0)
- rwerror("SEEK", blk);
- else if (read(fd, buf, (int)size) == size)
+ if (pread(fd, buf, size, offset) == size)
return (0);
rwerror("READ", blk);
- if (lseek(fd, offset, SEEK_SET) < 0)
- rwerror("SEEK", blk);
errs = 0;
memset(buf, 0, (size_t)size);
printf("THE FOLLOWING DISK SECTORS COULD NOT BE READ:");
for (cp = buf, i = 0; i < size; i += secsize, cp += secsize) {
- if (read(fd, cp, (int)secsize) != secsize) {
- (void)lseek(fd, offset + i + secsize, SEEK_SET);
+ if (pread(fd, cp, secsize, offset + i) != secsize) {
if (secsize != DEV_BSIZE)
printf(" %lld (%lld),",
(long long)((blk * DEV_BSIZE + i) /
return;
offset = blk;
offset *= DEV_BSIZE;
- if (lseek(fd, offset, SEEK_SET) < 0)
- rwerror("SEEK", blk);
- else if (write(fd, buf, (int)size) == size) {
+ if (pwrite(fd, buf, size, offset) == size) {
fsmodified = 1;
return;
}
rwerror("WRITE", blk);
- if (lseek(fd, offset, SEEK_SET) < 0)
- rwerror("SEEK", blk);
printf("THE FOLLOWING SECTORS COULD NOT BE WRITTEN:");
for (cp = buf, i = 0; i < size; i += secsize, cp += secsize)
- if (write(fd, cp, (int)secsize) != secsize) {
- (void)lseek(fd, offset + i + secsize, SEEK_SET);
+ if (pwrite(fd, cp, secsize, offset + i) != secsize) {
if (secsize != DEV_BSIZE)
printf(" %lld (%lld),",
(long long)((blk * DEV_BSIZE + i) /
-/* $OpenBSD: ncheck_ffs.c,v 1.41 2014/05/13 05:50:24 guenther Exp $ */
+/* $OpenBSD: ncheck_ffs.c,v 1.42 2014/05/20 21:11:16 krw Exp $ */
/*-
* Copyright (c) 1995, 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
int cnt, i;
loop:
- if (lseek(diskfd, ((off_t)blkno << dev_bshift), SEEK_SET) < 0)
- warnx("bread: lseek fails");
- if ((cnt = read(diskfd, buf, size)) == size)
+ if ((cnt = pread(diskfd, buf, size, (off_t)blkno << dev_bshift)) ==
+ size)
return;
if (blkno + (size / dev_bsize) > fsbtodb(sblock, sblock->fs_ffs1_size)) {
/*
*/
memset(buf, 0, size);
for (i = 0; i < size; i += dev_bsize, buf += dev_bsize, blkno++) {
- if (lseek(diskfd, ((off_t)blkno << dev_bshift), SEEK_SET) < 0)
- warnx("bread: lseek2 fails!");
- if ((cnt = read(diskfd, buf, (int)dev_bsize)) == dev_bsize)
+ if ((cnt = pread(diskfd, buf, (int)dev_bsize,
+ (off_t)blkno << dev_bshift)) == dev_bsize)
continue;
if (cnt == -1) {
warnx("read error from %s: %s: [sector %lld]: "
-/* $OpenBSD: quotacheck.c,v 1.32 2014/05/12 21:10:35 krw Exp $ */
+/* $OpenBSD: quotacheck.c,v 1.33 2014/05/20 21:11:16 krw Exp $ */
/* $NetBSD: quotacheck.c,v 1.12 1996/03/30 22:34:25 mark Exp $ */
/*
void
bread(daddr_t bno, char *buf, long cnt)
{
- if (lseek(fi, (off_t)bno * DEV_BSIZE, SEEK_SET) < 0 ||
- read(fi, buf, cnt) != cnt)
- err(1, "bread failed on block %lld", (long long)bno);
+ if (pread(fi, buf, cnt, bno * DEV_BSIZE) != cnt)
+ err(1, "read failed on block %lld", (long long)bno);
}
-/* $OpenBSD: tunefs.c,v 1.33 2014/05/12 12:16:53 krw Exp $ */
+/* $OpenBSD: tunefs.c,v 1.34 2014/05/20 21:11:16 krw Exp $ */
/* $NetBSD: tunefs.c,v 1.33 2005/01/19 20:46:16 xtraeme Exp $ */
/*
static void
bwrite(daddr_t blk, char *buffer, int size, const char *file)
{
- off_t offset;
-
- offset = (off_t)blk * DEV_BSIZE;
- if (lseek(fi, offset, SEEK_SET) == -1)
- err(6, "%s: seeking to %lld", file, (long long)offset);
- if (write(fi, buffer, size) != size)
- err(7, "%s: writing %d bytes", file, size);
+ if (pwrite(fi, buffer, size, blk * DEV_BSIZE) != size)
+ err(7, "%s: writing %d bytes @ %lld", file, size,
+ (long long)(blk * DEV_BSIZE));
}
static void
bread(daddr_t blk, char *buffer, int cnt, const char *file)
{
- off_t offset;
- int i;
-
- offset = (off_t)blk * DEV_BSIZE;
- if (lseek(fi, offset, SEEK_SET) == -1)
- err(4, "%s: seeking to %lld", file, (long long)offset);
- if ((i = read(fi, buffer, cnt)) != cnt)
- errx(5, "%s: short read", file);
+ if ((pread(fi, buffer, cnt, (off_t)blk * DEV_BSIZE)) != cnt)
+ errx(5, "%s: reading %d bytes @ %lld", file, cnt,
+ (long long)(blk * DEV_BSIZE));
}
static int