X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;ds=sidebyside;f=tools%2Fvirt-df;h=4aa1063d8efeed67e1b98dbcff1449e62289cb68;hb=f7d3c8ec692a0f2596b0410a47fa69871904b2e9;hp=6157e21c0db55d2e15361e4f66c5eb6cc5223636;hpb=9004f3c5302fbb70212ccc420b863c9a3ca75abf;p=libguestfs.git
diff --git a/tools/virt-df b/tools/virt-df
index 6157e21..4aa1063 100755
--- a/tools/virt-df
+++ b/tools/virt-df
@@ -20,14 +20,14 @@ use warnings;
use strict;
use Sys::Guestfs;
-use Sys::Guestfs::Lib qw(open_guest get_partitions resolve_windows_path
- inspect_all_partitions inspect_partition
- inspect_operating_systems mount_operating_system inspect_in_detail);
+use Sys::Guestfs::Lib qw(open_guest get_partitions);
+
use Pod::Usage;
use Getopt::Long;
use Data::Dumper;
-use File::Temp qw/tempdir/;
use XML::Writer;
+use POSIX qw(ceil);
+
use Locale::TextDomain 'libguestfs';
=encoding utf8
@@ -107,8 +107,8 @@ my $csv;
=item B<--csv>
-Write out the results in CSV format (comma-separated values). This
-format can be imported easily into databases and spreadsheets, but
+Write out the results in CSV format (comma-separated values). This format
+can be imported easily into databases and spreadsheets, but
read L below.
=cut
@@ -160,7 +160,10 @@ if (@ARGV == 0) {
my @doms = $conn->list_defined_domains ();
push @doms, $conn->list_domains ();
- my @domnames = map { $_->get_name () } @doms;
+ # https://bugzilla.redhat.com/show_bug.cgi?id=538041
+ @doms = grep { $_->get_id () != 0 } @doms;
+
+ my @domnames = sort (map { $_->get_name () } @doms);
if (@domnames) {
print_title ();
@@ -228,9 +231,7 @@ sub print_stat
push @cols, ($blocks-$bfree)*$factor; # total 1K blocks used
push @cols, $bavail*$factor; # total 1K blocks available
- # XXX %used column comes out different from the native 'df'
- # program. Need to check how 'df' calculates this.
- push @cols, 100.0 - 100.0 * $bavail / $blocks;
+ push @cols, 100.0 - 100.0 * $bfree / $blocks;
if ($human) {
$cols[2] = human_size ($cols[2]);
@@ -246,9 +247,7 @@ sub print_stat
push @cols, $files-$ffree;
push @cols, $ffree;
- # XXX %used column comes out different from the native 'df'
- # program. Need to check how 'df' calculates this.
- push @cols, 100.0 - 100.0 * $favail / $files;
+ push @cols, 100.0 - 100.0 * $ffree / $files;
}
print_cols (@cols);
@@ -290,7 +289,10 @@ sub print_cols
printf ("%-36s", $label);
print "\n"," "x36 if length ($label) > 36;
- my $percent = sprintf "%3.1f%%", $_[5];
+ # Use 'ceil' on the percentage in order to emulate
+ # what df itself does.
+ my $percent = sprintf "%3d%%", ceil($_[5]);
+
printf ("%10s %10s %10s %5s\n", $_[2], $_[3], $_[4], $percent);
} else {
printf ("\"%s\",\"%s\",%d,%d,%d,%.1f%%\n", @_);
@@ -346,11 +348,11 @@ L.
=head1 AUTHOR
-Richard W.M. Jones L
+Richard W.M. Jones L
=head1 COPYRIGHT
-Copyright (C) 2009 Red Hat Inc.
+Copyright (C) 2009-2010 Red Hat Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by