in reply to Dynamically determinig fstab file name

G'day Rick,

As far as I can tell, Sys::Filesystem does not report what fstab file it uses. It relies on the various Sys::Filesystem::<OS> modules, e.g. Sys::Filesystem::AIX, for the filesystem information. See the "Sys-Filesystem distro page" for a list of those modules.

If you simply want to perform some upfront sanity checks, perhaps code similar to the following might suffice.

#!/usr/bin/env perl use 5.010; use strict; use warnings; use Sys::Filesystem (); if (Sys::Filesystem::->supported()) { my $fs = Sys::Filesystem::->new(); say '$Sys::Filesystem::FSTAB: ', $Sys::Filesystem::FSTAB // 'undefined'; say '$fs->{fstab}: ', $fs->{fstab} // 'undefined'; say "O/S '$^O' supported."; say 'Using: ', ref($fs->{filesystems}); my @fs_list = $fs->filesystems(); if (@fs_list) { say 'Filesystems found:'; say "\t$_" for @fs_list; } else { warn "No filesystems found.\n"; } use Data::Dump; say '=' x 60; say 'Sys::Filesystem Object:'; say '=' x 60; dd $fs; say '-' x 60; } else { warn "O/S '$^O' not supported.\n"; }

I've included code to produce a lot of additional information which you may find interesting, but probably isn't wanted in production.

I'm strongly against breaking encapsulation and urge you to stick with the published API. I only included $fs->{fstab} and $fs->{filesystems} for demonstration purposes.

I don't have any of the four OSes you list available at home. Here's the output on my Cygwin system.

$Sys::Filesystem::FSTAB: undefined $fs->{fstab}: undefined O/S 'cygwin' supported. Using: Sys::Filesystem::Cygwin Filesystems found: / /cygdrive/c /cygdrive/d /usr/bin /usr/lib ============================================================ Sys::Filesystem Object: ============================================================ bless({ aliases => { boot_order => ["fs_mntno"], check_frequency => ["fs_freq"], check_order => ["fs_passno"], device => ["fs_spec", "dev"], filesystem => ["fs_file", "mount_point"], format => ["fs_vfstype", "vfs", "vfstype"] +, label => ["fs_label"], mount_point => ["fs_file", "filesystem"], options => ["fs_mntops"], type => ["fs_vfstype", "vfs"], volume => ["fs_volume", "fs_vol", "vol"], }, canondev => undef, filesystems => bless({ "/" => { device => "C:/cygwin64", fs_file => "/", fs_mntops => "binary,auto", fs_spec => "C:/cygwin64", fs_vfstype => "ntfs", mount_point => "/", mounted => 1, }, "/cygdrive/c" => { device => "C:", fs_file => "/cygdrive/c", fs_mntops => "binary,posix=0,user,noumount,auto +", fs_spec => "C:", fs_vfstype => "ntfs", mount_point => "/cygdrive/c", mounted => 1, }, "/cygdrive/d" => { device => "D:", fs_file => "/cygdrive/d", fs_mntops => "binary,posix=0,user,noumount,auto +", fs_spec => "D:", fs_vfstype => "ntfs", mount_point => "/cygdrive/d", mounted => 1, }, "/usr/bin" => { device => "C:/cygwin64/bin", fs_file => "/usr/bin", fs_mntops => "binary,auto", fs_spec => "C:/cygwin64/bin", fs_vfstype => "ntfs", mount_point => "/usr/bin", mounted => 1, }, "/usr/lib" => { device => "C:/cygwin64/lib", fs_file => "/usr/lib", fs_mntops => "binary,auto", fs_spec => "C:/cygwin64/lib", fs_vfstype => "ntfs", mount_point => "/usr/lib", mounted => 1, }, }, "Sys::Filesystem::Cygwin"), fstab => undef, mtab => undef, }, "Sys::Filesystem") ------------------------------------------------------------

— Ken

Replies are listed 'Best First'.
Re^2: Dynamically determinig fstab file name
by rgren925 (Beadle) on Nov 23, 2022 at 17:51 UTC

    Hi Ken

    Thanks very much for the reply.

    I just tried your code on RHEL 7. Here's the salient output:

    $Sys::Filesystem::FSTAB: undefined $fs->{fstab}: undefined O/S 'linux' supported. Using: Sys::Filesystem::Linux

    An environment issue?

    Rick

      "An environment issue?"

      I don't understand the question. What are you asking about the environment? What issue do think exists?

      Other than "[Ll]inux", instead of "[Cc]ygwin", that's identical to my first four lines of output. I assume you got, but didn't post, subsequent lines about "filesystems found", followed by dd $fs output.

      — Ken

        Sorry. Took a bit of a leap there. I made the (bad) assumption that your output was demonstration but that, perhaps, cygwin didn't output the fstab file name. The fstab value is what I am looking for. I can get all the data from I want from Sys::Filesystem--as long as I have read access to fstab. That's the sticking point. I want the name of the fstab file on that particular system. This code is running on 100k+ systems across several platforms, so I am loathe to make any assumptions.