From 2097cfd1ee2a4eb460946d999cc8b5eee369d0fc Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Thu, 2 May 2024 14:05:16 +0200 Subject: [PATCH] filesystem-functions.pl: Add btrfs_filesystem_usage() function This function calls the btrfs binary and returns it's output as an array. Signed-off-by: Stefan Schantl --- config/cfgroot/filesystem-functions.pl | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/config/cfgroot/filesystem-functions.pl b/config/cfgroot/filesystem-functions.pl index cc355efa3..f822657f2 100644 --- a/config/cfgroot/filesystem-functions.pl +++ b/config/cfgroot/filesystem-functions.pl @@ -21,6 +21,8 @@ package Filesystem; +require '/var/ipfire/general-functions.pl'; + use strict; # Import perl module to get details about the space usage. @@ -32,6 +34,9 @@ my $sysfs_block_dir = "/sys/class/block"; # Directory where the uuid mappings can be found. my $uuid_dir = "/dev/disk/by-uuid"; +# Location where the btrfs binary lives. +my $btrfs_bin = "/usr/bin/btrfs"; + # ## Function which returns a lot of details about the known devices ## as a hash of hashes. @@ -475,4 +480,28 @@ sub is_btrfs($) { # Return nothing if the mointpoint is not mounted as BTRFS. return; } + +# +## Function which simply calls the filesystem usage of the btrfs tool and +## returns it's output as array. +# +sub btrfs_filesystem_usage($$) { + my ($path, $check) = @_; + + # Default to check to determine if the given path contains a BTRFS + $check //= "check"; + + # Only run the is_btrfs check if requested or not set. + if ($check eq "check") { + # Abort if the given path does not exist or does not contain a BTRFS. + return unless(&is_btrfs($path)); + } + + # Call btrfs binary to get details about the current filesystem usage. + my @output = &General::system_output("$btrfs_bin", "filesystem", "usage", "-b", "$path"); + + # Return the grabbed output. + return @output; +} + 1; -- 2.39.5