The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

PTools::SDF::File::Mnttab - Parser for "/etc/mnttab" (/etc/fstab) file.

VERSION

This document describes version 0.08, released October, 2004.

SYNOPSIS

        use PTools::SDF::File::Mnttab;

   or   use PTools::SDF::File::Mnttab  qw( followPath );

        $mntRef = new PTools::SDF::File::Mnttab;     # load /etc/mnttab

        ($mount,$type) = $mntRef->findMountPoint("/some/dir/path");
   or   $mount         = $mntRef->findMountPoint("/some/dir/path");
        
        ($mount,$type) = $mntRef->findMountDev("/dev/vg00/lvol6");
   or   $mount         = $mntRef->findMountDev("/dev/someDevice");
        
        ($stat,$err) = $mntRef->status;      # returns any fatal error

        $mntRef->mountIsLocal   and print "FS is local\n";
        $mntRef->mountNotLocal  and print "FS is NOT local\n";
        $mntRef->validMountPoint or print "path: no directory found\n";

        $mount = $mntRef->getMountPoint;     # dir  from findMountPoint|Dev
        $type  = $mntRef->getMountType;      # type from findMountPoint|Dev
        $device= $mntRef->getMountDevice;    # dev  from findMountPoint|Dev

DESCRIPTION

This class is a simple parser for the file /etc/mnttab on Unix systems. It is used to easily find mount point information for various file paths.

Constructor

new ( BasePath [, Depth ] )

The new method loads some or all of the /etc/mnttab file into an object of this class.

BasePath

When you know that all of the paths you will work with are under the same base directory path, include this BasePath in the "new" method. This will load a subset of the /etc/mnttab file including only those entries where the base directory path is the same. This can speed mount point lookups when there are hundreds of entries in the /etc/mnttab file.

$mntRef = new PTools::SDF::File::Mnttab( $path );
Depth

Optionally include a Depth parameter to include addtional levels of subdirectory names in the match, thereby (potentially) loading an even smaller subset of mnttab entries. When a BasePath parameter is used, the default Depth is one, but this is in addition to the "/" (root) dir.

$mntRef = new PTools::SDF::File::Mnttab( $path, $depth );

Note: By default, any path with relative directory components or symbolic links is NOT recognized as valid. To allow these path components, add the "followPath" parameter to the "use" statement, as shown above. To ensure that mount points can be found, the full /etc/mnttab file is loaded in this case, and any $path and $depth parameters to the new method are ignored.

Methods

findMountPoint ( Path )

Find the /etc/mnttab entry, if any, for a given file system Path.

Examples:

($mount,$type) = $mntRef->findMountPoint("/some/dir/path");

$mount         = $mntRef->findMountPoint("/some/dir/path");
findMountDevice ( Device )

Find the /etc/mnttab entry, if any, for a given Device special file.

($mount,$type) = $mntRef->findMountDev("/dev/vg00/lvol6");

$mount         = $mntRef->findMountDev("/dev/someDevice");
listMountPoints

Return a list of the mount points loaded from the /etc/inittab file. Note that this may only be a subset of the entries in this file.

Example:

$i=0;
foreach $mount ( $mntRef->listMountPoints ) { 
    printf(" dir %3.3d: %s\n", $i++, $mount ); 
}
getMountDevice
getMountPoint
getMountType
getMountOpts
getMountTime

These methods return data values based on the result of a prior call to either the findMountPoint or findMountDevice methods.

Examples:

$mount = $mntRef->getMountPoint;

$type  = $mntRef->getMountType;

$device= $mntRef->getMountDevice;
mountIsLocal
mountNotLocal
validMountPoint

These methods return boolean values based on the result of a prior call to either the findMountPoint or findMountDevice methods.

Examples:

$mntRef->mountIsLocal   and print "FS is local\n";

$mntRef->mountNotLocal  and print "FS is NOT local\n";

$mntRef->validMountPoint or print "path: no directory found\n";
save

The save method is disabled in this class. You really don't want to rewrite the /etc/mnttab file as currently implemented. This would cause any comments in the file to be lost.

INHERITANCE

This class inherits from PTools::SDF::SDF which in turn inherits from PTools::SDF::File.

SEE ALSO

For additional methods see PTools::SDF::SDF and PTools::SDF::File.

AUTHOR

Chris Cobb, <nospamplease@ccobb.net>

COPYRIGHT

Copyright (c) 2002-2007 by Chris Cobb. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.