From 6a08921e2118eb63ba4e70a8ccee6cab0056b047 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Thu, 2 May 2024 13:59:02 +0200 Subject: [PATCH] filesystem-functions.pl: Add is_btrfs() function This function can be used to check if a given mountpoint contains a BTRFS filesystem. Signed-off-by: Stefan Schantl --- config/cfgroot/filesystem-functions.pl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/config/cfgroot/filesystem-functions.pl b/config/cfgroot/filesystem-functions.pl index 2c3877a9d..cc355efa3 100644 --- a/config/cfgroot/filesystem-functions.pl +++ b/config/cfgroot/filesystem-functions.pl @@ -453,4 +453,26 @@ sub get_device_mapper_group ($) { return $dev_path; } +# +## Function which returns true if the given mountpoint contains a BTRFS. +# +sub is_btrfs($) { + my ($mpoint) = @_; + + # Call the volumes status function without any additional arguments + # so we only get the mounted volumes, without df details or uuids. + my %volumes = &volumes_status(); + + # Loop through the hash of volumes. + foreach my $volume (sort keys %volumes) { + # Skip volume if it is not mounted to the requested mpoint. + next unless ($volumes{$volume}{'mpoint'} eq "$mpoint"); + + # Return "1" (True) if the requested mountpoint is mounted as BTRFS. + return 1 if ($volumes{$volume}{'filesystem'} eq "btrfs"); + } + + # Return nothing if the mointpoint is not mounted as BTRFS. + return; +} 1; -- 2.39.5