FusionInventory-Agent

 view release on metacpan or  search on metacpan

lib/FusionInventory/Agent/Task/Inventory/Linux/Drives.pm  view on Meta::CPAN


            # Find real devicemapper block name
            unless ($devicemapper{$uuid}) {
                foreach my $uuidfile (glob ("/sys/block/*/dm/uuid")) {
                    next unless getFirstLine(file => $uuidfile) eq $uuid;
                    ($devicemapper{$uuid}) = $uuidfile =~ m|^(/sys/block/[^/]+)|;
                    last;
                }
            }
            next unless $devicemapper{$uuid};

            # Lookup for crypto devicemapper slaves
            my @names = grep { defined($_) && length($_) } map {
                getFirstLine(file => $_)
            } glob ("$devicemapper{$uuid}/slaves/*/dm/name");

            # Finaly we may try on the device itself, see #825
            push @names, $filesystem->{VOLUMN};

            foreach my $name (@names) {
                # Check cryptsetup status for the found slave/device
                unless ($cryptsetup{$name}) {
                    my $handle = getFileHandle( command => "cryptsetup status $name" )
                        or next;
                    while (my $line = <$handle>) {
                        chomp $line;
                        next unless ($line =~ /^\s*(.*):\s*(.*)$/);
                        $cryptsetup{$name}->{uc($1)} = $2;
                    }
                    close $handle;
                }
                next unless $cryptsetup{$name};

                # Add cryptsetup status to filesystem
                $filesystem->{ENCRYPT_NAME}   = $cryptsetup{$name}->{TYPE};
                $filesystem->{ENCRYPT_STATUS} = 'Yes';
                $filesystem->{ENCRYPT_ALGO}   = $cryptsetup{$name}->{CIPHER};

                last;
            }
        }
    }

    return @filesystems;
}

sub _getFilesystemsFromHal {
    my $devices = _parseLshal(command => 'lshal');
    return @$devices;
}

sub _parseLshal {
    my $handle = getFileHandle(@_);
    return unless $handle;

    my $devices = [];
    my $device = {};

    while (my $line = <$handle>) {
        chomp $line;
        if ($line =~ m{^udi = '/org/freedesktop/Hal/devices/(volume|block).*}) {
            $device = {};
            next;
        }

        next unless defined $device;

        if ($line =~ /^$/) {
            if ($device->{ISVOLUME}) {
                delete($device->{ISVOLUME});
                push(@$devices, $device);
            }
            undef $device;
        } elsif ($line =~ /^\s+ block.device \s = \s '([^']+)'/x) {
            $device->{VOLUMN} = $1;
        } elsif ($line =~ /^\s+ volume.fstype \s = \s '([^']+)'/x) {
            $device->{FILESYSTEM} = $1;
        } elsif ($line =~ /^\s+ volume.label \s = \s '([^']+)'/x) {
            $device->{LABEL} = $1;
        } elsif ($line =~ /^\s+ volume.uuid \s = \s '([^']+)'/x) {
            $device->{SERIAL} = $1;
        } elsif ($line =~ /^\s+ storage.model \s = \s '([^']+)'/x) {
            $device->{TYPE} = $1;
         } elsif ($line =~ /^\s+ volume.size \s = \s (\S+)/x) {
            my $value = $1;
            $device->{TOTAL} = int($value/(1024*1024) + 0.5);
        } elsif ($line =~ /block.is_volume\s*=\s*true/i) {
            $device->{ISVOLUME} = 1;
        }
    }
    close $handle;

    return $devices;
}

1;



( run in 3.700 seconds using v1.01-cache-2.11-cpan-a49fcb8fa48 )