aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRostislav Skudnov <rostislav@tuxera.com>2018-10-15 10:26:15 +0000
committerDenys Vlasenko <vda.linux@googlemail.com>2018-10-30 16:55:09 +0100
commit3f6a978a0dabe08e9df15b3f9ee2bd3cf8e3c441 (patch)
tree60c1ddc5b1b41b89e70625fab629435465f954aa
parentf3e2838fc4e6bd0713d7ee5a17e752a19870a0f8 (diff)
downloadbusybox-w32-3f6a978a0dabe08e9df15b3f9ee2bd3cf8e3c441.tar.gz
busybox-w32-3f6a978a0dabe08e9df15b3f9ee2bd3cf8e3c441.tar.bz2
busybox-w32-3f6a978a0dabe08e9df15b3f9ee2bd3cf8e3c441.zip
dd: add 'oflag=seek_bytes'
Allow specifying position in the output file in bytes instead of obs-sized blocks, improve compatibility with GNU dd. function old new delta dd_main 1632 1693 +61 packed_usage 33130 33150 +20 static.oflag_words - 12 +12 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/0 up/down: 93/0) Total: 93 bytes Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/dd.c33
-rw-r--r--docs/posix_conformance.txt1
2 files changed, 25 insertions, 9 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 0f130bcad..129637e24 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, iflag and conv options" 40//config: bool "Enable ibs, obs, iflag, oflag 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|fullblock]") 60//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync] [iflag=skip_bytes|fullblock] [oflag=seek_bytes]")
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"
@@ -80,6 +80,7 @@
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: "\n iflag=fullblock Read full blocks"
83//usage: "\n oflag=seek_bytes seek=N is in bytes"
83//usage: ) 84//usage: )
84//usage: IF_FEATURE_DD_STATUS( 85//usage: IF_FEATURE_DD_STATUS(
85//usage: "\n status=noxfer Suppress rate output" 86//usage: "\n status=noxfer Suppress rate output"
@@ -133,10 +134,14 @@ enum {
133 FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS, 134 FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
134 FLAG_FULLBLOCK = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS, 135 FLAG_FULLBLOCK = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
135 /* end of input flags */ 136 /* end of input flags */
136 FLAG_TWOBUFS = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS, 137 /* start of output flags */
137 FLAG_COUNT = 1 << 8, 138 FLAG_OFLAG_SHIFT = 7,
138 FLAG_STATUS_NONE = 1 << 9, 139 FLAG_SEEK_BYTES = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS,
139 FLAG_STATUS_NOXFER = 1 << 10, 140 /* end of output flags */
141 FLAG_TWOBUFS = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS,
142 FLAG_COUNT = 1 << 9,
143 FLAG_STATUS_NONE = 1 << 10,
144 FLAG_STATUS_NOXFER = 1 << 11,
140}; 145};
141 146
142static void dd_output_status(int UNUSED_PARAM cur_signal) 147static void dd_output_status(int UNUSED_PARAM cur_signal)
@@ -250,7 +255,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
250 static const char keywords[] ALIGN1 = 255 static const char keywords[] ALIGN1 =
251 "bs\0""count\0""seek\0""skip\0""if\0""of\0"IF_FEATURE_DD_STATUS("status\0") 256 "bs\0""count\0""seek\0""skip\0""if\0""of\0"IF_FEATURE_DD_STATUS("status\0")
252#if ENABLE_FEATURE_DD_IBS_OBS 257#if ENABLE_FEATURE_DD_IBS_OBS
253 "ibs\0""obs\0""conv\0""iflag\0" 258 "ibs\0""obs\0""conv\0""iflag\0""oflag\0"
254#endif 259#endif
255 ; 260 ;
256#if ENABLE_FEATURE_DD_IBS_OBS 261#if ENABLE_FEATURE_DD_IBS_OBS
@@ -258,6 +263,8 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
258 "notrunc\0""sync\0""noerror\0""fsync\0""swab\0"; 263 "notrunc\0""sync\0""noerror\0""fsync\0""swab\0";
259 static const char iflag_words[] ALIGN1 = 264 static const char iflag_words[] ALIGN1 =
260 "skip_bytes\0""fullblock\0"; 265 "skip_bytes\0""fullblock\0";
266 static const char oflag_words[] ALIGN1 =
267 "seek_bytes\0";
261#endif 268#endif
262#if ENABLE_FEATURE_DD_STATUS 269#if ENABLE_FEATURE_DD_STATUS
263 static const char status_words[] ALIGN1 = 270 static const char status_words[] ALIGN1 =
@@ -276,6 +283,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
276 OP_obs, 283 OP_obs,
277 OP_conv, 284 OP_conv,
278 OP_iflag, 285 OP_iflag,
286 OP_oflag,
279 /* Must be in the same order as FLAG_XXX! */ 287 /* Must be in the same order as FLAG_XXX! */
280 OP_conv_notrunc = 0, 288 OP_conv_notrunc = 0,
281 OP_conv_sync, 289 OP_conv_sync,
@@ -297,6 +305,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
297 //swab swap every pair of input bytes: will abort on non-even reads 305 //swab swap every pair of input bytes: will abort on non-even reads
298 OP_iflag_skip_bytes, 306 OP_iflag_skip_bytes,
299 OP_iflag_fullblock, 307 OP_iflag_fullblock,
308 OP_oflag_seek_bytes,
300#endif 309#endif
301 }; 310 };
302 smallint exitcode = EXIT_FAILURE; 311 smallint exitcode = EXIT_FAILURE;
@@ -368,6 +377,10 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
368 G.flags |= parse_comma_flags(val, iflag_words, "iflag") << FLAG_IFLAG_SHIFT; 377 G.flags |= parse_comma_flags(val, iflag_words, "iflag") << FLAG_IFLAG_SHIFT;
369 /*continue;*/ 378 /*continue;*/
370 } 379 }
380 if (what == OP_oflag) {
381 G.flags |= parse_comma_flags(val, oflag_words, "oflag") << FLAG_OFLAG_SHIFT;
382 /*continue;*/
383 }
371#endif 384#endif
372 if (what == OP_bs) { 385 if (what == OP_bs) {
373 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); 386 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
@@ -439,7 +452,8 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
439 xmove_fd(xopen(outfile, oflag), ofd); 452 xmove_fd(xopen(outfile, oflag), ofd);
440 453
441 if (seek && !(G.flags & FLAG_NOTRUNC)) { 454 if (seek && !(G.flags & FLAG_NOTRUNC)) {
442 if (ftruncate(ofd, seek * obs) < 0) { 455 size_t blocksz = (G.flags & FLAG_SEEK_BYTES) ? 1 : obs;
456 if (ftruncate(ofd, seek * blocksz) < 0) {
443 struct stat st; 457 struct stat st;
444 458
445 if (fstat(ofd, &st) < 0 459 if (fstat(ofd, &st) < 0
@@ -472,7 +486,8 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
472 } 486 }
473 } 487 }
474 if (seek) { 488 if (seek) {
475 if (lseek(ofd, seek * obs, SEEK_CUR) < 0) 489 size_t blocksz = (G.flags & FLAG_SEEK_BYTES) ? 1 : obs;
490 if (lseek(ofd, seek * blocksz, SEEK_CUR) < 0)
476 goto die_outfile; 491 goto die_outfile;
477 } 492 }
478 493
diff --git a/docs/posix_conformance.txt b/docs/posix_conformance.txt
index cdf89b744..0e6f4a317 100644
--- a/docs/posix_conformance.txt
+++ b/docs/posix_conformance.txt
@@ -182,6 +182,7 @@ dd compatibility options:
182 conv=fsync | yes | | 182 conv=fsync | yes | |
183 iflag=skip_bytes| yes | | 183 iflag=skip_bytes| yes | |
184 iflag=fullblock | yes | | 184 iflag=fullblock | yes | |
185 oflag=seek_bytes| yes | |
185 186
186df POSIX options 187df POSIX options
187 option | exists | compliant | remarks 188 option | exists | compliant | remarks