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>
This commit is contained in:
parent
ae0045e31a
commit
f00cfdfae5
@ -286,25 +286,26 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
|
while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
|
||||||
if (flags & FLAG_NOERROR) /* Pre-zero the buffer if conv=noerror */
|
|
||||||
memset(ibuf, 0, ibs);
|
|
||||||
n = safe_read(ifd, ibuf, ibs);
|
n = safe_read(ifd, ibuf, ibs);
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
break;
|
break;
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
|
/* "Bad block" */
|
||||||
if (!(flags & FLAG_NOERROR))
|
if (!(flags & FLAG_NOERROR))
|
||||||
goto die_infile;
|
goto die_infile;
|
||||||
n = ibs;
|
|
||||||
bb_simple_perror_msg(infile);
|
bb_simple_perror_msg(infile);
|
||||||
/* GNU dd with conv=noerror skips over "bad blocks" */
|
/* GNU dd with conv=noerror skips over bad blocks */
|
||||||
xlseek(ifd, ibs, SEEK_CUR);
|
xlseek(ifd, ibs, SEEK_CUR);
|
||||||
|
/* conv=noerror,sync writes NULs,
|
||||||
|
* conv=noerror just ignores input bad blocks */
|
||||||
|
n = 0;
|
||||||
}
|
}
|
||||||
if ((size_t)n == ibs)
|
if ((size_t)n == ibs)
|
||||||
G.in_full++;
|
G.in_full++;
|
||||||
else {
|
else {
|
||||||
G.in_part++;
|
G.in_part++;
|
||||||
if (flags & FLAG_SYNC) {
|
if (flags & FLAG_SYNC) {
|
||||||
memset(ibuf + n, '\0', ibs - n);
|
memset(ibuf + n, 0, ibs - n);
|
||||||
n = ibs;
|
n = ibs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user