df: add -i (conditional on CONFIG)
uasge: trim a bit
This commit is contained in:
parent
1fe4e9e573
commit
f430cdbf2e
@ -135,6 +135,13 @@ config DF
|
|||||||
df reports the amount of disk space used and available
|
df reports the amount of disk space used and available
|
||||||
on filesystems.
|
on filesystems.
|
||||||
|
|
||||||
|
config FEATURE_DF_INODE
|
||||||
|
bool "Enable -i (inode information)"
|
||||||
|
default n
|
||||||
|
depends on DF
|
||||||
|
help
|
||||||
|
This option enables support for df -i.
|
||||||
|
|
||||||
config DIRNAME
|
config DIRNAME
|
||||||
bool "dirname"
|
bool "dirname"
|
||||||
default n
|
default n
|
||||||
|
@ -45,9 +45,14 @@ int df_main(int argc, char **argv)
|
|||||||
/* default display is kilobytes */
|
/* default display is kilobytes */
|
||||||
const char *disp_units_hdr = "1k-blocks";
|
const char *disp_units_hdr = "1k-blocks";
|
||||||
|
|
||||||
|
enum {
|
||||||
|
OPT_INODE = (ENABLE_FEATURE_HUMAN_READABLE ? (1 << 3) : (1 << 1))
|
||||||
|
* ENABLE_FEATURE_DF_INODE
|
||||||
|
};
|
||||||
|
|
||||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||||
opt_complementary = "h-km:k-hm:m-hk";
|
opt_complementary = "h-km:k-hm:m-hk";
|
||||||
opt = getopt32(argv, "hmk");
|
opt = getopt32(argv, "hmk" USE_FEATURE_DF_INODE("i"));
|
||||||
if (opt & 1) {
|
if (opt & 1) {
|
||||||
df_disp_hr = 0;
|
df_disp_hr = 0;
|
||||||
disp_units_hdr = " Size";
|
disp_units_hdr = " Size";
|
||||||
@ -56,8 +61,11 @@ int df_main(int argc, char **argv)
|
|||||||
df_disp_hr = 1024*1024;
|
df_disp_hr = 1024*1024;
|
||||||
disp_units_hdr = "1M-blocks";
|
disp_units_hdr = "1M-blocks";
|
||||||
}
|
}
|
||||||
|
if (opt & OPT_INODE) {
|
||||||
|
disp_units_hdr = " Inodes";
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
opt = getopt32(argv, "k");
|
opt = getopt32(argv, "k" USE_FEATURE_DF_INODE("i"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf("Filesystem%11s%-15sUsed Available Use%% Mounted on\n",
|
printf("Filesystem%11s%-15sUsed Available Use%% Mounted on\n",
|
||||||
@ -105,6 +113,15 @@ int df_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((s.f_blocks > 0) || !mount_table) {
|
if ((s.f_blocks > 0) || !mount_table) {
|
||||||
|
if (opt & OPT_INODE) {
|
||||||
|
s.f_blocks = s.f_files;
|
||||||
|
s.f_bavail = s.f_bfree = s.f_ffree;
|
||||||
|
s.f_bsize = 1;
|
||||||
|
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||||
|
if (df_disp_hr)
|
||||||
|
df_disp_hr = 1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
blocks_used = s.f_blocks - s.f_bfree;
|
blocks_used = s.f_blocks - s.f_bfree;
|
||||||
blocks_percent_used = 0;
|
blocks_percent_used = 0;
|
||||||
if (blocks_used + s.f_bavail) {
|
if (blocks_used + s.f_bavail) {
|
||||||
@ -115,7 +132,8 @@ int df_main(int argc, char **argv)
|
|||||||
|
|
||||||
if (strcmp(device, "rootfs") == 0) {
|
if (strcmp(device, "rootfs") == 0) {
|
||||||
continue;
|
continue;
|
||||||
} else if (strcmp(device, "/dev/root") == 0) {
|
}
|
||||||
|
if (strcmp(device, "/dev/root") == 0) {
|
||||||
/* Adjusts device to be the real root device,
|
/* Adjusts device to be the real root device,
|
||||||
* or leaves device alone if it can't find it */
|
* or leaves device alone if it can't find it */
|
||||||
device = find_block_device("/");
|
device = find_block_device("/");
|
||||||
|
@ -630,18 +630,28 @@
|
|||||||
"\n and processing synthetic REGISTER events," \
|
"\n and processing synthetic REGISTER events," \
|
||||||
"\n do not poll for events")
|
"\n do not poll for events")
|
||||||
|
|
||||||
|
/* -k is accepted but ignored for !HUMAN_READABLE,
|
||||||
|
* but we won't mention this (unimportant) */
|
||||||
|
#if ENABLE_FEATURE_HUMAN_READABLE || ENABLE_FEATURE_DF_INODE
|
||||||
|
#define DF_HAS_OPTIONS(x) x
|
||||||
|
#else
|
||||||
|
#define DF_HAS_OPTIONS(x)
|
||||||
|
#endif
|
||||||
#define df_trivial_usage \
|
#define df_trivial_usage \
|
||||||
"[-" USE_FEATURE_HUMAN_READABLE("hm") "k] [FILESYSTEM ...]"
|
DF_HAS_OPTIONS("[-") \
|
||||||
|
USE_FEATURE_HUMAN_READABLE("hmk") USE_FEATURE_DF_INODE("i") \
|
||||||
|
DF_HAS_OPTIONS("] ") "[FILESYSTEM...]"
|
||||||
#define df_full_usage \
|
#define df_full_usage \
|
||||||
"Print the filesystem space used and space available" \
|
"Print filesystem usage statistics" \
|
||||||
|
DF_HAS_OPTIONS("\n\nOptions:") \
|
||||||
USE_FEATURE_HUMAN_READABLE( \
|
USE_FEATURE_HUMAN_READABLE( \
|
||||||
"\n\nOptions control size display:" \
|
|
||||||
"\n -h Human readable (e.g. 1K 243M 2G)" \
|
"\n -h Human readable (e.g. 1K 243M 2G)" \
|
||||||
"\n -m 1024*1024 blocks" \
|
"\n -m 1024*1024 blocks" \
|
||||||
"\n -k 1024 blocks") \
|
"\n -k 1024 blocks" \
|
||||||
SKIP_FEATURE_HUMAN_READABLE( \
|
) \
|
||||||
"\n\nOptions:" \
|
USE_FEATURE_DF_INODE( \
|
||||||
"\n -k Ignored")
|
"\n -i Inodes" \
|
||||||
|
)
|
||||||
#define df_example_usage \
|
#define df_example_usage \
|
||||||
"$ df\n" \
|
"$ df\n" \
|
||||||
"Filesystem 1k-blocks Used Available Use% Mounted on\n" \
|
"Filesystem 1k-blocks Used Available Use% Mounted on\n" \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user