aboutsummaryrefslogtreecommitdiff
path: root/coreutils/dd.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-02-13 09:44:44 +0000
committerRon Yorston <rmy@pobox.com>2018-02-13 09:44:44 +0000
commitdc19a361bd6c6df30338371532691bbc7f7126bb (patch)
tree1fb2cd646d54b5f8e425c4f11f3e09fc21d1966b /coreutils/dd.c
parent096aee2bb468d1ab044de36e176ed1f6c7e3674d (diff)
parent3459024bf404af814cacfe90a0deb719e282ae62 (diff)
downloadbusybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.tar.gz
busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.tar.bz2
busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils/dd.c')
-rw-r--r--coreutils/dd.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 14d270a1e..178576752 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -37,7 +37,7 @@
37//config: elapsed time and speed. 37//config: elapsed time and speed.
38//config: 38//config:
39//config:config FEATURE_DD_IBS_OBS 39//config:config FEATURE_DD_IBS_OBS
40//config: bool "Enable ibs, obs and conv options" 40//config: bool "Enable ibs, obs, iflag and conv options"
41//config: default y 41//config: default y
42//config: depends on DD 42//config: depends on DD
43//config: help 43//config: help
@@ -57,7 +57,7 @@
57 57
58//usage:#define dd_trivial_usage 58//usage:#define dd_trivial_usage
59//usage: "[if=FILE] [of=FILE] " IF_FEATURE_DD_IBS_OBS("[ibs=N] [obs=N] ") "[bs=N] [count=N] [skip=N]\n" 59//usage: "[if=FILE] [of=FILE] " IF_FEATURE_DD_IBS_OBS("[ibs=N] [obs=N] ") "[bs=N] [count=N] [skip=N]\n"
60//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync] [iflag=skip_bytes]") 60//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync] [iflag=skip_bytes|fullblock]")
61//usage:#define dd_full_usage "\n\n" 61//usage:#define dd_full_usage "\n\n"
62//usage: "Copy a file with converting and formatting\n" 62//usage: "Copy a file with converting and formatting\n"
63//usage: "\n if=FILE Read from FILE instead of stdin" 63//usage: "\n if=FILE Read from FILE instead of stdin"
@@ -79,6 +79,7 @@
79//usage: "\n conv=fsync Physically write data out before finishing" 79//usage: "\n conv=fsync Physically write data out before finishing"
80//usage: "\n conv=swab Swap every pair of bytes" 80//usage: "\n conv=swab Swap every pair of bytes"
81//usage: "\n iflag=skip_bytes skip=N is in bytes" 81//usage: "\n iflag=skip_bytes skip=N is in bytes"
82//usage: "\n iflag=fullblock Read full blocks"
82//usage: ) 83//usage: )
83//usage: IF_FEATURE_DD_STATUS( 84//usage: IF_FEATURE_DD_STATUS(
84//usage: "\n status=noxfer Suppress rate output" 85//usage: "\n status=noxfer Suppress rate output"
@@ -130,11 +131,12 @@ enum {
130 /* start of input flags */ 131 /* start of input flags */
131 FLAG_IFLAG_SHIFT = 5, 132 FLAG_IFLAG_SHIFT = 5,
132 FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS, 133 FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
134 FLAG_FULLBLOCK = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
133 /* end of input flags */ 135 /* end of input flags */
134 FLAG_TWOBUFS = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS, 136 FLAG_TWOBUFS = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS,
135 FLAG_COUNT = 1 << 7, 137 FLAG_COUNT = 1 << 8,
136 FLAG_STATUS_NONE = 1 << 8, 138 FLAG_STATUS_NONE = 1 << 9,
137 FLAG_STATUS_NOXFER = 1 << 9, 139 FLAG_STATUS_NOXFER = 1 << 10,
138}; 140};
139 141
140static void dd_output_status(int UNUSED_PARAM cur_signal) 142static void dd_output_status(int UNUSED_PARAM cur_signal)
@@ -195,14 +197,18 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
195 ssize_t n = full_write_or_warn(buf, len, filename); 197 ssize_t n = full_write_or_warn(buf, len, filename);
196 if (n < 0) 198 if (n < 0)
197 return 1; 199 return 1;
198 if ((size_t)n == obs)
199 G.out_full++;
200 else if (n) /* > 0 */
201 G.out_part++;
202#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE 200#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
203 G.total_bytes += n; 201 G.total_bytes += n;
204#endif 202#endif
205 return 0; 203 if ((size_t)n == obs) {
204 G.out_full++;
205 return 0;
206 }
207 if ((size_t)n == len) {
208 G.out_part++;
209 return 0;
210 }
211 return 1;
206} 212}
207 213
208#if ENABLE_LFS 214#if ENABLE_LFS
@@ -251,7 +257,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
251 static const char conv_words[] ALIGN1 = 257 static const char conv_words[] ALIGN1 =
252 "notrunc\0""sync\0""noerror\0""fsync\0""swab\0"; 258 "notrunc\0""sync\0""noerror\0""fsync\0""swab\0";
253 static const char iflag_words[] ALIGN1 = 259 static const char iflag_words[] ALIGN1 =
254 "skip_bytes\0"; 260 "skip_bytes\0""fullblock\0";
255#endif 261#endif
256#if ENABLE_FEATURE_DD_STATUS 262#if ENABLE_FEATURE_DD_STATUS
257 static const char status_words[] ALIGN1 = 263 static const char status_words[] ALIGN1 =
@@ -290,6 +296,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
290 /* Partially implemented: */ 296 /* Partially implemented: */
291 //swab swap every pair of input bytes: will abort on non-even reads 297 //swab swap every pair of input bytes: will abort on non-even reads
292 OP_iflag_skip_bytes, 298 OP_iflag_skip_bytes,
299 OP_iflag_fullblock,
293#endif 300#endif
294 }; 301 };
295 smallint exitcode = EXIT_FAILURE; 302 smallint exitcode = EXIT_FAILURE;
@@ -456,7 +463,13 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
456 size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs; 463 size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs;
457 if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) { 464 if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) {
458 do { 465 do {
459 ssize_t n = safe_read(ifd, ibuf, blocksz); 466 ssize_t n;
467#if ENABLE_FEATURE_DD_IBS_OBS
468 if (G.flags & FLAG_FULLBLOCK)
469 n = full_read(ifd, ibuf, blocksz);
470 else
471#endif
472 n = safe_read(ifd, ibuf, blocksz);
460 if (n < 0) 473 if (n < 0)
461 goto die_infile; 474 goto die_infile;
462 if (n == 0) 475 if (n == 0)
@@ -477,6 +490,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
477 n = ibs; 490 n = ibs;
478 } 491 }
479 else 492 else
493#if ENABLE_FEATURE_DD_IBS_OBS
494 if (G.flags & FLAG_FULLBLOCK)
495 n = full_read(ifd, ibuf, ibs);
496 else
497#endif
480 n = safe_read(ifd, ibuf, ibs); 498 n = safe_read(ifd, ibuf, ibs);
481 if (n == 0) 499 if (n == 0)
482 break; 500 break;