/usr/share/perl5/Sys/Filesystem.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 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | ############################################################
#
# $Id$
# Sys::Filesystem - Retrieve list of filesystems and their properties
#
# Copyright 2004,2005,2006 Nicola Worthington
# Copyright 2008,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;
# vim:ts=4:sw=4:tw=78
use 5.008001;
my @query_order;
use strict;
use warnings;
use vars qw($VERSION $AUTOLOAD $CANONDEV $FSTAB $MTAB);
use Carp qw(croak cluck confess);
use Module::Pluggable
require => 1,
only => [ @query_order = map { __PACKAGE__ . '::' . $_ } ( ucfirst( lc $^O ), $^O =~ m/Win32/i ? 'Win32' : 'Unix', 'Dummy' ) ],
inner => 0,
search_path => ['Sys::Filesystem'],
sub_name => '_plugins';
use Params::Util qw(_INSTANCE);
use Scalar::Util qw(blessed);
use List::Util qw(first);
use constant DEBUG => $ENV{SYS_FILESYSTEM_DEBUG} ? 1 : 0;
use constant SPECIAL => ( 'darwin' eq $^O ) ? 0 : undef;
$VERSION = '1.406';
my ( $FsPlugin, $Supported );
BEGIN
{
Sys::Filesystem->_plugins();
foreach my $qo (@query_order)
{
next unless ( UNIVERSAL::isa( $qo, $qo ) );
$FsPlugin = $qo;
last;
}
$Supported = $FsPlugin ne 'Sys::Filesystem::Unix' and $FsPlugin ne 'Sys::Filesystem::Dummy';
}
sub new
{
# Check we're being called correctly with a class name
ref( my $class = shift ) and croak 'Class name required';
# Check we've got something sane passed
croak 'Odd number of elements passed when even number was expected' if ( @_ % 2 );
my %args = @_;
exists $args{xtab} and carp("Using xtab is depreciated") and delete $args{xtab};
defined $FSTAB and not exists $args{fstab} and $args{fstab} = $FSTAB;
defined $MTAB and not exists $args{mtab} and $args{mtab} = $MTAB;
defined $CANONDEV and not exists $args{canondev} and $args{canondev} = $CANONDEV;
# Double check the key pairs for stuff we recognise
my @sane_keys = qw(aliases canondev fstab mtab);
my %sane_args;
@sane_args{@sane_keys} = delete @args{@sane_keys};
scalar keys %args and croak( "Unrecognised parameter(s) '" . join( "', '", sort keys %args ) . "' passed to module $class" );
my $self = {%sane_args};
# Filesystem property aliases - unless caller knows better ...
defined $self->{aliases}
or $self->{aliases} = {
device => [qw(fs_spec dev)],
filesystem => [qw(fs_file mount_point)],
mount_point => [qw(fs_file filesystem)],
type => [qw(fs_vfstype vfs)],
format => [qw(fs_vfstype vfs vfstype)],
options => [qw(fs_mntops)],
check_frequency => [qw(fs_freq)],
check_order => [qw(fs_passno)],
boot_order => [qw(fs_mntno)],
volume => [qw(fs_volume fs_vol vol)],
label => [qw(fs_label)],
};
# Debug
DUMP( '$self', $self ) if (DEBUG);
$self->{filesystems} = $FsPlugin->new(%sane_args);
# Maybe upchuck a little
croak "Unable to create object for OS type '$self->{osname}'" unless ( $self->{filesystems} );
# Bless and return
bless( $self, $class );
return $self;
}
sub filesystems
{
my $self = shift;
unless ( defined( _INSTANCE( $self, __PACKAGE__ ) ) )
{
unshift @_, $self unless ( 0 == ( scalar(@_) % 2 ) );
$self = __PACKAGE__->new();
}
# Check we've got something sane passed
@_ % 2 and croak 'Odd number of elements passed when even number was expected';
my $params = {@_};
for my $param ( keys %{$params} )
{
croak "Illegal paramater '$param' passed to filesystems() method"
unless grep( m/^$param$/, qw(mounted unmounted special device regular) );
}
# Invert logic for regular
if ( exists $params->{regular} )
{
delete $params->{regular};
exists( $params->{special} )
and carp("Mutual exclusive parameters 'special' and 'regular' specified together");
$params->{special} = SPECIAL;
}
my @filesystems = ();
# Return list of all filesystems
keys %{$params} or return sort( keys( %{ $self->{filesystems} } ) );
for my $fsname ( sort( keys( %{ $self->{filesystems} } ) ) )
{
for my $requirement ( keys( %{$params} ) )
{
my $fs = $self->{filesystems}->{$fsname};
my $fsreqname =
( !exists $fs->{$requirement} and exists $self->{aliases}->{$requirement} )
? first { exists $fs->{$_} } @{ $self->{aliases}->{$requirement} }
: $requirement;
defined $params->{$requirement}
and exists $fs->{$fsreqname}
and $fs->{$fsreqname} eq $params->{$requirement}
and push( @filesystems, $fsname )
and last;
push( @filesystems, $fsname ) and last
unless defined( $params->{$requirement} )
or exists( $fs->{$fsreqname} );
}
}
# Return
return @filesystems;
}
sub supported
{
return $Supported;
}
sub mounted_filesystems
{
return $_[0]->filesystems( mounted => 1 );
}
sub unmounted_filesystems
{
return $_[0]->filesystems( unmounted => 1 );
}
sub special_filesystems
{
return $_[0]->filesystems( special => 1 );
}
sub regular_filesystems
{
return $_[0]->filesystems( special => SPECIAL );
}
sub DESTROY { }
sub AUTOLOAD
{
my ( $self, $fsname ) = @_;
croak "$self is not an object" unless ( blessed($self) );
croak "No filesystem passed where expected" unless ($fsname);
( my $name = $AUTOLOAD ) =~ s/.*://;
# No such filesystem
exists $self->{filesystems}->{$fsname} or croak "No such filesystem";
# Found the property
my $fs = $self->{filesystems}->{$fsname};
exists $fs->{$name} and return $fs->{$name};
# Didn't find the property, but check any aliases
exists $self->{aliases}->{$name}
and $name = first { exists $fs->{$_} } @{ $self->{aliases}->{$name} }
and return $fs->{$name};
return;
}
sub TRACE
{
return unless DEBUG;
warn( $_[0] );
}
sub DUMP
{
return unless DEBUG;
eval {
require Data::Dumper;
warn( shift() . ': ' . Data::Dumper::Dumper( shift() ) );
};
}
1;
=pod
=head1 NAME
Sys::Filesystem - Retrieve list of filesystems and their properties
=head1 SYNOPSIS
use strict;
use Sys::Filesystem ();
# Method 1
my $fs = Sys::Filesystem->new();
my @filesystems = $fs->filesystems();
for (@filesystems)
{
printf("%s is a %s filesystem mounted on %s\n",
$fs->mount_point($_),
$fs->format($_),
$fs->device($_)
);
}
# Method 2
my $weird_fs = Sys::Filesystem->new(
fstab => '/etc/weird/vfstab.conf',
mtab => '/etc/active_mounts',
xtab => '/etc/nfs/mounts'
);
my @weird_filesystems = $weird_fs->filesystems();
# Method 3 (nice but naughty)
my @filesystems = Sys::Filesystem->filesystems();
=head1 DESCRIPTION
Sys::Filesystem is intended to be a portable interface to list and query
filesystem names and their properties. At the time of writing there were only
Solaris and Win32 modules available on CPAN to perform this kind of operation.
This module hopes to provide a consistent API to list all, mounted, unmounted
and special filesystems on a system, and query as many properties as possible
with common aliases wherever possible.
=head1 INHERITANCE
Sys::Filesystem
ISA UNIVERSAL
=head1 METHODS
=over 4
=item new
Creates a new Sys::Filesystem object. C<new> accepts following optional key
value pairs to help or force where mount information is gathered from. These
values are not otherwise defaulted by the main Sys::Filesystem object, but
left to the platform specific helper modules to determine as an exercise of
common sense.
=over 4
=item canondev
Specify whether device path's shall be resolved when they're a symbolic
link.
C<$Sys::Filesystem::CANONDEV> is used when no key C<canondev> is passed.
=item fstab
Specify the full path and filename of the filesystem table (or fstab for
short). Not all platforms have such a file and so this option may be
ignored on some systems.
C<$Sys::Filesystem::FSTAB> is used when no key C<fstab> is passed.
=item mtab
Specify the full path and filename of the mounted filesystem table (or mtab
for short). Not all platforms have such a file and so this option may be
ignored on some systems.
C<$Sys::Filesystem::MTAB> is used when no key C<mtab> is passed.
=item xtab
B<DEPRECIATED> Specify the full path and filename of the mounted NFS
filesystem table (or xtab for short). This is usually only pertinant
to Unix bases systems. Not all helper modules will query NFS mounts
as a separate exercise, and therefore this option may be ignored on
some systems.
B<None> of the OS plugins use that tunable (anymore?), so it now a warning
is raised when it's used. The entire support will be removed not before
2015. Once that happened, using C<xtab> will raise an exception.
=item aliases
Overrides internal aliasing table used to match queries against OS
plugin. This should be used only when dealing with closed source platform
helper module(s).
=back
=item supported
Returns true if the operating system is supported by Sys::Filesystem.
Unsupported operating systems may get less information, e.g. the mount
state couldn't determined or which file system type is special ins't
known.
=back
=head2 Listing Filesystems
=over 4
=item filesystems()
Returns a list of all filesystem. May accept an optional list of key pair
values in order to filter/restrict the results which are returned. The
restrictions are evaluated to match as much as possible, so asking for
regular and special file system (or mounted and special file systems),
you'll get all.
For better understanding, please imagine the parameters like:
@fslist = $fs->filesystems( mounted => 1, special => 1 );
# results similar as
SELECT mountpoint FROM filesystems WHERE mounted = 1 OR special = 1
If you need other selection choices, please take a look at L<DBD::Sys>.
Valid values are as follows:
=over 4
=item device => "string"
Returns only filesystems that are mounted using the device of "string".
For example:
my $fdd_filesytem = Sys::Filesystem->filesystems(device => "/dev/fd0");
=item mounted => 1
Returns only filesystems which can be confirmed as actively mounted.
(Filesystems which are mounted).
The mounted_filesystems() method is an alias for this syntax.
=item unmounted => 1
Returns only filesystems which cannot be confirmed as actively mounted.
(Filesystems which are not mounted).
The unmounted_filesystems() method is an alias for this syntax.
=item special => 1
Returns only filesystems which are regarded as special in some way. A
filesystem is marked as special by the operating specific helper
module. For example, a tmpfs type filesystem on one operating system
might be regarded as a special filesystem, but not on others. Consult
the documentation of the operating system specific helper module for
further information about your system. (Sys::Filesystem::Linux for Linux
or Sys::Filesystem::Solaris for Solaris etc).
This parameter is mutually exclusive to C<regular>.
The special_filesystems() method is an alias for this syntax.
=item regular => 1
Returns only fileystems which are not regarded as special. (Normal
filesystems).
This parameter is mutually exclusive to C<special>.
The regular_filesystems() method is an alias for this syntax.
=back
=item mounted_filesystems()
Returns a list of all filesystems which can be verified as currently
being mounted.
=item unmounted_filesystems()
Returns a list of all filesystems which cannot be verified as currently
being mounted.
=item special_filesystems()
Returns a list of all fileystems which are considered special. This will
usually contain meta and swap partitions like /proc and /dev/shm on Linux.
=item regular_filesystems()
Returns a list of all filesystems which are not considered to be special.
=back
=head2 Filesystem Properties
Available filesystem properties and their names vary wildly between platforms.
Common aliases have been provided wherever possible. You should check the
documentation of the specific platform helper module to list all of the
properties which are available for that platform. For example, read the
Sys::Filesystem::Linux documentation for a list of all filesystem properties
available to query under Linux.
=over 4
=item mount_point() or filesystem()
Returns the friendly name of the filesystem. This will usually be the same
name as appears in the list returned by the filesystems() method.
=item mounted()
Returns boolean true if the filesystem is mounted.
=item label()
Returns the fileystem label.
This functionality may need to be retrofitted to some original OS specific
helper modules as of Sys::Filesystem 1.12.
=item volume()
Returns the volume that the filesystem belongs to or is mounted on.
This functionality may need to be retrofitted to some original OS specific
helper modules as of Sys::Filesystem 1.12.
=item device()
Returns the physical device that the filesystem is connected to.
=item special()
Returns boolean true if the filesystem type is considered "special".
=item type() or format()
Returns the type of filesystem format. fat32, ntfs, ufs, hpfs, ext3, xfs etc.
=item options()
Returns the options that the filesystem was mounted with. This may commonly
contain information such as read-write, user and group settings and
permissions.
=item mount_order()
Returns the order in which this filesystem should be mounted on boot.
=item check_order()
Returns the order in which this filesystem should be consistency checked
on boot.
=item check_frequency()
Returns how often this filesystem is checked for consistency.
=back
=head1 OS SPECIFIC HELPER MODULES
=head2 Dummy
The Dummy module is there to provide a default failover result to the main
Sys::Filesystem module if no suitable platform specific module can be found
or successfully loaded. This is the last module to be tried, in order of
platform, Unix (if not on Win32), and then Dummy.
=head2 Unix
The Unix module is intended to provide a "best guess" failover result to the
main Sys::Filesystem module if no suitable platform specific module can be
found, and the platform is not 'MSWin32'.
This module requires additional work to improve it's guestimation abilities.
=head2 Darwin
First written by Christian Renz <crenz@web42.com>.
=head2 Win32
Provides C<mount_point> and C<device> of mounted filesystems on Windows.
=head2 AIX
Please be aware that the AIX /etc/filesystems file has both a "type" and
"vfs" field. The "type" field should not be confused with the filesystem
format/type (that is stored in the "vfs" field). You may wish to use the
"format" field when querying for filesystem types, since it is aliased to
be more reliable accross different platforms.
=head2 Other
Linux, Solaris, Cygwin, FreeBSD, NetBSD, HP-UX.
=head2 OS Identifiers
The following list is taken from L<perlport>. Please refer to the original
source for the most up to date version. This information should help anyone
who wishes to write a helper module for a new platform. Modules should have
the same name as ^O in title caps. Thus 'openbsd' becomes 'Openbsd.pm'.
=head1 REQUIREMENTS
Sys::Filesystem requires Perl >= 5.6 to run.
=head1 TODO
Add support for Tru64, MidnightBSD, Haiku, Minix, DragonflyBSD and OpenBSD.
Please contact me if you would like to provide code for these operating
systems.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Sys::Filesystem
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sys-Filesystem>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Sys-Filesystem>
=item * CPAN Ratings
L<http://cpanratings.perl.org/s/Sys-Filesystem>
=item * Search CPAN
L<http://search.cpan.org/dist/Sys-Filesystem/>
=back
=head1 SEE ALSO
L<perlport>, L<Solaris::DeviceTree>, L<Win32::DriveInfo>
=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 ACKNOWLEDGEMENTS
See CREDITS in the distribution tarball.
=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
|