couple fixes

This commit is contained in:
speed47 2015-10-31 17:12:53 +01:00
parent da916191ae
commit 482cdbacf4

View File

@ -95,7 +95,6 @@ sub link2real
}
sub raw2human
{
my $human = shift;
if ($human !~ /^(\d+)(\.\d+)?$/) { return $human; }
@ -118,8 +117,9 @@ if ($version lt '3.16')
}
@cmd = run_cmd( { can_fail => 0 }, qw{ uname -r } );
my ($kerver) = $cmd[1][0] =~ /^([0-9]+\.[0-9]+)/;
if ($kerver lt $version)
my ($kerver) = $cmd[1][0] =~ /^(\d+\.\d+)/;
my ($shortversion) = $version =~ /^(\d+\.\d+)/;
if ($kerver lt $shortversion)
{
print STDERR "WARNING: your kernel seems older (v$kerver.x) than the btrfs-progs userspace tool (v$version), some features might not be supported.\n";
}
@ -149,6 +149,11 @@ foreach (@{ $cmd[1] })
{
$label = $1;
$fuuid = $2;
# some versions of btrfs-progs enquote the label
if ($label =~ /^'(.+)'$/)
{
$label = $1;
}
}
if (defined $fuuid and m{devid\s.+path\s+(\S+)})
{
@ -173,12 +178,28 @@ my %mountpoints;
open(MP, '/proc/mounts');
while (<MP>)
{
if (m{^(\S+)\s+(\S+)})
if (m{^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)})
{
# ugly fix for /dev/mapper/stuff being a sylink to ../dm-xxx
my $dev = $1;
my $mp = $2;
$mountpoints{$dev} = $mp;
my $fstype = $3;
my $options = $4;
$fstype ne 'btrfs' and next;
debug(">> mounts item [$dev] mounted on $mp");
if ($options =~ /subvolid=(\d+)/)
{
if ($1 < 256)
{
debug(">> ... subvolid $1 so keeping it");
$mountpoints{$dev} = $mp;
}
else
{
debug(">> ... subvolid $1 so ignoring it");
next;
}
}
if (-l $dev)
{
$mountpoints{ link2real($dev) } = $mp;
@ -242,7 +263,7 @@ foreach my $fuuid (keys %filesystems)
parent => '-',
top => '-',
puuid => '*',
ruuid => '-', type => 'fidf', mode => 'rw',
ruuid => '-', type => 'fs', mode => 'rw',
rfer => "-",
excl => raw2human($used),
free => $free,
@ -398,13 +419,13 @@ foreach my $fuuid (keys %filesystems)
{
$vol{$fuuid}{$id} = {
id => $id,
path => $filesystems{$fuuid}{mountpoint},
path => "[main]", #$filesystems{$fuuid}{mountpoint},
gen => 0,
cgen => 0,
parent => '-',
top => '-',
puuid => '+',
ruuid => '-', type => 'vol', mode => 'rw'
ruuid => '-', type => 'mainvol', mode => 'rw'
};
}
$vol{$fuuid}{$id}{rfer} = $rfer;
@ -469,8 +490,8 @@ foreach my $fuuid (keys %filesystems)
$len > $longestpath and $longestpath = $len;
}
my $format = "%-${longestpath}s %3s %8s %9s %9s %s\n";
printf $format, 'PATH', 'ID', "TYPE", "REFER", "USED", "" ;
my $format = "%-${longestpath}s %5s %8s %9s %9s %s\n";
printf $format, 'NAME', 'ID', "TYPE", "REFER", "USED", "" ;
foreach (@ordered)
{
#print Dumper $_;