[git commit] dd: exit with 1 if last write was incomplete

Denys Vlasenko vda.linux at googlemail.com
Wed Jan 10 09:58:55 UTC 2018


commit: https://git.busybox.net/busybox/commit/?id=5afd63a631f49112ac305ea1532dd226e9c39d12
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

$ busybox dd if=/dev/zero of=/dev/loop0 bs=100M count=8; echo $?
8+0 records in
7+1 records out
805220352 bytes (767.9MB) copied, 0.464010 seconds, 1.6GB/s
1  <=========== FIXED

function                                             old     new   delta
write_and_stats                                       96      97      +1

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 coreutils/dd.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/coreutils/dd.c b/coreutils/dd.c
index d302f35..9d173cc 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -195,14 +195,16 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
 	ssize_t n = full_write_or_warn(buf, len, filename);
 	if (n < 0)
 		return 1;
-	if ((size_t)n == obs)
-		G.out_full++;
-	else if (n) /* > 0 */
-		G.out_part++;
 #if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
 	G.total_bytes += n;
 #endif
-	return 0;
+	if ((size_t)n == obs) {
+		G.out_full++;
+		return 0;
+	}
+	if (n) /* > 0 */
+		G.out_part++;
+	return 1;
 }
 
 #if ENABLE_LFS


More information about the busybox-cvs mailing list