#!/usr/bin/perl use strict; use warnings; for my $bind (@{find_mount_bind()}) { print qq!Directory "$bind->{root}" is bound to "$bind->{mount_point}"\n!; } ######################################## ######################################## ######################################## sub parse_mounts { my $file="/proc/$$/mounts"; open(my $fh, '<', $file) or die("ERROR $file ($!)\n"); my @ret; while(<$fh>) { my %info; my @line=split(/\s+/,$_); $info{device}=shift(@line); $info{mount_point}=shift(@line); $info{fstype}=shift(@line); $info{mount_options}=[split(/,/,shift(@line))]; push(@ret,\%info); } close($fh); return \@ret; } sub parse_mountinfo { my $file="/proc/$$/mountinfo"; open(my $fh, '<', $file) or die("ERROR $file ($!)\n"); my @ret; while(<$fh>) { my %info; my @line=split(/\s+/,$_); $info{mount_id}=shift(@line); $info{parent_id}=shift(@line); my @m=split(/:/,shift(@line)); $info{major}=shift(@m); $info{minor}=shift(@m); $info{root}=shift(@line); $info{mount_point}=shift(@line); $info{mount_options}=[split(/,/,shift(@line))]; $info{optional_fields}={}; while(my $val=shift(@line)) { last if($val eq '-'); my ($k,$v)=split(/:/,$val); $info{optional_fields}->{$k}=$v; } $info{fstype}=shift(@line); $info{mount_source}=shift(@line); $info{super_options}=[split(/,/,shift(@line))]; push(@ret,\%info); } close($fh); return \@ret; } sub find_mount_bind { my $infos=parse_mountinfo(); my $mount=parse_mounts(); my @ret; for my $ip (@$infos) { if($ip->{root} ne '/') { for my $mp (@$mount) { if( $ip->{mount_source} eq $mp->{device} ) { next if($mp->{mount_point} eq $ip->{mount_point}); push(@ret,{ root => $mp->{mount_point}.$ip->{root}, mount_point => $ip->{mount_point}, }); last; } } } } return \@ret; }