/usr/share/perl5/Sys/Filesystem/Unix.pm is in libsys-filesystem-perl 1.406-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | ############################################################
#
# $Id$
# Sys::Filesystem - Retrieve list of filesystems and their properties
#
# Copyright 2004,2005,2006 Nicola Worthington
# Copyright 2009 Jens Rehsack
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
############################################################
package Sys::Filesystem::Unix;
# vim:ts=4:sw=4:tw=78
use 5.008001;
use strict;
use warnings;
use vars qw($VERSION);
use Carp qw(croak);
use Cwd 'abs_path';
use Fcntl qw(:flock);
use IO::File;
$VERSION = '1.406';
sub version()
{
return $VERSION;
}
# Default fstab and mtab layout
my @keys = qw(fs_spec fs_file fs_vfstype fs_mntops fs_freq fs_passno);
my %special_fs = (
swap => 1,
proc => 1
);
sub new
{
ref( my $class = shift ) && croak 'Class name required';
my %args = @_;
my $self = bless( {}, $class );
$args{canondev} and $self->{canondev} = 1;
# Defaults
$args{fstab} ||= '/etc/fstab';
$args{mtab} ||= '/etc/mtab';
$self->readFsTab( $args{fstab}, \@keys, [ 0, 1, 2 ], \%special_fs );
$self->readMntTab( $args{mtab}, \@keys, [ 0, 1, 2 ], \%special_fs );
delete $self->{canondev};
$self;
}
sub readFsTab($\@\@\%)
{
my ( $self, $fstabPath, $fstabKeys, $pridx, $special_fs ) = @_;
# Read the fstab
local $/ = "\n";
if ( my $fstab = IO::File->new( $fstabPath, 'r' ) )
{
while (<$fstab>)
{
next if ( /^\s*#/ || /^\s*$/ );
# $_ =~ s/#.*$//;
# next if( /^\s*$/ );
my @vals = split( ' ', $_ );
$self->{canondev} and -l $vals[ $pridx->[0] ] and $vals[ $pridx->[0] ] = abs_path( $vals[ $pridx->[0] ] );
$self->{ $vals[ $pridx->[1] ] }->{mount_point} = $vals[ $pridx->[1] ];
$self->{ $vals[ $pridx->[1] ] }->{device} = $vals[ $pridx->[0] ];
$self->{ $vals[ $pridx->[1] ] }->{unmounted} = 1
unless ( defined( $self->{ $vals[ $pridx->[1] ] }->{mounted} ) );
if ( defined( $pridx->[2] ) )
{
my $vfs_type = $self->{ $vals[ $pridx->[1] ] }->{fs_vfstype} = $vals[ $pridx->[2] ];
$self->{ $vals[ $pridx->[1] ] }->{special} = 1
if ( defined( $special_fs->{$vfs_type} ) );
}
else
{
$self->{ $vals[ $pridx->[1] ] }->{special} = 0
unless ( defined( $self->{ $vals[ $pridx->[1] ] }->{special} ) );
}
for ( my $i = 0; $i < @{$fstabKeys}; ++$i )
{
$self->{ $vals[ $pridx->[1] ] }->{ $fstabKeys->[$i] } =
defined( $vals[$i] ) ? $vals[$i] : '';
}
}
$fstab->close();
1;
}
else
{
0;
}
}
sub readMntTab($\@\@\%)
{
my ( $self, $mnttabPath, $mnttabKeys, $pridx, $special_fs ) = @_;
# Read the mtab
local $/ = "\n";
my $mtab;
if ( ( $mtab = IO::File->new( $mnttabPath, 'r' ) ) && flock( $mtab, LOCK_SH | LOCK_NB ) )
{
while (<$mtab>)
{
next if ( /^\s*#/ || /^\s*$/ );
# $_ =~ s/#.*$//;
# next if( /^\s*$/ );
my @vals = split( /\s+/, $_ );
$self->{canondev} and -l $vals[ $pridx->[0] ] and $vals[ $pridx->[0] ] = abs_path( $vals[ $pridx->[0] ] );
delete $self->{ $vals[ $pridx->[1] ] }->{unmounted}
if ( exists( $self->{ $vals[ $pridx->[1] ] }->{unmounted} ) );
$self->{ $vals[ $pridx->[1] ] }->{mounted} = 1;
$self->{ $vals[ $pridx->[1] ] }->{mount_point} = $vals[ $pridx->[1] ];
$self->{ $vals[ $pridx->[1] ] }->{device} = $vals[ $pridx->[0] ];
if ( defined( $pridx->[2] ) )
{
my $vfs_type = $self->{ $vals[ $pridx->[1] ] }->{fs_vfstype} = $vals[ $pridx->[2] ];
$self->{ $vals[ $pridx->[1] ] }->{special} = 1
if ( defined( $special_fs->{$vfs_type} ) );
}
else
{
$self->{ $vals[ $pridx->[1] ] }->{special} = 0
unless ( defined( $self->{ $vals[ $pridx->[1] ] }->{special} ) );
}
for ( my $i = 0; $i < @{$mnttabKeys}; ++$i )
{
$self->{ $vals[ $pridx->[1] ] }->{ $mnttabKeys->[$i] } =
defined( $vals[$i] ) ? $vals[$i] : '';
}
}
$mtab->close();
1;
}
else
{
0;
}
}
sub readMounts
{
my ( $self, $mount_rx, $pridx, $keys, $special, @lines ) = @_;
foreach my $line (@lines)
{
if ( my @vals = $line =~ $mount_rx )
{
$self->{canondev} and -l $vals[ $pridx->[0] ] and $vals[ $pridx->[0] ] = abs_path( $vals[ $pridx->[0] ] );
$self->{ $vals[ $pridx->[1] ] }->{mount_point} = $vals[ $pridx->[1] ];
$self->{ $vals[ $pridx->[1] ] }->{device} = $vals[ $pridx->[0] ];
$self->{ $vals[ $pridx->[1] ] }->{mounted} = 1;
delete $self->{ $vals[ $pridx->[1] ] }->{unmounted}
if ( exists( $self->{ $vals[ $pridx->[1] ] }->{unmounted} ) );
if ( defined( $pridx->[2] ) )
{
my $vfs_type = $self->{ $vals[ $pridx->[1] ] }->{fs_vfstype} = $vals[ $pridx->[2] ];
$self->{ $vals[ $pridx->[1] ] }->{special} = 1
if ( defined( $special->{$vfs_type} ) );
}
elsif ( !defined( $self->{ $vals[ $pridx->[1] ] }->{special} ) )
{
$self->{ $vals[ $pridx->[1] ] }->{special} = 0;
}
for ( my $i = 0; $i < @{$keys}; ++$i )
{
$self->{ $vals[ $pridx->[1] ] }->{ $keys->[$i] } =
defined( $vals[$i] ) ? $vals[$i] : '';
}
}
}
$self;
}
sub readSwap
{
my ( $self, $swap_rx, @lines ) = @_;
foreach my $line (@lines)
{
if ( my ($dev) = $line =~ $swap_rx )
{
$self->{canondev} and -l $dev and $dev = abs_path($dev);
$self->{none}->{mount_point} ||= 'none';
$self->{none}->{device} = $dev;
$self->{none}->{fs_vfstype} = 'swap';
$self->{none}->{mounted} = 1;
$self->{none}->{special} = 1;
delete $self->{none}->{unmounted};
}
}
$self;
}
1;
=pod
=head1 NAME
Sys::Filesystem::Unix - Return generic Unix filesystem information to Sys::Filesystem
=head1 SYNOPSIS
See L<Sys::Filesystem>.
=head1 INHERITANCE
Sys::Filesystem::Unix
ISA UNIVERSAL
=head1 METHODS
=over 4
=item version()
Return the version of the (sub)module.
=item readFsTab
This method provides the capability to parse a standard unix fstab file.
It expects following arguments:
=over 8
=item fstabPath
Full qualified path to the fstab file to read.
=item fstabKeys
The column names for the fstab file through an array reference.
=item special_fs
Hash reference containing the names of all special file systems having a true
value as key.
=back
This method return true in case the specified file could be opened for reading,
false otherwise.
=item readMntTab
This method provides the capability to read abd parse a standard unix
mount-tab file. The file is locked using flock after opening it.
It expects following arguments:
=over 8
=item mnttabPath
Full qualified path to the mnttab file to read.
=item mnttabKeys
The column names for the mnttab file through an array reference.
=item $special_fs
Hash reference containing the names of all special file systems having a true
value as key.
=back
This method return true in case the specified file could be opened for reading
and locked, false otherwise.
=item readMounts
This method is called to parse the information got from C<mount> system command.
It expects following arguments:
=over 8
=item mount_rx
Regular expression to extract the information from each mount line.
=item pridx
Array reference containing the index for primary keys of interest in match
in following order: device, mount_point, type.
=item keys
Array reference of the columns of the match - in order of paranteses in
regular expression.
=item special
Array reference containing the names of the special file system types.
=item lines
Array containing the lines to parse.
=back
=item readSwap
This method is called to parse the information from the swap status.
It expects following arguments:
=over 8
=item swap_rx
Regular expression to extract the information from each swap status line.
This regular expression should have exact one pair of parantheses to
identify the swap device.
=item lines
Array containing the lines to parse.
=back
=back
=head1 VERSION
$Id$
=head1 AUTHOR
Nicola Worthington <nicolaw@cpan.org> - L<http://perlgirl.org.uk>
Jens Rehsack <rehsack@cpan.org> - L<http://www.rehsack.de/>
=head1 COPYRIGHT
Copyright 2004,2005,2006 Nicola Worthington.
Copyright 2008-2014 Jens Rehsack.
This software is licensed under The Apache Software License, Version 2.0.
L<http://www.apache.org/licenses/LICENSE-2.0>
=cut
|