From cb7ba0e640f7226fedaecb6d1289bebabe033a3b Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Tue, 19 Jan 2021 15:15:12 -0800 Subject: dd: error with invalid size suffixes, add 'm' When invoking with dd with an invalid size suffix, we silently accept the suffix. This can lead to confusion, because lines like: dd -bs 1K dd -bs 1m will silently copy in 1-byte increments. This has caught people by surprise. While we're at it, megabytes are convenient, so let's have them too. --- sys/src/cmd/dd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sys/src/cmd/dd.c b/sys/src/cmd/dd.c index ad433d8e1..6f0157bf4 100644 --- a/sys/src/cmd/dd.c +++ b/sys/src/cmd/dd.c @@ -353,7 +353,9 @@ number(vlong big) n = n*10 + *cs++ - '0'; for(;;) switch(*cs++) { - + case 'm': + n *= 1024*1024; + continue; case 'k': n *= 1024; continue; @@ -373,6 +375,9 @@ number(vlong big) exits("range"); } return n; + default: + fprint(2, "dd: invalid size suffix '%c'\n", cs[-1]); + exits("invalid"); } /* never gets here */ } -- cgit v1.2.3