$volumes{$dev}{'mpoint'} = $mpoint unless($volumes{$dev}{'mpoint'});
if ($options{'df'} eq "True") {
- # Call df module to get details about space usage
- # and request the output in bytes (1).
- my $df = Filesys::Df::df($mpoint, 1);
-
- # Assign grabbed storrage details to the hash.
- if (defined($df)) {
- $volumes{$dev}{"size"} = $df->{blocks};
- $volumes{$dev}{"free"} = $df->{bfree};
- $volumes{$dev}{"avail"} = $df->{bavail};
- $volumes{$dev}{"used"} = $df->{used};
- $volumes{$dev}{"percent_used"} = $df->{per};
- $volumes{$dev}{"percent_free"} = int(100) - $df->{per};
-
- # Undefine created df object for the processed mountpoint.
- undef $df;
+ # Check if the device contains a BTRFS.
+ if ($fs eq "btrfs") {
+ # Call the corresponding BTRFS function to proper get
+ # the filesystem usage details.
+ my @usage = &btrfs_filesystem_usage($mpoint, "nocheck");
+
+ my $size;
+ my $allocated;
+
+ # Loop through the output of the usage function.
+ foreach my $line (@usage) {
+ # Remove any newlines.
+ chomp($line);
+
+ # Grab the total size of the filesystem.
+ if ($line =~/.*Device size:\s+(.*)/) {
+ $size = $1;
+
+ # Grab the allocated space.
+ } elsif ($line =~/.*Device allocated:\s+(.*)/) {
+ $allocated = $1;
+ }
+
+ # Break the loop in case the size and free space have been grabbed.
+ last if(($size) && ($allocated));
+ }
+
+ # Compute the unallocated space.
+ my $unallocated = $size - $allocated;
+
+ # Compute the allocated space in percent.
+ my $allocated_percent = $allocated * 100 / $size;
+
+ # Format the allocated percent with only 2 digits after comma.
+ $allocated_percent = sprintf("%.2f", $allocated_percent);
+
+ # Assign the values to the hash.
+ $volumes{$dev}{"size"} = $size;
+ $volumes{$dev}{"free"} = $unallocated;
+ $volumes{$dev}{"avail"} = $unallocated;
+ $volumes{$dev}{"used"} = $allocated;
+ $volumes{$dev}{"percent_used"} = $allocated_percent;
+ $volumes{$dev}{"percent_free"} = int(100) - $allocated_percent;
+
+ # Perform any other used filesystem.
+ } else {
+ # Call df module to get details about space usage
+ # and request the output in bytes (1).
+ my $df = Filesys::Df::df($mpoint, 1);
+
+ # Assign grabbed storrage details to the hash.
+ if (defined($df)) {
+ $volumes{$dev}{"size"} = $df->{blocks};
+ $volumes{$dev}{"free"} = $df->{bfree};
+ $volumes{$dev}{"avail"} = $df->{bavail};
+ $volumes{$dev}{"used"} = $df->{used};
+ $volumes{$dev}{"percent_used"} = $df->{per};
+ $volumes{$dev}{"percent_free"} = int(100) - $df->{per};
+
+ # Undefine created df object for the processed mountpoint.
+ undef $df;
+ }
}
}
}