From 2e8be0d4e340b414e6fd3995ec99ec50e69cd373 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 28 Jun 2022 02:54:48 -0500 Subject: [PATCH] Next round of dd cleanup (mostly hammering on help text). --- toys/pending/dd.c | 78 +++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 46 deletions(-) diff --git a/toys/pending/dd.c b/toys/pending/dd.c index 199e5914..104b4f39 100644 --- a/toys/pending/dd.c +++ b/toys/pending/dd.c @@ -1,9 +1,9 @@ -/* dd.c - program to convert and copy a file. +/* dd.c - convert/copy a file * * Copyright 2013 Ashwini Kumar * Copyright 2013 Kyungwan Han * - * See http://opengroup.org/onlinepubs/9699919799/utilities/dd.html + * See http://opengroup.org/onlinepubs/9699919799/utilities/dd.html USE_DD(NEWTOY(dd, 0, TOYFLAG_USR|TOYFLAG_BIN)) @@ -11,37 +11,28 @@ config DD bool "dd" default n help - usage: dd [if=FILE] [of=FILE] [ibs=N] [obs=N] [iflag=FLAGS] [oflag=FLAGS] - [bs=N] [count=N] [seek=N] [skip=N] - [conv=notrunc|noerror|sync|fsync] [status=noxfer|none] - - Copy/convert files. - - if=FILE Read from FILE instead of stdin - of=FILE Write to FILE instead of stdout - bs=N Read and write N bytes at a time - ibs=N Input block size - obs=N Output block size - count=N Copy only N input blocks - skip=N Skip N input blocks - seek=N Skip N output blocks - iflag=FLAGS Set input flags - oflag=FLAGS Set output flags - conv=notrunc Don't truncate output file - conv=noerror Continue after read errors - conv=sync Pad blocks with zeros - conv=fsync Physically write data out before finishing - status=noxfer Don't show transfer rate - status=none Don't show transfer rate or records in/out - - FLAGS is a comma-separated list of: - - count_bytes (iflag) interpret count=N in bytes, not blocks - seek_bytes (oflag) interpret seek=N in bytes, not blocks - skip_bytes (iflag) interpret skip=N in bytes, not blocks - - Numbers may be suffixed by c (*1), w (*2), b (*512), kD (*1000), k (*1024), - MD (*1000*1000), M (*1024*1024), GD (*1000*1000*1000) or G (*1024*1024*1024). + usage: dd [if|of=FILE] [ibs|obs|bs|count|seek|skip=N] [conv|status|iflag|oflag=FLAG[,FLAG...]] + + Copy/convert blocks of data from input to output, with the following + keyword=value modifiers (and their default values): + + if=FILE Read FILE (stdin) of=FILE Write to FILE (stdout) + bs=N Block size in bytes (512) count=N Stop after copying N blocks + ibs=N Input block size (bs=) obs=N Output block size (bs=) + skip=N Skip N input blocks (0) seek=N Skip N output blocks (0) + + Each =N value accepts the normal unit suffixes (see toybox --help). + + These modifiers take a comma separated list of potential options: + + iflag=count_bytes,skip_bytes count=N or skip=N is in bytes not blocks + oflag=seek_bytes,append seek=N is in bytes, append output to file + status=noxfer,none don't show transfer rate, no summary info + conv= + notrunc Don't truncate output noerror Continue after read errors + sync Zero pad short reads fsync Flush output to disk at end + sparse Seek past zeroed output excl Fail if output file exists + nocreat Fail if of=FILE missing */ #define FOR_dd @@ -66,7 +57,7 @@ struct dd_flag { }; static const struct dd_flag dd_conv[] = TAGGED_ARRAY(DD_conv, - {"fsync"}, {"noerror"}, {"notrunc"}, {"sync"}, + {"fsync"}, {"noerror"}, {"notrunc"}, {"sync"}, // TODO sparse excl nocreat ); static const struct dd_flag dd_iflag[] = TAGGED_ARRAY(DD_iflag, @@ -128,16 +119,15 @@ static void parse_flags(char *what, char *arg, char *pre = xstrdup(arg); int i; - for (i=0; i