Module Name:    src
Committed By:   dyoung
Date:           Thu Apr 16 18:54:16 UTC 2009

Modified Files:
        src/usr.sbin/makefs: ffs.c

Log Message:
Distinguish read(2) failure due to a short read from other causes, and
suggest in the error message a possible cause: the size= attribute in
the metalog (if one is given) may be different from the source file's
actual size.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/usr.sbin/makefs/ffs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/makefs/ffs.c
diff -u src/usr.sbin/makefs/ffs.c:1.42 src/usr.sbin/makefs/ffs.c:1.43
--- src/usr.sbin/makefs/ffs.c:1.42	Mon Dec 18 21:03:29 2006
+++ src/usr.sbin/makefs/ffs.c	Thu Apr 16 18:54:16 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs.c,v 1.42 2006/12/18 21:03:29 christos Exp $	*/
+/*	$NetBSD: ffs.c,v 1.43 2009/04/16 18:54:16 dyoung Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -71,7 +71,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: ffs.c,v 1.42 2006/12/18 21:03:29 christos Exp $");
+__RCSID("$NetBSD: ffs.c,v 1.43 2009/04/16 18:54:16 dyoung Exp $");
 #endif	/* !__lint */
 
 #include <sys/param.h>
@@ -845,6 +845,7 @@
 	int 	isfile, ffd;
 	char	*fbuf, *p;
 	off_t	bufleft, chunk, offset;
+	ssize_t nread;
 	struct inode	in;
 	struct buf *	bp;
 	ffs_opt_t	*ffs_opts = fsopts->fs_specific;
@@ -899,12 +900,19 @@
 	chunk = 0;
 	for (bufleft = DIP(din, size); bufleft > 0; bufleft -= chunk) {
 		chunk = MIN(bufleft, ffs_opts->bsize);
-		if (isfile) {
-			if (read(ffd, fbuf, chunk) != chunk)
-				err(1, "Reading `%s', %lld bytes to go",
-				    (char *)buf, (long long)bufleft);
+		if (!isfile)
+			;
+		else if ((nread = read(ffd, fbuf, chunk)) == -1)
+			err(EXIT_FAILURE, "Reading `%s', %lld bytes to go",
+			    (char *)buf, (long long)bufleft);
+		else if (nread != chunk)
+			errx(EXIT_FAILURE, "Reading `%s', %lld bytes to go, "
+			    "read %zd bytes, expected %ju bytes, does "
+			    "metalog size= attribute mismatch source size?",
+			    (char *)buf, (long long)bufleft, nread,
+			    (uintmax_t)chunk);
+		else
 			p = fbuf;
-		}
 		offset = DIP(din, size) - bufleft;
 		if (debug & DEBUG_FS_WRITE_FILE_BLOCK)
 			printf(

Reply via email to