]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
filesystem-functions.pl: Add is_btrfs() function
authorStefan Schantl <stefan.schantl@ipfire.org>
Thu, 2 May 2024 11:59:02 +0000 (13:59 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Thu, 2 May 2024 11:59:02 +0000 (13:59 +0200)
This function can be used to check if a given mountpoint contains a
BTRFS filesystem.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/cfgroot/filesystem-functions.pl

index 2c3877a9d108457006e8b997b5214db4f9aab537..cc355efa31bc52effb5cde919c218cc8cb057897 100644 (file)
@@ -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;