df: match coreutils behavior of wrapping lines if filesystem name is too long.
df: trim help text
This commit is contained in:
parent
319f8ebef8
commit
08294dbf5b
@ -23,19 +23,19 @@
|
||||
#include "libbb.h"
|
||||
|
||||
#if !ENABLE_FEATURE_HUMAN_READABLE
|
||||
static long kscale(long b, long bs)
|
||||
static unsigned long kscale(unsigned long b, unsigned long bs)
|
||||
{
|
||||
return ( b * (long long) bs + 1024/2 ) / 1024;
|
||||
return (b * (unsigned long long) bs + 1024/2) / 1024;
|
||||
}
|
||||
#endif
|
||||
|
||||
int df_main(int argc, char **argv);
|
||||
int df_main(int argc, char **argv)
|
||||
{
|
||||
long blocks_used;
|
||||
long blocks_percent_used;
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
unsigned long df_disp_hr = 1024;
|
||||
unsigned long blocks_used;
|
||||
unsigned blocks_percent_used;
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
unsigned df_disp_hr = 1024;
|
||||
#endif
|
||||
int status = EXIT_SUCCESS;
|
||||
unsigned opt;
|
||||
@ -43,10 +43,9 @@ int df_main(int argc, char **argv)
|
||||
struct mntent *mount_entry;
|
||||
struct statfs s;
|
||||
/* default display is kilobytes */
|
||||
static const char hdr_1k[] ALIGN1 = "1k-blocks";
|
||||
const char *disp_units_hdr = hdr_1k;
|
||||
const char *disp_units_hdr = "1k-blocks";
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
opt_complementary = "h-km:k-hm:m-hk";
|
||||
opt = getopt32(argc, argv, "hmk");
|
||||
if (opt & 1) {
|
||||
@ -73,7 +72,7 @@ int df_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
while (1) {
|
||||
const char *device;
|
||||
const char *mount_point;
|
||||
|
||||
@ -109,7 +108,7 @@ int df_main(int argc, char **argv)
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = 0;
|
||||
if (blocks_used + s.f_bavail) {
|
||||
blocks_percent_used = (((long long) blocks_used) * 100
|
||||
blocks_percent_used = (blocks_used * 100ULL
|
||||
+ (blocks_used + s.f_bavail)/2
|
||||
) / (blocks_used + s.f_bavail);
|
||||
}
|
||||
@ -125,28 +124,28 @@ int df_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (printf("\n%-20s" + 1, device) > 20)
|
||||
printf("\n%-20s", "");
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
printf("%-20s %9s ", device,
|
||||
printf(" %9s ",
|
||||
make_human_readable_str(s.f_blocks, s.f_bsize, df_disp_hr));
|
||||
|
||||
printf("%9s ",
|
||||
make_human_readable_str( (s.f_blocks - s.f_bfree),
|
||||
printf(" %9s " + 1,
|
||||
make_human_readable_str((s.f_blocks - s.f_bfree),
|
||||
s.f_bsize, df_disp_hr));
|
||||
|
||||
printf("%9s %3ld%% %s\n",
|
||||
make_human_readable_str(s.f_bavail, s.f_bsize, df_disp_hr),
|
||||
blocks_percent_used, mount_point);
|
||||
printf("%9s %3u%% %s\n",
|
||||
make_human_readable_str(s.f_bavail, s.f_bsize, df_disp_hr),
|
||||
blocks_percent_used, mount_point);
|
||||
#else
|
||||
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
||||
device,
|
||||
kscale(s.f_blocks, s.f_bsize),
|
||||
kscale(s.f_blocks-s.f_bfree, s.f_bsize),
|
||||
kscale(s.f_bavail, s.f_bsize),
|
||||
blocks_percent_used, mount_point);
|
||||
printf(" %9lu %9lu %9lu %3u%% %s\n",
|
||||
kscale(s.f_blocks, s.f_bsize),
|
||||
kscale(s.f_blocks-s.f_bfree, s.f_bsize),
|
||||
kscale(s.f_bavail, s.f_bsize),
|
||||
blocks_percent_used, mount_point);
|
||||
#endif
|
||||
}
|
||||
|
||||
} while (1);
|
||||
}
|
||||
|
||||
fflush_stdout_and_exit(status);
|
||||
}
|
||||
|
@ -607,12 +607,13 @@
|
||||
"[-" USE_FEATURE_HUMAN_READABLE("hm") "k] [FILESYSTEM ...]"
|
||||
#define df_full_usage \
|
||||
"Print the filesystem space used and space available" \
|
||||
"\n\nOptions:\n" \
|
||||
USE_FEATURE_HUMAN_READABLE( \
|
||||
"\n -h Print sizes in human readable format (e.g., 1K 243M 2G )\n" \
|
||||
" -m Print sizes in megabytes\n" \
|
||||
" -k Print sizes in kilobytes(default)") \
|
||||
"\n\nOptions control size display:" \
|
||||
"\n -h Human readable (e.g. 1K 243M 2G)" \
|
||||
"\n -m 1024*1024 blocks" \
|
||||
"\n -k 1024 blocks") \
|
||||
SKIP_FEATURE_HUMAN_READABLE( \
|
||||
"\n\nOptions:" \
|
||||
"\n -k Ignored")
|
||||
#define df_example_usage \
|
||||
"$ df\n" \
|
||||
|
Loading…
Reference in New Issue
Block a user