bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

df patch: show inode usage and block usage at once


From: Andrew Klyachkin
Subject: df patch: show inode usage and block usage at once
Date: Fri, 22 Jul 2005 23:32:33 +0400
User-agent: KMail/1.8

The following patch adds `-I' option to df. With this option df produces 
output similar to BSD's `df -i' - block usage and inode usage at once.

diff -p -u -r coreutils/doc/coreutils.texi 
coreutils.andrewk/doc/coreutils.texi
--- coreutils/doc/coreutils.texi        2005-07-19 11:34:26.000000000 +0400
+++ coreutils.andrewk/doc/coreutils.texi        2005-07-22 22:55:41.706062480 
+0400
@@ -8744,6 +8744,14 @@ List inode usage information instead of 
 for index node) contains information about a file such as its owner,
 permissions, timestamps, and location on the disk.
 
address@hidden -o
address@hidden --with-inodes
address@hidden -i
address@hidden --with-inodes
address@hidden inode usage
+List inode usage information with block usage information.
+This option produces output like df -i in FreeBSD.
+
 @item -k
 @opindex -k
 @cindex kibibytes for file system sizes
diff -p -u -r coreutils/src/df.c coreutils.andrewk/src/df.c
--- coreutils/src/df.c  2005-06-02 09:12:59.000000000 +0400
+++ coreutils.andrewk/src/df.c  2005-07-22 22:42:13.889869208 +0400
@@ -49,6 +49,9 @@ char *program_name;
 /* If true, show inode information. */
 static bool inode_format;
 
+/* If true, show only inode information. */
+static bool inode_only_format;
+
 /* If true, show even file systems with zero size or
    uninteresting types. */
 static bool show_all_fs;
@@ -123,6 +126,7 @@ static struct option const long_options[
   {"all", no_argument, NULL, 'a'},
   {"block-size", required_argument, NULL, 'B'},
   {"inodes", no_argument, NULL, 'i'},
+  {"with-inodes", no_argument, NULL, 'I'},
   {"human-readable", no_argument, NULL, 'h'},
   {"si", no_argument, NULL, 'H'},
   {"kilobytes", no_argument, NULL, 'k'}, /* long form is obsolescent */
@@ -149,7 +153,7 @@ print_header (void)
   else
     fputs (_("Filesystem        "), stdout);
 
-  if (inode_format)
+  if (inode_only_format)
     printf (_("    Inodes   IUsed   IFree IUse%%"));
   else if (human_output_opts & human_autoscale)
     {
@@ -194,6 +198,18 @@ print_header (void)
              human_readable (output_block_size, buf, opts, 1, 1));
     }
 
+  if (inode_format && !inode_only_format) {
+      if (posix_format)
+          printf(_("    Inodes     IUsed     IFree    IUse%%"));
+      else if (human_output_opts)
+          if (human_output_opts & human_base_1024)
+              printf(_(" Inods IUsed IFree IUs%%"));
+          else
+              printf(_("  Inods  IUsed  IFree IUs%%"));
+      else
+          printf(_("    Inodes     IUsed     IFree IUse%%"));
+  }
+
   printf (_(" Mounted on\n"));
 }
 
