aboutsummaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorJaakko Heinonen <jh@FreeBSD.org>2010-06-30 18:34:45 +0000
committerJaakko Heinonen <jh@FreeBSD.org>2010-06-30 18:34:45 +0000
commit049a97931c5bd75650a5278f77ebaabcbdfbe05f (patch)
treec7a01d7cb9a3b2971cbae5008380fcd1662749ac /sbin
parentfc0de8f0b67cc985fc43ce36df1a736f0d37c9a7 (diff)
downloadsrc-049a97931c5bd75650a5278f77ebaabcbdfbe05f.tar.gz
src-049a97931c5bd75650a5278f77ebaabcbdfbe05f.zip
- Don't assign the return value from read(2) to a variable of type
int. - Use errx(3) instead of err(3) to print the error message on short reads in readlabel(). errno won't be set on short reads which can easily occur here due to the fixed size read request. PR: 144307 Reviewed by: bde
Notes
Notes: svn path=/head/; revision=209614
Diffstat (limited to 'sbin')
-rw-r--r--sbin/bsdlabel/bsdlabel.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/sbin/bsdlabel/bsdlabel.c b/sbin/bsdlabel/bsdlabel.c
index 7f058747f246..b34fe75d0758 100644
--- a/sbin/bsdlabel/bsdlabel.c
+++ b/sbin/bsdlabel/bsdlabel.c
@@ -347,7 +347,7 @@ makelabel(const char *type, struct disklabel *lp)
static void
readboot(void)
{
- int fd, i;
+ int fd;
struct stat st;
uint64_t *p;
@@ -358,8 +358,7 @@ readboot(void)
err(1, "cannot open %s", xxboot);
fstat(fd, &st);
if (alphacksum && st.st_size <= BBSIZE - 512) {
- i = read(fd, bootarea + 512, st.st_size);
- if (i != st.st_size)
+ if (read(fd, bootarea + 512, st.st_size) != st.st_size)
err(1, "read error %s", xxboot);
/*
@@ -372,8 +371,7 @@ readboot(void)
p[62] = 0;
return;
} else if ((!alphacksum) && st.st_size <= BBSIZE) {
- i = read(fd, bootarea, st.st_size);
- if (i != st.st_size)
+ if (read(fd, bootarea, st.st_size) != st.st_size)
err(1, "read error %s", xxboot);
return;
}
@@ -479,6 +477,7 @@ get_file_parms(int f)
static int
readlabel(int flag)
{
+ ssize_t nbytes;
uint32_t lba;
int f, i;
int error;
@@ -498,8 +497,11 @@ readlabel(int flag)
errx(1,
"disks with more than 2^32-1 sectors are not supported");
(void)lseek(f, (off_t)0, SEEK_SET);
- if (read(f, bootarea, BBSIZE) != BBSIZE)
+ nbytes = read(f, bootarea, BBSIZE);
+ if (nbytes == -1)
err(4, "%s read", specname);
+ if (nbytes != BBSIZE)
+ errx(4, "couldn't read %d bytes from %s", BBSIZE, specname);
close (f);
error = bsd_disklabel_le_dec(
bootarea + (labeloffset + labelsoffset * secsize),