| 1 | |||||||||||
| 2 | package Filesys::Type; | ||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Exporter (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | $VERSION = 0.02; | |||||||||
| 9 | 1 | @ISA = qw (Exporter); | |||||||||
| 10 | #Give a hoot don't pollute, do not export more than needed by default | ||||||||||
| 11 | 1 | @EXPORT = qw (); | |||||||||
| 12 | 1 | @EXPORT_OK = qw (fstype case diagnose); | |||||||||
| 13 | 1 | %EXPORT_TAGS = (all => [qw(fstype case diagnose)]); | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | =head1 NAME | ||||||||||
| 18 | |||||||||||
| 19 | Filesys::Type - Portable way of determining the type of a file system. | ||||||||||
| 20 | |||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||
| 22 | |||||||||||
| 23 | use Filesys::Type qw(fstype); | ||||||||||
| 24 | |||||||||||
| 25 | ... | ||||||||||
| 26 | my $fs = '/mnt/hda7'; | ||||||||||
| 27 | warn "Not able to share with Windows" | ||||||||||
| 28 | if (fstype($fs) ne 'vfat'); | ||||||||||
| 29 | |||||||||||
| 30 | |||||||||||
| 31 | =head1 DESCRIPTION | ||||||||||
| 32 | |||||||||||
| 33 | This module provides a portable interface, either to Unix mount -n | ||||||||||
| 34 | or to Win32::filesys or to another native OS interface. | ||||||||||
| 35 | |||||||||||
| 36 | The module is pluggable, which will allow for other operating systems | ||||||||||
| 37 | to be added in future without needing to change the core module. | ||||||||||
| 38 | |||||||||||
| 39 | =head2 fstype | ||||||||||
| 40 | |||||||||||
| 41 | This exportable function takes a string, which is a file or directory | ||||||||||
| 42 | path, and returns the file system type, e.g. vfat, ntfs, ext2, etc. | ||||||||||
| 43 | Note that the exact string returned is operating system dependent. | ||||||||||
| 44 | |||||||||||
| 45 | =head2 case | ||||||||||
| 46 | |||||||||||
| 47 | This is another exportable function that returns the case sensitivity | ||||||||||
| 48 | of a file system. It either takes a file system type as returned by | ||||||||||
| 49 | fstype, or a path as input. It returns one of the following: | ||||||||||
| 50 | |||||||||||
| 51 | =over 4 | ||||||||||
| 52 | |||||||||||
| 53 | =item C<sensitive> | ||||||||||
| 54 | |||||||||||
| 55 | like Unix ext2, ext3, etc. | ||||||||||
| 56 | |||||||||||
| 57 | =item C<lower> | ||||||||||
| 58 | |||||||||||
| 59 | VMS ODS-2 filenames are case insensitive. System services return the | ||||||||||
| 60 | names in upper case, but the CRTL which provides globbing and the | ||||||||||
| 61 | command line interface turns to lower case. | ||||||||||
| 62 | |||||||||||
| 63 | =item C<insensitive> | ||||||||||
| 64 | |||||||||||
| 65 | This is the behaviour of Windows file systems, FAT16, FAT32 and NTFS. | ||||||||||
| 66 | The file names are case insensitive, i.e. foo, Foo and FOO refer to the | ||||||||||
| 67 | same file, but the initial case of the letters of the file name is | ||||||||||
| 68 | preserved from the time it was created. | ||||||||||
| 69 | |||||||||||
| 70 | =back | ||||||||||
| 71 | |||||||||||
| 72 | =head2 C<diagnose> | ||||||||||
| 73 | |||||||||||
| 74 | Use this to determine what went wrong if fstype returned undef. Returns | ||||||||||
| 75 | a string suitable for printing in a log or on stderr. | ||||||||||
| 76 | |||||||||||
| 77 | =head1 SECURITY | ||||||||||
| 78 | |||||||||||
| 79 | Note that some platforms use backtick shell commands to derive information | ||||||||||
| 80 | about the file systems. Be careful that a rogue user could execute | ||||||||||
| 81 | operating system commands by injecting into the path. | ||||||||||
| 82 | |||||||||||
| 83 | It is recommended only to pass in untainted strings. See perldoc perlsec | ||||||||||
| 84 | for details of running in taint mode, and for a description of how to untaint | ||||||||||
| 85 | a string passed in from outside. | ||||||||||
| 86 | |||||||||||
| 87 | =head1 BUGS | ||||||||||
| 88 | |||||||||||
| 89 | Please report bugs to http://rt.cpan.org. Post to bug-filesys-type@rt.cpan.org | ||||||||||
| 90 | |||||||||||
| 91 | |||||||||||
| 92 | =head1 HISTORY | ||||||||||
| 93 | |||||||||||
| 94 | 0.01 Sun Jun 12 2005 | ||||||||||
| 95 | - original version; created by ExtUtils::ModuleMaker 0.32 | ||||||||||
| 96 | |||||||||||
| 97 | 0.02 Fri Jul 08 2005 | ||||||||||
| 98 | - Change plugins to be OO. Add diagnostic facility to see | ||||||||||
| 99 | more about failing tests on some platforms. | ||||||||||
| 100 | |||||||||||
| 101 | =head1 AUTHOR | ||||||||||
| 102 | |||||||||||
| 103 | I. Williams | ||||||||||
| 104 | ivorw@cpan.org | ||||||||||
| 105 | |||||||||||
| 106 | =head1 COPYRIGHT | ||||||||||
| 107 | |||||||||||
| 108 | This program is free software; you can redistribute | ||||||||||
| 109 | it and/or modify it under the same terms as Perl itself. | ||||||||||
| 110 | |||||||||||
| 111 | The full text of the license can be found in the | ||||||||||
| 112 | LICENSE file included with this module. | ||||||||||
| 113 | |||||||||||
| 114 | |||||||||||
| 115 | =head1 SEE ALSO | ||||||||||
| 116 | |||||||||||
| 117 | L<Win32>. | ||||||||||
| 118 | |||||||||||
| 119 | =cut | ||||||||||
| 120 | |||||||||||
| 121 | 1 | ▶ | use Module::Pluggable instantiate => 'new'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 122 | 1 | our ($plugin) = grep {defined $_} __PACKAGE__->plugins; | |||||||||
| 123 | 1 | ▶ | warn "failed to detect suitable Filesys::Type::Plugin" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 124 | unless defined $plugin; | ||||||||||
| 125 | |||||||||||
| 126 | 5 | ▶ | sub fstype { | ||||||||
|
Subroutine
fstype: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 127 | 5 | $plugin->fstype(shift); | |||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | 1 | our %case_sensitivity = ( | |||||||||
| 131 | msdos => 'insensitive', | ||||||||||
| 132 | umsdos => 'insensitive', | ||||||||||
| 133 | vfat => 'insensitive', | ||||||||||
| 134 | ntfs => 'insensitive', | ||||||||||
| 135 | minix => 'sensitive', | ||||||||||
| 136 | xiafs => 'sensitive', | ||||||||||
| 137 | ext2 => 'sensitive', | ||||||||||
| 138 | ext3 => 'sensitive', | ||||||||||
| 139 | iso9660 => 'sensitive', | ||||||||||
| 140 | hpfs => 'sensitive', | ||||||||||
| 141 | sysv => 'sensitive', | ||||||||||
| 142 | nfs => 'sensitive', | ||||||||||
| 143 | smb => 'insensitive', | ||||||||||
| 144 | ncpfs => 'insensitive', | ||||||||||
| 145 | FAT => 'insensitive', | ||||||||||
| 146 | FAT32 => 'insensitive', | ||||||||||
| 147 | CDFS => 'insensitive', | ||||||||||
| 148 | NTFS => 'insensitive', | ||||||||||
| 149 | 'ODS-2' => 'lower', | ||||||||||
| 150 | ); | ||||||||||
| 151 | |||||||||||
| 152 | 2 | ▶ | sub case { | ||||||||
|
Subroutine
case: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 153 | 2 | my $fs = shift; | |||||||||
| 154 | |||||||||||
| 155 | 2 | ▶ | return $case_sensitivity{$fs} if exists $case_sensitivity{$fs}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 156 | 2 | $fs = fstype($fs); | |||||||||
| 157 | |||||||||||
| 158 | 2 | $case_sensitivity{$fs}; | |||||||||
| 159 | } | ||||||||||
| 160 | |||||||||||
| 161 | 1 | ▶ | sub diagnose { | ||||||||
|
Subroutine
diagnose: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 162 | 1 | $plugin->diagnose; | |||||||||
| 163 | } | ||||||||||
| 164 | |||||||||||
| 165 | 1 | 1; #this line is important and will help the module return a true value | |||||||||
| 166 | __END__ | ||||||||||