@@ -271,8 +287,14 @@ show_dev (const char *disk, const char *
   uintmax_t output_units;
   uintmax_t total;
   uintmax_t available;
+  uintmax_t input_inodes;
+  uintmax_t output_inodes;
+  uintmax_t total_inodes;
+  uintmax_t avail_inodes;
   bool negate_available;
+  bool negate_avail_inodes;
   uintmax_t available_to_root;
+  uintmax_t avail_to_root_inodes;
   uintmax_t used;
   bool negate_used;
   double pct = -1;
@@ -328,7 +350,7 @@ show_dev (const char *disk, const char *
        printf ("%-20s", disk);
     }
 
-  if (inode_format)
+  if (inode_only_format)
     {
       width = 7;
       use_width = 5;
@@ -340,6 +362,13 @@ show_dev (const char *disk, const char *
     }
   else
     {
+      if (inode_format) {
+          input_inodes = output_inodes = 1;
+          total_inodes = fsu.fsu_files;
+          avail_inodes = fsu.fsu_ffree;
+          negate_avail_inodes = false;
+          avail_to_root_inodes = avail_inodes;
+      }
       width = (human_output_opts & human_autoscale
               ? 5 + ! (human_output_opts & human_base_1024)
               : 9);
@@ -412,6 +441,51 @@ show_dev (const char *disk, const char *
   else
     printf ("%*s", use_width, "- ");
 
+  if (inode_format && !inode_only_format) {
+      used = -1;
+      negate_used = false;
+      if (total_inodes != UINTMAX_MAX && avail_to_root_inodes != UINTMAX_MAX) 
{
+          used = total_inodes - avail_to_root_inodes;
+          if (total_inodes < avail_to_root_inodes) {
+              negate_used = true;
+              used = -used;
+          }
+      }
+      printf(" %*s %*s %*s ",
+              width, df_readable(0, total_inodes,
+                  buf[0], input_inodes, output_inodes),
+              width, df_readable(negate_used, used,
+                  buf[1], input_inodes, output_inodes),
+              width, df_readable(negate_avail_inodes, avail_inodes,
+                  buf[2], input_inodes, output_inodes));
+
+      if (used == UINTMAX_MAX || avail_inodes == UINTMAX_MAX)
+          ;
+      else if (!negate_used
+              && used <= TYPE_MAXIMUM (uintmax_t) / 100
+              && used + avail_inodes != 0
+              && (used + avail_inodes < used) == negate_avail_inodes) {
+          uintmax_t u100 = used * 100;
+          uintmax_t nonroot_total = used + avail_inodes;
+          pct = u100 / nonroot_total + (u100 % nonroot_total != 0);
+      } else {
+          double u = negate_used ? - (double) - used : used;
+          double a = negate_avail_inodes ? - (double) - avail_inodes : 
avail_inodes;
+          double nonroot_total = u + a;
+          if (nonroot_total) {
+              long int lipct = pct = u * 100 / nonroot_total;
+              double ipct = lipct;
+              if (ipct - 1 < pct && pct <= ipct + 1)
+                  pct = ipct + (ipct < pct);
+          } else
+              pct = -1;
+      }
+      if (0 <= pct)
+          printf("%*.0f%%", use_width - 1, pct);
+      else
+          printf("%*s", use_width, "- ");
+  }
+
   if (mount_point)
     {
 #ifdef HIDE_AUTOMOUNT_PREFIX
@@ -723,6 +797,7 @@ Mandatory arguments to long options are 
 "), stdout);
       fputs (_("\
   -i, --inodes          list inode information instead of block usage\n\
+  -I, --with-inodes     list inode information with block usage\n\
   -k                    like --block-size=1K\n\
   -l, --local           limit listing to local file systems\n\
       --no-sync         do not invoke sync before getting usage info 
(default)\n\
@@ -774,7 +849,7 @@ main (int argc, char **argv)
   posix_format = false;
   exit_status = EXIT_SUCCESS;
 
-  while ((c = getopt_long (argc, argv, "aB:iF:hHklmPTt:vx:", long_options, 
NULL))
+  while ((c = getopt_long (argc, argv, "aB:iIF:hHklmPTt:vx:", long_options, 
NULL))
         != -1)
     {
       switch (c)
@@ -786,8 +861,11 @@ main (int argc, char **argv)
          human_output_opts = human_options (optarg, true, &output_block_size);
          break;
        case 'i':
-         inode_format = true;
+         inode_only_format = true;
          break;
+    case 'I':
+      inode_format = true;
+      break;
        case 'h':
          human_output_opts = human_autoscale | human_SI | human_base_1024;
          output_block_size = 1;



-- 
Sincerely yours,
Andrew Klyachkin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]