From f4c01e5c172807e185b31531a0f217324baca521 Mon Sep 17 00:00:00 2001 From: trasz Date: Fri, 9 Mar 2012 18:34:14 +0000 Subject: [PATCH] Improve error reporting in diskinfo(8) by not displaying errno when it doesn't make sense. --- usr.sbin/diskinfo/diskinfo.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/usr.sbin/diskinfo/diskinfo.c b/usr.sbin/diskinfo/diskinfo.c index 554b09e9c2d1..fa234433fc18 100644 --- a/usr.sbin/diskinfo/diskinfo.c +++ b/usr.sbin/diskinfo/diskinfo.c @@ -99,13 +99,13 @@ main(int argc, char **argv) } error = ioctl(fd, DIOCGMEDIASIZE, &mediasize); if (error) { - warn("%s: ioctl(DIOCGMEDIASIZE) failed, probably not a disk.", argv[i]); + warnx("%s: ioctl(DIOCGMEDIASIZE) failed, probably not a disk.", argv[i]); exitval = 1; goto out; } error = ioctl(fd, DIOCGSECTORSIZE, §orsize); if (error) { - warn("%s: DIOCGSECTORSIZE failed, probably not a disk.", argv[i]); + warnx("%s: ioctl(DIOCGSECTORSIZE) failed, probably not a disk.", argv[i]); exitval = 1; goto out; } @@ -178,8 +178,10 @@ rdsect(int fd, off_t blockno, u_int sectorsize) lseek(fd, (off_t)blockno * sectorsize, SEEK_SET); error = read(fd, sector, sectorsize); + if (error == -1) + err(1, "read"); if (error != (int)sectorsize) - err(1, "read error or disk too small for test."); + errx(1, "disk too small for test."); } static void @@ -188,8 +190,10 @@ rdmega(int fd) int error; error = read(fd, mega, sizeof(mega)); + if (error == -1) + err(1, "read"); if (error != sizeof(mega)) - err(1, "read error or disk too small for test."); + errx(1, "disk too small for test."); } static struct timeval tv1, tv2;