diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-18 20:49:36 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-18 20:49:36 +0200 |
commit | f00cfdfae53d8ef623238ecb1001969b5f649cbd (patch) | |
tree | b2375cbd092ae5c24d8a2d5c9c010b2004e81284 /coreutils | |
parent | ae0045e31a414f4dcb3ab54bfc937c8802180bc6 (diff) | |
download | busybox-w32-f00cfdfae53d8ef623238ecb1001969b5f649cbd.tar.gz busybox-w32-f00cfdfae53d8ef623238ecb1001969b5f649cbd.tar.bz2 busybox-w32-f00cfdfae53d8ef623238ecb1001969b5f649cbd.zip |
dd: fix conv=noerror w/o sync to not write out zeroed blocks
function old new delta
dd_main 1480 1463 -17
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/dd.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index 3fdfc236a..627e7e7b5 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -286,25 +286,26 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
286 | } | 286 | } |
287 | 287 | ||
288 | while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) { | 288 | while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) { |
289 | if (flags & FLAG_NOERROR) /* Pre-zero the buffer if conv=noerror */ | ||
290 | memset(ibuf, 0, ibs); | ||
291 | n = safe_read(ifd, ibuf, ibs); | 289 | n = safe_read(ifd, ibuf, ibs); |
292 | if (n == 0) | 290 | if (n == 0) |
293 | break; | 291 | break; |
294 | if (n < 0) { | 292 | if (n < 0) { |
293 | /* "Bad block" */ | ||
295 | if (!(flags & FLAG_NOERROR)) | 294 | if (!(flags & FLAG_NOERROR)) |
296 | goto die_infile; | 295 | goto die_infile; |
297 | n = ibs; | ||
298 | bb_simple_perror_msg(infile); | 296 | bb_simple_perror_msg(infile); |
299 | /* GNU dd with conv=noerror skips over "bad blocks" */ | 297 | /* GNU dd with conv=noerror skips over bad blocks */ |
300 | xlseek(ifd, ibs, SEEK_CUR); | 298 | xlseek(ifd, ibs, SEEK_CUR); |
299 | /* conv=noerror,sync writes NULs, | ||
300 | * conv=noerror just ignores input bad blocks */ | ||
301 | n = 0; | ||
301 | } | 302 | } |
302 | if ((size_t)n == ibs) | 303 | if ((size_t)n == ibs) |
303 | G.in_full++; | 304 | G.in_full++; |
304 | else { | 305 | else { |
305 | G.in_part++; | 306 | G.in_part++; |
306 | if (flags & FLAG_SYNC) { | 307 | if (flags & FLAG_SYNC) { |
307 | memset(ibuf + n, '\0', ibs - n); | 308 | memset(ibuf + n, 0, ibs - n); |
308 | n = ibs; | 309 | n = ibs; |
309 | } | 310 | } |
310 | } | 311 | } |