Re-factor function to get total disk space, handle ZFS
authorJamie Cameron <jcameron@webmin.com>
Thu, 7 Aug 2008 19:51:31 +0000 (19:51 +0000)
committerJamie Cameron <jcameron@webmin.com>
Thu, 7 Aug 2008 19:51:31 +0000 (19:51 +0000)
blue-theme/right.cgi
mount/mount-lib.pl

index 2bd6461..ea5b434 100755 (executable)
@@ -115,20 +115,7 @@ if ($level == 0) {
        # Disk space on local drives
        if (&foreign_check("mount")) {
                &foreign_require("mount", "mount-lib.pl");
-               @mounted = &mount::list_mounted();
-               $total = 0;
-               $free = 0;
-               foreach $m (@mounted) {
-                       if ($m->[2] eq "ext2" || $m->[2] eq "ext3" ||
-                           $m->[2] eq "reiserfs" || $m->[2] eq "ufs" ||
-                           $m->[2] eq "zfs" || $m->[2] eq "simfs" ||
-                           $m->[2] eq "xfs" ||
-                           $m->[1] =~ /^\/dev\//) {
-                               ($t, $f) = &mount::disk_space($m->[2], $m->[0]);
-                               $total += $t*1024;
-                               $free += $f*1024;
-                               }
-                       }
+               ($total, $free) = &mount::local_disk_space();
                if ($total) {
                        print "<tr> <td><b>$text{'right_disk'}</b></td>\n";
                        print "<td>",&text('right_used',
index f1c27f6..7a3ab12 100644 (file)
@@ -286,5 +286,33 @@ foreach my $m (&list_mounted()) {
 return ( );
 }
 
+# local_disk_space([&always-count])
+# Returns the total local and free disk space on the system.
+sub local_disk_space
+{
+my ($always) = @_;
+my ($total, $free) = (0, 0);
+my @mounted = &mount::list_mounted();
+my %donezone;
+foreach $m (@mounted) {
+       if ($m->[2] eq "ext2" || $m->[2] eq "ext3" ||
+           $m->[2] eq "reiserfs" || $m->[2] eq "ufs" ||
+           $m->[2] eq "zfs" || $m->[2] eq "simfs" ||
+           $m->[2] eq "xfs" ||
+           $m->[1] =~ /^\/dev\// ||
+           &indexof($m->[1], @$always) >= 0) {
+               if ($m->[1] =~ /^zones\/([^\/]+)/ &&
+                    $m->[2] eq "zfs" && $donezone{$1}++) {
+                       # Don't double-count zones
+                       next;
+                       }
+               my ($t, $f) = &mount::disk_space($m->[2], $m->[0]);
+               $total += $t*1024;
+               $free += $f*1024;
+               }
+       }
+return ($total, $free);
+}
+
 1;