diff options
author | Ron Yorston <rmy@pobox.com> | 2021-05-14 08:17:12 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-05-14 08:17:12 +0100 |
commit | a3f5a1b7f4275f713acf22f534f95c0da8392e53 (patch) | |
tree | 49b65422a3e9c33f508da9ccf3ae79d324bd9e96 /coreutils/dd.c | |
parent | 375cda9a88024135d630ca8990d9aff4ea414e89 (diff) | |
parent | 7de0ab21d939a5a304157f75918d0318a95261a3 (diff) | |
download | busybox-w32-a3f5a1b7f4275f713acf22f534f95c0da8392e53.tar.gz busybox-w32-a3f5a1b7f4275f713acf22f534f95c0da8392e53.tar.bz2 busybox-w32-a3f5a1b7f4275f713acf22f534f95c0da8392e53.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils/dd.c')
-rw-r--r-- | coreutils/dd.c | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index bd799aa2b..15938f689 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -59,7 +59,7 @@ | |||
59 | //usage: "[if=FILE] [of=FILE] [" IF_FEATURE_DD_IBS_OBS("ibs=N obs=N/") "bs=N] [count=N] [skip=N] [seek=N]\n" | 59 | //usage: "[if=FILE] [of=FILE] [" IF_FEATURE_DD_IBS_OBS("ibs=N obs=N/") "bs=N] [count=N] [skip=N] [seek=N]\n" |
60 | //usage: IF_FEATURE_DD_IBS_OBS( | 60 | //usage: IF_FEATURE_DD_IBS_OBS( |
61 | //usage: " [conv=notrunc|noerror|sync|fsync]\n" | 61 | //usage: " [conv=notrunc|noerror|sync|fsync]\n" |
62 | //usage: " [iflag=skip_bytes|fullblock|direct] [oflag=seek_bytes|append|direct]" | 62 | //usage: " [iflag=skip_bytes|count_bytes|fullblock|direct] [oflag=seek_bytes|append|direct]" |
63 | //usage: ) | 63 | //usage: ) |
64 | //usage:#define dd_full_usage "\n\n" | 64 | //usage:#define dd_full_usage "\n\n" |
65 | //usage: "Copy a file with converting and formatting\n" | 65 | //usage: "Copy a file with converting and formatting\n" |
@@ -82,6 +82,7 @@ | |||
82 | //usage: "\n conv=fsync Physically write data out before finishing" | 82 | //usage: "\n conv=fsync Physically write data out before finishing" |
83 | //usage: "\n conv=swab Swap every pair of bytes" | 83 | //usage: "\n conv=swab Swap every pair of bytes" |
84 | //usage: "\n iflag=skip_bytes skip=N is in bytes" | 84 | //usage: "\n iflag=skip_bytes skip=N is in bytes" |
85 | //usage: "\n iflag=count_bytes count=N is in bytes" | ||
85 | //usage: "\n oflag=seek_bytes seek=N is in bytes" | 86 | //usage: "\n oflag=seek_bytes seek=N is in bytes" |
86 | //usage: "\n iflag=direct O_DIRECT input" | 87 | //usage: "\n iflag=direct O_DIRECT input" |
87 | //usage: "\n oflag=direct O_DIRECT output" | 88 | //usage: "\n oflag=direct O_DIRECT output" |
@@ -139,21 +140,22 @@ enum { | |||
139 | FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS, | 140 | FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS, |
140 | /* end of conv flags */ | 141 | /* end of conv flags */ |
141 | /* start of input flags */ | 142 | /* start of input flags */ |
142 | FLAG_IFLAG_SHIFT = 5, | 143 | FLAG_IFLAG_SHIFT = 5, |
143 | FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS, | 144 | FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS, |
144 | FLAG_FULLBLOCK = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS, | 145 | FLAG_COUNT_BYTES = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS, |
145 | FLAG_IDIRECT = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS, | 146 | FLAG_FULLBLOCK = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS, |
147 | FLAG_IDIRECT = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS, | ||
146 | /* end of input flags */ | 148 | /* end of input flags */ |
147 | /* start of output flags */ | 149 | /* start of output flags */ |
148 | FLAG_OFLAG_SHIFT = 8, | 150 | FLAG_OFLAG_SHIFT = 9, |
149 | FLAG_SEEK_BYTES = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS, | 151 | FLAG_SEEK_BYTES = (1 << 9) * ENABLE_FEATURE_DD_IBS_OBS, |
150 | FLAG_APPEND = (1 << 9) * ENABLE_FEATURE_DD_IBS_OBS, | 152 | FLAG_APPEND = (1 << 10) * ENABLE_FEATURE_DD_IBS_OBS, |
151 | FLAG_ODIRECT = (1 << 10) * ENABLE_FEATURE_DD_IBS_OBS, | 153 | FLAG_ODIRECT = (1 << 11) * ENABLE_FEATURE_DD_IBS_OBS, |
152 | /* end of output flags */ | 154 | /* end of output flags */ |
153 | FLAG_TWOBUFS = (1 << 11) * ENABLE_FEATURE_DD_IBS_OBS, | 155 | FLAG_TWOBUFS = (1 << 12) * ENABLE_FEATURE_DD_IBS_OBS, |
154 | FLAG_COUNT = 1 << 12, | 156 | FLAG_COUNT = 1 << 13, |
155 | FLAG_STATUS_NONE = 1 << 13, | 157 | FLAG_STATUS_NONE = 1 << 14, |
156 | FLAG_STATUS_NOXFER = 1 << 14, | 158 | FLAG_STATUS_NOXFER = 1 << 15, |
157 | }; | 159 | }; |
158 | 160 | ||
159 | static void dd_output_status(int UNUSED_PARAM cur_signal) | 161 | static void dd_output_status(int UNUSED_PARAM cur_signal) |
@@ -178,8 +180,9 @@ static void dd_output_status(int UNUSED_PARAM cur_signal) | |||
178 | //So far we react to it (we print the stats), | 180 | //So far we react to it (we print the stats), |
179 | //status=none only suppresses final, non-USR1 generated status message. | 181 | //status=none only suppresses final, non-USR1 generated status message. |
180 | # endif | 182 | # endif |
181 | fprintf(stderr, "%llu bytes (%sB) copied, ", | 183 | fprintf(stderr, /*G.total_bytes < 1024 |
182 | G.total_bytes, | 184 | ? "%llu bytes copied, " : */ "%llu bytes (%sB) copied, " |
185 | , G.total_bytes, | ||
183 | /* show fractional digit, use suffixes */ | 186 | /* show fractional digit, use suffixes */ |
184 | make_human_readable_str(G.total_bytes, 1, 0) | 187 | make_human_readable_str(G.total_bytes, 1, 0) |
185 | ); | 188 | ); |
@@ -322,7 +325,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
322 | static const char conv_words[] ALIGN1 = | 325 | static const char conv_words[] ALIGN1 = |
323 | "notrunc\0""sync\0""noerror\0""fsync\0""swab\0"; | 326 | "notrunc\0""sync\0""noerror\0""fsync\0""swab\0"; |
324 | static const char iflag_words[] ALIGN1 = | 327 | static const char iflag_words[] ALIGN1 = |
325 | "skip_bytes\0""fullblock\0""direct\0"; | 328 | "skip_bytes\0""count_bytes\0""fullblock\0""direct\0"; |
326 | static const char oflag_words[] ALIGN1 = | 329 | static const char oflag_words[] ALIGN1 = |
327 | "seek_bytes\0append\0""direct\0"; | 330 | "seek_bytes\0append\0""direct\0"; |
328 | #endif | 331 | #endif |
@@ -364,6 +367,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
364 | /* Partially implemented: */ | 367 | /* Partially implemented: */ |
365 | //swab swap every pair of input bytes: will abort on non-even reads | 368 | //swab swap every pair of input bytes: will abort on non-even reads |
366 | OP_iflag_skip_bytes, | 369 | OP_iflag_skip_bytes, |
370 | OP_iflag_count_bytes, | ||
367 | OP_iflag_fullblock, | 371 | OP_iflag_fullblock, |
368 | OP_iflag_direct, | 372 | OP_iflag_direct, |
369 | OP_oflag_seek_bytes, | 373 | OP_oflag_seek_bytes, |
@@ -581,8 +585,17 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
581 | goto die_outfile; | 585 | goto die_outfile; |
582 | } | 586 | } |
583 | 587 | ||
584 | while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) { | 588 | while (1) { |
585 | ssize_t n = dd_read(ibuf, ibs); | 589 | ssize_t n = ibs; |
590 | |||
591 | if (G.flags & FLAG_COUNT) { | ||
592 | if (count == 0) | ||
593 | break; | ||
594 | if ((G.flags & FLAG_COUNT_BYTES) && count < ibs) | ||
595 | n = count; | ||
596 | } | ||
597 | |||
598 | n = dd_read(ibuf, n); | ||
586 | if (n == 0) | 599 | if (n == 0) |
587 | break; | 600 | break; |
588 | if (n < 0) { | 601 | if (n < 0) { |
@@ -617,6 +630,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
617 | p16++; | 630 | p16++; |
618 | } | 631 | } |
619 | } | 632 | } |
633 | count -= (G.flags & FLAG_COUNT_BYTES) ? n : 1; | ||
620 | if ((size_t)n == ibs) | 634 | if ((size_t)n == ibs) |
621 | G.in_full++; | 635 | G.in_full++; |
622 | else { | 636 | else { |