cal: remove lone static data variable. -4 bytes. coreutils
[oweals/busybox.git] / coreutils / df.c
index fba59e791055adc0bf1de5e7a47551de5e5ad3db..9cb328aa3117b36ba4bc5a1bc959633497b39031 100644 (file)
@@ -29,7 +29,7 @@ static unsigned long kscale(unsigned long b, unsigned long bs)
 }
 #endif
 
-int df_main(int argc, char **argv);
+int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int df_main(int argc, char **argv)
 {
        unsigned long blocks_used;
@@ -45,23 +45,32 @@ int df_main(int argc, char **argv)
        /* default display is kilobytes */
        const char *disp_units_hdr = "1k-blocks";
 
+       enum {
+               OPT_ALL = (1 << 0),
+               OPT_INODE = (ENABLE_FEATURE_HUMAN_READABLE ? (1 << 4) : (1 << 2))
+                           * ENABLE_FEATURE_DF_INODE
+       };
+
 #if ENABLE_FEATURE_HUMAN_READABLE
        opt_complementary = "h-km:k-hm:m-hk";
-       opt = getopt32(argc, argv, "hmk");
-       if (opt & 1) {
+       opt = getopt32(argv, "ahmk" USE_FEATURE_DF_INODE("i"));
+       if (opt & (1 << 1)) { // -h
                df_disp_hr = 0;
                disp_units_hdr = "     Size";
        }
-       if (opt & 2) {
+       if (opt & (1 << 2)) { // -m
                df_disp_hr = 1024*1024;
                disp_units_hdr = "1M-blocks";
        }
+       if (opt & OPT_INODE) {
+               disp_units_hdr = "   Inodes";
+       }
 #else
-       opt = getopt32(argc, argv, "k");
+       opt = getopt32(argv, "ak" USE_FEATURE_DF_INODE("i"));
 #endif
 
-       printf("Filesystem%11s%-15sUsed Available Use%% Mounted on\n",
-                         "", disp_units_hdr);
+       printf("Filesystem           %-15sUsed Available Use%% Mounted on\n",
+                       disp_units_hdr);
 
        mount_table = NULL;
        argv += optind;
@@ -100,11 +109,20 @@ int df_main(int argc, char **argv)
                mount_point = mount_entry->mnt_dir;
 
                if (statfs(mount_point, &s) != 0) {
-                       bb_perror_msg("%s", mount_point);
+                       bb_simple_perror_msg(mount_point);
                        goto SET_ERROR;
                }
 
-               if ((s.f_blocks > 0) || !mount_table){
+               if ((s.f_blocks > 0) || !mount_table || (opt & OPT_ALL)) {
+                       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_percent_used = 0;
                        if (blocks_used + s.f_bavail) {
@@ -113,9 +131,14 @@ int df_main(int argc, char **argv)
                                                ) / (blocks_used + s.f_bavail);
                        }
 
+#ifdef WHY_IT_SHOULD_BE_HIDDEN
                        if (strcmp(device, "rootfs") == 0) {
                                continue;
-                       } else if (strcmp(device, "/dev/root") == 0) {
+                       }
+#endif
+#ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY
+/* ... and also this is the only user of find_block_device */
+                       if (strcmp(device, "/dev/root") == 0) {
                                /* Adjusts device to be the real root device,
                                * or leaves device alone if it can't find it */
                                device = find_block_device("/");
@@ -123,6 +146,7 @@ int df_main(int argc, char **argv)
                                        goto SET_ERROR;
                                }
                        }
+#endif
 
                        if (printf("\n%-20s" + 1, device) > 20)
                                    printf("\n%-20s", "");