Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Check that a ramdisk is mounted

by jcb (Parson)
on May 15, 2021 at 02:18 UTC ( [id://11132616] : note . print w/replies, xml ) Need Help??


in reply to Check that a ramdisk is mounted

The first element of the list returned by stat will be different on a directory and its parent directory if and only if the directory is a mountpoint.

#!/usr/bin/perl use strict; use warnings; use Cwd qw/realpath/; use File::Spec; my $Dir = realpath(shift || File::Spec->curdir); my $Parent = realpath(File::Spec->catdir($Dir, File::Spec->updir)); my $Dir_fsid = (stat($Dir))[0]; my $Parent_fsid = (stat($Parent))[0]; printf 'dir: [on %4x] %s%s', $Dir_fsid,$Dir,"\n"; printf ' up: [on %4x] %s%s', $Parent_fsid,$Parent,"\n"; if ($Dir_fsid == $Parent_fsid) { print "$Dir is not a mountpoint\n" } else { print "$Dir is a mountpoint\n" } __END__