diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-12-12 19:56:31 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-12-12 19:56:31 +0100 |
commit | e184a883567ee3fd735644416e4bd683f1894ac5 (patch) | |
tree | 7eae83fb609ecc41c44803e5969db5b1bb726f10 | |
parent | 76de3257f7133a760c3d8908a99b850ea2d0f0b0 (diff) | |
download | busybox-w32-e184a883567ee3fd735644416e4bd683f1894ac5.tar.gz busybox-w32-e184a883567ee3fd735644416e4bd683f1894ac5.tar.bz2 busybox-w32-e184a883567ee3fd735644416e4bd683f1894ac5.zip |
df: implement -B n<suff> and -B <suff> formats of -B option
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/df.c | 20 | ||||
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | libbb/xatonum.c | 19 | ||||
-rw-r--r-- | util-linux/fstrim.c | 25 |
4 files changed, 41 insertions, 24 deletions
diff --git a/coreutils/df.c b/coreutils/df.c index fdcdae675..79e4c4670 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -129,8 +129,19 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
129 | if (opt & OPT_MEGA) | 129 | if (opt & OPT_MEGA) |
130 | df_disp_hr = 1024*1024; | 130 | df_disp_hr = 1024*1024; |
131 | 131 | ||
132 | if (opt & OPT_BSIZE) | 132 | if (opt & OPT_BSIZE) { |
133 | df_disp_hr = xatoul_range(chp, 1, ULONG_MAX); /* disallow 0 */ | 133 | /* GNU coreutils 8.25 accepts "-BMiB" form too */ |
134 | int i; | ||
135 | for (i = 0; kmg_i_suffixes[i].suffix[0]; i++) { | ||
136 | if (strcmp(kmg_i_suffixes[i].suffix, chp) == 0) { | ||
137 | df_disp_hr = kmg_i_suffixes[i].mult; | ||
138 | goto got_it; | ||
139 | } | ||
140 | } | ||
141 | /* Range used to disallow 0 */ | ||
142 | df_disp_hr = xatoul_range_sfx(chp, 1, ULONG_MAX, kmg_i_suffixes); | ||
143 | got_it: ; | ||
144 | } | ||
134 | 145 | ||
135 | /* From the manpage of df from coreutils-6.10: | 146 | /* From the manpage of df from coreutils-6.10: |
136 | * Disk space is shown in 1K blocks by default, unless the environment | 147 | * Disk space is shown in 1K blocks by default, unless the environment |
@@ -203,6 +214,11 @@ int df_main(int argc UNUSED_PARAM, char **argv) | |||
203 | bb_simple_perror_msg(mount_point); | 214 | bb_simple_perror_msg(mount_point); |
204 | goto set_error; | 215 | goto set_error; |
205 | } | 216 | } |
217 | /* Some uclibc versions were seen to lose f_frsize | ||
218 | * (kernel does return it, but then uclibc does not copy it) | ||
219 | */ | ||
220 | if (s.f_frsize == 0) | ||
221 | s.f_frsize = s.f_bsize; | ||
206 | 222 | ||
207 | if ((s.f_blocks > 0) || !mount_table || (opt & OPT_ALL)) { | 223 | if ((s.f_blocks > 0) || !mount_table || (opt & OPT_ALL)) { |
208 | if (opt & OPT_INODE) { | 224 | if (opt & OPT_INODE) { |
diff --git a/include/libbb.h b/include/libbb.h index b1fec0157..abdc8c2b8 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -923,6 +923,7 @@ extern const struct suffix_mult bkm_suffixes[]; | |||
923 | #define km_suffixes (bkm_suffixes + 1) | 923 | #define km_suffixes (bkm_suffixes + 1) |
924 | extern const struct suffix_mult cwbkMG_suffixes[]; | 924 | extern const struct suffix_mult cwbkMG_suffixes[]; |
925 | #define kMG_suffixes (cwbkMG_suffixes + 3) | 925 | #define kMG_suffixes (cwbkMG_suffixes + 3) |
926 | extern const struct suffix_mult kmg_i_suffixes[]; | ||
926 | 927 | ||
927 | #include "xatonum.h" | 928 | #include "xatonum.h" |
928 | /* Specialized: */ | 929 | /* Specialized: */ |
diff --git a/libbb/xatonum.c b/libbb/xatonum.c index 9dd5c3e7e..b63b7f54d 100644 --- a/libbb/xatonum.c +++ b/libbb/xatonum.c | |||
@@ -96,3 +96,22 @@ const struct suffix_mult cwbkMG_suffixes[] = { | |||
96 | /* coreutils also understands TPEZY suffixes for tera- and so on, with B suffix for decimal */ | 96 | /* coreutils also understands TPEZY suffixes for tera- and so on, with B suffix for decimal */ |
97 | { "", 0 } | 97 | { "", 0 } |
98 | }; | 98 | }; |
99 | |||
100 | const struct suffix_mult kmg_i_suffixes[] = { | ||
101 | { "KiB", 1024 }, | ||
102 | { "kiB", 1024 }, | ||
103 | { "K", 1024 }, | ||
104 | { "k", 1024 }, | ||
105 | { "MiB", 1048576 }, | ||
106 | { "miB", 1048576 }, | ||
107 | { "M", 1048576 }, | ||
108 | { "m", 1048576 }, | ||
109 | { "GiB", 1073741824 }, | ||
110 | { "giB", 1073741824 }, | ||
111 | { "G", 1073741824 }, | ||
112 | { "g", 1073741824 }, | ||
113 | { "KB", 1000 }, | ||
114 | { "MB", 1000000 }, | ||
115 | { "GB", 1000000000 }, | ||
116 | { "", 0 } | ||
117 | }; | ||
diff --git a/util-linux/fstrim.c b/util-linux/fstrim.c index 51400ef0b..fc51878b6 100644 --- a/util-linux/fstrim.c +++ b/util-linux/fstrim.c | |||
@@ -47,25 +47,6 @@ struct fstrim_range { | |||
47 | #define FITRIM _IOWR('X', 121, struct fstrim_range) | 47 | #define FITRIM _IOWR('X', 121, struct fstrim_range) |
48 | #endif | 48 | #endif |
49 | 49 | ||
50 | static const struct suffix_mult fstrim_sfx[] = { | ||
51 | { "KiB", 1024 }, | ||
52 | { "kiB", 1024 }, | ||
53 | { "K", 1024 }, | ||
54 | { "k", 1024 }, | ||
55 | { "MiB", 1048576 }, | ||
56 | { "miB", 1048576 }, | ||
57 | { "M", 1048576 }, | ||
58 | { "m", 1048576 }, | ||
59 | { "GiB", 1073741824 }, | ||
60 | { "giB", 1073741824 }, | ||
61 | { "G", 1073741824 }, | ||
62 | { "g", 1073741824 }, | ||
63 | { "KB", 1000 }, | ||
64 | { "MB", 1000000 }, | ||
65 | { "GB", 1000000000 }, | ||
66 | { "", 0 } | ||
67 | }; | ||
68 | |||
69 | int fstrim_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 50 | int fstrim_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
70 | int fstrim_main(int argc UNUSED_PARAM, char **argv) | 51 | int fstrim_main(int argc UNUSED_PARAM, char **argv) |
71 | { | 52 | { |
@@ -98,11 +79,11 @@ int fstrim_main(int argc UNUSED_PARAM, char **argv) | |||
98 | range.len = ULLONG_MAX; | 79 | range.len = ULLONG_MAX; |
99 | 80 | ||
100 | if (opts & OPT_o) | 81 | if (opts & OPT_o) |
101 | range.start = xatoull_sfx(arg_o, fstrim_sfx); | 82 | range.start = xatoull_sfx(arg_o, kmg_i_suffixes); |
102 | if (opts & OPT_l) | 83 | if (opts & OPT_l) |
103 | range.len = xatoull_sfx(arg_l, fstrim_sfx); | 84 | range.len = xatoull_sfx(arg_l, kmg_i_suffixes); |
104 | if (opts & OPT_m) | 85 | if (opts & OPT_m) |
105 | range.minlen = xatoull_sfx(arg_m, fstrim_sfx); | 86 | range.minlen = xatoull_sfx(arg_m, kmg_i_suffixes); |
106 | 87 | ||
107 | mp = argv[optind]; | 88 | mp = argv[optind]; |
108 | if (find_block_device(mp)) { | 89 | if (find_block_device(mp)) { |