*** df.c	Tue Aug  8 02:56:15 2000
--- df.c.new	Tue Aug  8 03:01:27 2000
***************
*** 80,85 ****
--- 80,91 ----
     SunOs4.1.3, for one.  It is *not* necessary on Linux.  */
  static int require_sync = 0;
  
+ /* If 1, compute totals.  If 2, display totals. */
+ static int do_totals = 0;
+ static int total_total = 0;
+ static int total_available = 0;
+ static int total_used = 0;
+ 
  /* Nonzero if errors have occurred. */
  static int exit_status;
  
***************
*** 121,127 ****
  {
    SYNC_OPTION = CHAR_MAX + 1,
    NO_SYNC_OPTION,
!   BLOCK_SIZE_OPTION
  };
  
  static struct option const long_options[] =
--- 127,134 ----
  {
    SYNC_OPTION = CHAR_MAX + 1,
    NO_SYNC_OPTION,
!   BLOCK_SIZE_OPTION,
!   TOTALS_OPTION
  };
  
  static struct option const long_options[] =
***************
*** 140,145 ****
--- 147,153 ----
    {"no-sync", no_argument, NULL, NO_SYNC_OPTION},
    {"type", required_argument, NULL, 't'},
    {"exclude-type", required_argument, NULL, 'x'},
+   {"totals", no_argument, NULL, TOTALS_OPTION},
    {GETOPT_HELP_OPTION_DECL},
    {GETOPT_VERSION_OPTION_DECL},
    {NULL, 0, NULL, 0}
***************
*** 297,316 ****
    if (!selected_fstype (fstype) || excluded_fstype (fstype))
      return;
  
    /* If MOUNT_POINT is NULL, then the filesystem is not mounted, and this
       program reports on the filesystem that the special file is on.
       It would be better to report on the unmounted filesystem,
       but statfs doesn't do that on most systems.  */
    stat_file = mount_point ? decode_name((char *) mount_point) : disk;
  
!   if (get_fs_usage (stat_file, disk, &fsu))
      {
        error (0, errno, "%s", stat_file);
        exit_status = 1;
        return;
      }
  
!   if (fsu.fsu_blocks == 0 && !show_all_fs && !show_listed_fs)
      return;
  
    if (! disk)
--- 305,326 ----
    if (!selected_fstype (fstype) || excluded_fstype (fstype))
      return;
  
+   if (strcmp(disk, "Total") == 0 && do_totals) do_totals = 2;
+ 
    /* If MOUNT_POINT is NULL, then the filesystem is not mounted, and this
       program reports on the filesystem that the special file is on.
       It would be better to report on the unmounted filesystem,
       but statfs doesn't do that on most systems.  */
    stat_file = mount_point ? decode_name((char *) mount_point) : disk;
  
!   if (do_totals != 2 && get_fs_usage (stat_file, disk, &fsu))
      {
        error (0, errno, "%s", stat_file);
        exit_status = 1;
        return;
      }
  
!   if (fsu.fsu_blocks == 0 && !show_all_fs && !show_listed_fs && do_totals != 2)
      return;
  
    if (! disk)
***************
*** 374,379 ****
--- 384,398 ----
  	}
      }
  
+   if (do_totals == 2)
+     {
+       total = total_total;
+       used = total_used;
+       available = total_available;
+       negate_used = negate_available = 0;
+       input_units = output_units = 1;
+    }
+ 
    printf (" %*s %*s %*s ",
  	  width, df_readable (0, total,
  			      buf[0], input_units, output_units),
***************
*** 382,387 ****
--- 401,413 ----
  	  width, df_readable (negate_available, available,
  			      buf[2], input_units, output_units));
  
+   if (do_totals == 1)
+     {
+       total_total += (total * input_units) / output_units;
+       total_used += (used * input_units) / output_units;
+       total_available += (available * input_units) / output_units;
+     }
+ 
    if (used != -1 && available != -1)
      {
        /* The following floating-point calculations can suffer from
***************
*** 776,781 ****
--- 802,808 ----
        --sync            invoke sync before getting usage info\n\
    -t, --type=TYPE       limit listing to filesystems of type TYPE\n\
    -T, --print-type      print filesystem type\n\
+       --totals          print totals\n\
    -x, --exclude-type=TYPE   limit listing to filesystems not of type TYPE\n\
    -v                    (ignored)\n\
        --help            display this help and exit\n\
***************
*** 855,860 ****
--- 882,891 ----
  	  human_block_size (optarg, 1, &output_block_size);
  	  break;
  
+ 	case TOTALS_OPTION:
+ 	  do_totals = 1;
+ 	  break;
+ 
  	case 'F':
  	  /* Accept -F as a synonym for -t for compatibility with Solaris.  */
  	case 't':
***************
*** 952,957 ****
--- 983,992 ----
  	if (argv[i])
  	  show_entry (argv[i], &stats[i - optind]);
      }
+ 
+   if (do_totals) {
+     show_dev("Total", NULL, NULL, 0, 0);
+   }
  
    close_stdout ();
    exit (exit_status);
