diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-20 13:08:50 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-20 13:08:50 +0200 |
| commit | ec3170ac9578d4a42423e5a966a8ba668df68337 (patch) | |
| tree | 33c96188abf62b845fdfea797b720a2aa8b5140a | |
| parent | 83dff7f43154cd41e4d2e5831060a2d2ddc6596e (diff) | |
| download | busybox-w32-ec3170ac9578d4a42423e5a966a8ba668df68337.tar.gz busybox-w32-ec3170ac9578d4a42423e5a966a8ba668df68337.tar.bz2 busybox-w32-ec3170ac9578d4a42423e5a966a8ba668df68337.zip | |
shred: implement -s SIZE
function old new delta
shred_main 337 391 +54
.rodata 103393 103395 +2
packed_usage 33666 33656 -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 56/-10) Total: 46 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | coreutils/shred.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/coreutils/shred.c b/coreutils/shred.c index 69fb3e8cc..4b95d197c 100644 --- a/coreutils/shred.c +++ b/coreutils/shred.c | |||
| @@ -15,14 +15,15 @@ | |||
| 15 | //kbuild:lib-$(CONFIG_SHRED) += shred.o | 15 | //kbuild:lib-$(CONFIG_SHRED) += shred.o |
| 16 | 16 | ||
| 17 | //usage:#define shred_trivial_usage | 17 | //usage:#define shred_trivial_usage |
| 18 | //usage: "[-fuz] [-n N] FILE..." | 18 | //usage: "[-fuz] [-n N] [-s SIZE] FILE..." |
| 19 | //usage:#define shred_full_usage "\n\n" | 19 | //usage:#define shred_full_usage "\n\n" |
| 20 | //usage: "Overwrite/delete FILEs\n" | 20 | //usage: "Overwrite/delete FILEs\n" |
| 21 | //usage: "\n -f Chmod to ensure writability" | 21 | //usage: "\n -f Chmod to ensure writability" |
| 22 | //usage: "\n -s SIZE Size to write" | ||
| 22 | //usage: "\n -n N Overwrite N times (default 3)" | 23 | //usage: "\n -n N Overwrite N times (default 3)" |
| 23 | //usage: "\n -z Final overwrite with zeros" | 24 | //usage: "\n -z Final overwrite with zeros" |
| 24 | //usage: "\n -u Remove file" | 25 | //usage: "\n -u Remove file" |
| 25 | //-x and -v are accepted but have no effect | 26 | //-x (exact: don't round up to 4k) and -v (verbose) are accepted but have no effect |
| 26 | 27 | ||
| 27 | /* shred (GNU coreutils) 8.25: | 28 | /* shred (GNU coreutils) 8.25: |
| 28 | -f, --force change permissions to allow writing if necessary | 29 | -f, --force change permissions to allow writing if necessary |
| @@ -41,6 +42,7 @@ | |||
| 41 | int shred_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 42 | int shred_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 42 | int shred_main(int argc UNUSED_PARAM, char **argv) | 43 | int shred_main(int argc UNUSED_PARAM, char **argv) |
| 43 | { | 44 | { |
| 45 | char *opt_s; | ||
| 44 | int rand_fd = rand_fd; /* for compiler */ | 46 | int rand_fd = rand_fd; /* for compiler */ |
| 45 | int zero_fd; | 47 | int zero_fd; |
| 46 | unsigned num_iter = 3; | 48 | unsigned num_iter = 3; |
| @@ -52,9 +54,10 @@ int shred_main(int argc UNUSED_PARAM, char **argv) | |||
| 52 | OPT_n = (1 << 3), | 54 | OPT_n = (1 << 3), |
| 53 | OPT_v = (1 << 4), | 55 | OPT_v = (1 << 4), |
| 54 | OPT_x = (1 << 5), | 56 | OPT_x = (1 << 5), |
| 57 | OPT_s = (1 << 6), | ||
| 55 | }; | 58 | }; |
| 56 | 59 | ||
| 57 | opt = getopt32(argv, "^" "fuzn:+vx" "\0" "-1"/*min 1 arg*/, &num_iter); | 60 | opt = getopt32(argv, "^" "fuzn:+vxs:" "\0" "-1"/*min 1 arg*/, &num_iter, &opt_s); |
| 58 | argv += optind; | 61 | argv += optind; |
| 59 | 62 | ||
| 60 | zero_fd = xopen("/dev/zero", O_RDONLY); | 63 | zero_fd = xopen("/dev/zero", O_RDONLY); |
| @@ -82,6 +85,11 @@ int shred_main(int argc UNUSED_PARAM, char **argv) | |||
| 82 | if (fstat(fd, &sb) == 0 && sb.st_size > 0) { | 85 | if (fstat(fd, &sb) == 0 && sb.st_size > 0) { |
| 83 | off_t size = sb.st_size; | 86 | off_t size = sb.st_size; |
| 84 | 87 | ||
| 88 | if (opt & OPT_s) { | ||
| 89 | size = BB_STRTOOFF(opt_s, NULL, 0); /* accepts oct/hex */ | ||
| 90 | if (errno || size < 0) bb_show_usage(); | ||
| 91 | } | ||
| 92 | |||
| 85 | for (i = 0; i < num_iter; i++) { | 93 | for (i = 0; i < num_iter; i++) { |
| 86 | bb_copyfd_size(rand_fd, fd, size); | 94 | bb_copyfd_size(rand_fd, fd, size); |
| 87 | fdatasync(fd); | 95 | fdatasync(fd); |
