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

Tie::Mounted - Tie a mounted node to an array

SYNOPSIS

 require Tie::Mounted;

 tie @files, 'Tie::Mounted', '/backup', '-v';
 print $files[-1];
 untie @files;

DESCRIPTION

This module ties files (and directories) of a mount point to an array by invoking the system commands mount and umount; mount is invoked when a former attempt to tie an array is being committed, umount when a tied array is to be untied. Suitability is therefore limited and suggests a rarely used node (such as /backup).

The mandatory parameter consists of the node (or: mount point) to be mounted (/backup - as declared in /etc/fstab); optional options to mount may be subsequently passed (-v). Device names and mount options (-a,-A,-d) will be discarded in regard of system security.

Default paths to mount and umount may be overriden by setting accordingly either $Tie::Mounted::MOUNT_BIN or $Tie::Mounted::UMOUNT_BIN.

If $Tie::Mounted::No_files is set to a true value, a bogus array with zero files will be tied.

CAVEATS

Security

Tie::Mounted requires by default to either have $APPROVE set to an untrue value in order to pass nodes as desired, or @NODES to contain the nodes that are considered ``approved"; both variables are lexically scoped and adjustable within _private(). If in approval mode and a node is passed that is considered unapproved, Tie::Mounted will throw an exception.

Such ``security" is rather trivial; instead it is recommended to adjust filesystem permissions to prevent malicious use.

Portability

It is doubted that it will work reliably on a non-(Open)BSD system due to the fact that a pipe to mount has to be established to ensure that a node is not already being mounted; which requires a parameter to be passed that widely varies on common Unix systems.

Miscellanea

The tied array is read-only.

Files within the tied array are statically tied.

Internals

It is not recommended to modify internals unless the parameters to _localcall() are being adjusted accordingly.

SEE ALSO

"tie" in perlfunc, fstab(5), mount(8), umount(8)