aboutsummaryrefslogtreecommitdiff
path: root/coreutils/df.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/df.c')
-rw-r--r--coreutils/df.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/coreutils/df.c b/coreutils/df.c
index 5e9a8670f..d79c11a6c 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -25,6 +25,7 @@
25//usage:#define df_trivial_usage 25//usage:#define df_trivial_usage
26//usage: "[-Pk" 26//usage: "[-Pk"
27//usage: IF_FEATURE_HUMAN_READABLE("mh") 27//usage: IF_FEATURE_HUMAN_READABLE("mh")
28//usage: "T"
28//usage: IF_FEATURE_DF_FANCY("ai] [-B SIZE") 29//usage: IF_FEATURE_DF_FANCY("ai] [-B SIZE")
29//usage: "] [FILESYSTEM]..." 30//usage: "] [FILESYSTEM]..."
30//usage:#define df_full_usage "\n\n" 31//usage:#define df_full_usage "\n\n"
@@ -35,6 +36,7 @@
35//usage: "\n -m 1M-byte blocks" 36//usage: "\n -m 1M-byte blocks"
36//usage: "\n -h Human readable (e.g. 1K 243M 2G)" 37//usage: "\n -h Human readable (e.g. 1K 243M 2G)"
37//usage: ) 38//usage: )
39//usage: "\n -T Print filesystem type"
38//usage: IF_FEATURE_DF_FANCY( 40//usage: IF_FEATURE_DF_FANCY(
39//usage: "\n -a Show all filesystems" 41//usage: "\n -a Show all filesystems"
40//usage: "\n -i Inodes" 42//usage: "\n -i Inodes"
@@ -83,11 +85,12 @@ int df_main(int argc UNUSED_PARAM, char **argv)
83 enum { 85 enum {
84 OPT_KILO = (1 << 0), 86 OPT_KILO = (1 << 0),
85 OPT_POSIX = (1 << 1), 87 OPT_POSIX = (1 << 1),
86 OPT_ALL = (1 << 2) * ENABLE_FEATURE_DF_FANCY, 88 OPT_FSTYPE = (1 << 2),
87 OPT_INODE = (1 << 3) * ENABLE_FEATURE_DF_FANCY, 89 OPT_ALL = (1 << 3) * ENABLE_FEATURE_DF_FANCY,
88 OPT_BSIZE = (1 << 4) * ENABLE_FEATURE_DF_FANCY, 90 OPT_INODE = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
89 OPT_HUMAN = (1 << (2 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE, 91 OPT_BSIZE = (1 << 5) * ENABLE_FEATURE_DF_FANCY,
90 OPT_MEGA = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE, 92 OPT_HUMAN = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
93 OPT_MEGA = (1 << (4 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
91 }; 94 };
92 const char *disp_units_hdr = NULL; 95 const char *disp_units_hdr = NULL;
93 char *chp; 96 char *chp;
@@ -99,7 +102,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
99#elif ENABLE_FEATURE_HUMAN_READABLE 102#elif ENABLE_FEATURE_HUMAN_READABLE
100 opt_complementary = "k-m:m-k"; 103 opt_complementary = "k-m:m-k";
101#endif 104#endif
102 opt = getopt32(argv, "kP" 105 opt = getopt32(argv, "kPT"
103 IF_FEATURE_DF_FANCY("aiB:") 106 IF_FEATURE_DF_FANCY("aiB:")
104 IF_FEATURE_HUMAN_READABLE("hm") 107 IF_FEATURE_HUMAN_READABLE("hm")
105 IF_FEATURE_DF_FANCY(, &chp)); 108 IF_FEATURE_DF_FANCY(, &chp));
@@ -134,8 +137,11 @@ int df_main(int argc UNUSED_PARAM, char **argv)
134 disp_units_hdr = xasprintf("%lu-blocks", df_disp_hr); 137 disp_units_hdr = xasprintf("%lu-blocks", df_disp_hr);
135#endif 138#endif
136 } 139 }
137 printf("Filesystem %-15sUsed Available %s Mounted on\n", 140
138 disp_units_hdr, (opt & OPT_POSIX) ? "Capacity" : "Use%"); 141 printf("Filesystem %s%-15sUsed Available %s Mounted on\n",
142 (opt & OPT_FSTYPE) ? "Type " : "",
143 disp_units_hdr,
144 (opt & OPT_POSIX) ? "Capacity" : "Use%");
139 145
140 mount_table = NULL; 146 mount_table = NULL;
141 argv += optind; 147 argv += optind;
@@ -148,6 +154,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
148 while (1) { 154 while (1) {
149 const char *device; 155 const char *device;
150 const char *mount_point; 156 const char *mount_point;
157 const char *fs_type;
151 158
152 if (mount_table) { 159 if (mount_table) {
153 mount_entry = getmntent(mount_table); 160 mount_entry = getmntent(mount_table);
@@ -170,6 +177,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
170 177
171 device = mount_entry->mnt_fsname; 178 device = mount_entry->mnt_fsname;
172 mount_point = mount_entry->mnt_dir; 179 mount_point = mount_entry->mnt_dir;
180 fs_type = mount_entry->mnt_type;
173 181
174 if (statfs(mount_point, &s) != 0) { 182 if (statfs(mount_point, &s) != 0) {
175 bb_simple_perror_msg(mount_point); 183 bb_simple_perror_msg(mount_point);
@@ -218,10 +226,22 @@ int df_main(int argc UNUSED_PARAM, char **argv)
218 printf("%s%*s", uni_dev, 20 - (int)uni_stat.unicode_width, ""); 226 printf("%s%*s", uni_dev, 20 - (int)uni_stat.unicode_width, "");
219 } 227 }
220 free(uni_dev); 228 free(uni_dev);
229 if (opt & OPT_FSTYPE) {
230 char *uni_type = unicode_conv_to_printable(&uni_stat, fs_type);
231 if (uni_stat.unicode_width > 10 && !(opt & OPT_POSIX))
232 printf(" %s\n%31s", uni_type, "");
233 else
234 printf(" %s%*s", uni_type, 10 - (int)uni_stat.unicode_width, "");
235 free(uni_type);
236 }
221 } 237 }
222#else 238#else
223 if (printf("\n%-20s" + 1, device) > 20 && !(opt & OPT_POSIX)) 239 if (printf("\n%-20s" + 1, device) > 20 && !(opt & OPT_POSIX))
224 printf("\n%-20s", ""); 240 printf("\n%-20s", "");
241 if (opt & OPT_FSTYPE) {
242 if (printf(" %-10s", fs_type) > 11 && !(opt & OPT_POSIX))
243 printf("\n%-30s", "");
244 }
225#endif 245#endif
226 246
227#if ENABLE_FEATURE_HUMAN_READABLE 247#if ENABLE_FEATURE_HUMAN_READABLE