#!/usr/bin/perl
#
# Include only certain filesystems, create an exclusion list of the others.
#
# You could just exclude everything in /proc/mounts where the type is not in the list,
# but this reduces the list to the minimum
#


use strict;
use warnings;
use List::Util qw<any none>;

my @include = qw< ext2 ext3 ext4 xfs jfs squashfs>;


my @rawmounts = `cat /proc/mounts`;
chomp @rawmounts;
my @mounts = map {
        my ($what, $mp, $type, $options) = split / /, $_, 4;
        +{
                what    => $what,
                mp      => $mp,
                type    => $type,
                exclude => none { $type eq $_ } @include,
                options => $options,
        };
} @rawmounts;


use Data::Dump;
my @excluded =  grep {$_->{exclude}} @mounts;
@excluded = sort { $a->{mp} cmp $b->{mp} } @excluded;

#dd @excluded;

die "Nothing excluded" if (not @excluded);
exit 0 if (not @excluded); # unlikely, maybe impossible, but let's not take any chances


my @out;
my $cur = shift @excluded;
push @out, $cur;
for (@excluded) {
        my $mp = $cur->{mp};
        if ($_->{mp} !~ /^\Q$mp\E(?:$|\/)/) {
                $cur = $_;
                push @out, $cur;
        } else {
                #print "Exclude $_->{mp}, below $mp\n";
        }
}
print "$_->{mp}\n" for @out;
