Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

How to determine if a file is a mount point?

by gw1500se (Beadle)
on Jun 29, 2008 at 00:52 UTC ( [id://694567]=perlquestion: print w/replies, xml ) Need Help??

gw1500se has asked for the wisdom of the Perl Monks concerning the following question:

I am well down the road with my directory parsing script. However, I have encountered a stumbling block. The -X feature does not have a function that tells me if the file is a mount point or more accurately a mounted file system. How do I determine if I am at a mount point so I can avoid parsing it? Thanks.
  • Comment on How to determine if a file is a mount point?

Replies are listed 'Best First'.
Re: How to determine if a file is a mount point?
by pc88mxer (Vicar) on Jun 29, 2008 at 01:19 UTC
    Under Unix-like systems, sometimes checking the device field returned by lstat() will work. For instance, here's the wanted() routine generated by find2perl / -xdev:
    use File::Find; File::Find::find({wanted => \&wanted}, '/'); exit; sub wanted { my ($dev,$ino,$mode,$nlink,$uid,$gid); (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && !($File::Find::prune |= ($dev != $File::Find::topdev)) && print("$name\n"); }
    $File::Find::topdev is simply the device associated with the root directory /:
    ($File::Find::topdev) = lstat("/");
      Thanks. That seems to help with one exception so far. Using that method, it makes /dev look like a mounted file system which it is not. Is there some special meaning to $dev for certain directories like /dev?

        Actually, /dev is a mounted file system -- see what the mount command reports.

        It is not a remote file system like NFS, but then Linux doesn't differentiate "remote" file systems from other kinds of file systems (like /proc or EXT2 or NTFS or FTPFS).

        The value of the device field identifies the handler (file system driver) that the OS uses to implement the file system object. If you only interested in NFS files, you could find out what its device id is and just check for that particular value.

        /dev and /proc are both mounted file systems. They are just special, because they are not disk based.

        Look at the output of mount. It should list both /dev and /proc.

        grep
        One dead unjugged rabbit fish later...
Re: How to determine if a file is a mount point?
by linuxer (Curate) on Jun 29, 2008 at 15:36 UTC

    You can check /etc/mtab to see what is mounted at which mountpoint.

    Create a list (or something else) with all mountpoints and you can check against that list.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://694567]
Approved by pc88mxer
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-23 06:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found