line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# $Id$ |
4
|
|
|
|
|
|
|
# Sys::Filesystem - Retrieve list of filesystems and their properties |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright 2004,2005,2006 Nicola Worthington |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
|
|
|
|
# you may not use this file except in compliance with the License. |
10
|
|
|
|
|
|
|
# You may obtain a copy of the License at |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software |
15
|
|
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
|
|
|
|
# See the License for the specific language governing permissions and |
18
|
|
|
|
|
|
|
# limitations under the License. |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
############################################################ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
package Sys::Filesystem::Linux; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# vim:ts=4:sw=4:tw=78 |
25
|
|
|
|
|
|
|
|
26
|
6
|
|
|
6
|
|
6312
|
use 5.008001; |
|
6
|
|
|
|
|
25
|
|
|
6
|
|
|
|
|
260
|
|
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
6
|
|
33
|
use strict; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
174
|
|
29
|
6
|
|
|
6
|
|
33
|
use warnings; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
261
|
|
30
|
6
|
|
|
6
|
|
30
|
use vars qw($VERSION @ISA); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
511
|
|
31
|
|
|
|
|
|
|
|
32
|
6
|
|
|
6
|
|
49
|
use Carp qw(croak); |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
473
|
|
33
|
6
|
|
|
6
|
|
34
|
use Cwd 'abs_path'; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
255
|
|
34
|
6
|
|
|
6
|
|
32
|
use IO::File (); |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
173
|
|
35
|
6
|
|
|
6
|
|
32
|
use Sys::Filesystem::Unix (); |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
4258
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$VERSION = '1.406'; |
38
|
|
|
|
|
|
|
@ISA = qw(Sys::Filesystem::Unix); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub version() |
41
|
|
|
|
|
|
|
{ |
42
|
0
|
|
|
0
|
1
|
0
|
return $VERSION; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Default fstab and mtab layout |
46
|
|
|
|
|
|
|
my @keys = qw(fs_spec fs_file fs_vfstype fs_mntops fs_freq fs_passno); |
47
|
|
|
|
|
|
|
my %special_fs = ( |
48
|
|
|
|
|
|
|
binfmt_misc => 1, |
49
|
|
|
|
|
|
|
debugfs => 1, |
50
|
|
|
|
|
|
|
devpts => 1, |
51
|
|
|
|
|
|
|
fusectl => 1, |
52
|
|
|
|
|
|
|
'fuse.gvfs-fuse-daemon' => 1, |
53
|
|
|
|
|
|
|
mini_fo => 1, |
54
|
|
|
|
|
|
|
nfsd => 1, |
55
|
|
|
|
|
|
|
proc => 1, |
56
|
|
|
|
|
|
|
procbususb => 1, |
57
|
|
|
|
|
|
|
securityfs => 1, |
58
|
|
|
|
|
|
|
swap => 1, |
59
|
|
|
|
|
|
|
sysfs => 1, |
60
|
|
|
|
|
|
|
tmpfs => 1, |
61
|
|
|
|
|
|
|
udev => 1, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new |
65
|
|
|
|
|
|
|
{ |
66
|
9
|
50
|
|
9
|
0
|
47
|
ref( my $class = shift ) && croak 'Class name required'; |
67
|
9
|
|
|
|
|
32
|
my %args = @_; |
68
|
9
|
|
|
|
|
39
|
my $self = bless( {}, $class ); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Defaults |
71
|
9
|
|
50
|
|
|
66
|
$args{fstab} ||= '/etc/fstab'; |
72
|
9
|
50
|
33
|
|
|
1103
|
$args{mtab} ||= -r '/proc/mounts' ? '/proc/mounts' : '/etc/mtab'; |
73
|
|
|
|
|
|
|
#$args{xtab} ||= '/etc/lib/nfs/xtab'; |
74
|
9
|
100
|
|
|
|
52
|
$args{canondev} and $self->{canondev} = 1; |
75
|
|
|
|
|
|
|
|
76
|
9
|
|
|
|
|
188
|
local $/ = "\n"; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Read the fstab |
79
|
9
|
50
|
|
|
|
107
|
if ( my $fstab = IO::File->new( $args{fstab}, 'r' ) ) |
80
|
|
|
|
|
|
|
{ |
81
|
9
|
|
|
|
|
2195
|
while (<$fstab>) |
82
|
|
|
|
|
|
|
{ |
83
|
9
|
50
|
33
|
|
|
147
|
next if ( /^\s*#/ || /^\s*$/ ); |
84
|
0
|
|
|
|
|
0
|
my @vals = split( ' ', $_ ); |
85
|
0
|
0
|
|
|
|
0
|
$vals[0] =~ /^\s*LABEL=(.+)\s*$/ |
86
|
|
|
|
|
|
|
and $self->{ $vals[1] }->{label} = $1; |
87
|
0
|
0
|
0
|
|
|
0
|
$args{canondev} and -l $vals[0] and $vals[0] = abs_path( $vals[0] ); |
88
|
0
|
|
|
|
|
0
|
$self->{ $vals[1] }->{mount_point} = $vals[1]; |
89
|
0
|
|
|
|
|
0
|
$self->{ $vals[1] }->{device} = $vals[0]; |
90
|
0
|
|
|
|
|
0
|
$self->{ $vals[1] }->{unmounted} = 1; |
91
|
0
|
0
|
|
|
|
0
|
defined $special_fs{ $vals[2] } |
92
|
|
|
|
|
|
|
and $self->{ $vals[1] }->{special} = 1; |
93
|
0
|
|
|
|
|
0
|
@{ $self->{ $vals[1] } }{@keys} = @vals; |
|
0
|
|
|
|
|
0
|
|
94
|
|
|
|
|
|
|
} |
95
|
9
|
|
|
|
|
70
|
$fstab->close(); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else |
98
|
|
|
|
|
|
|
{ |
99
|
0
|
|
|
|
|
0
|
croak "Unable to open fstab file ($args{fstab})\n"; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Read the mtab |
103
|
9
|
50
|
|
|
|
267
|
unless ( $self->readMntTab( $args{mtab}, \@keys, [ 0, 1, 2 ], \%special_fs ) ) |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
|
|
0
|
croak "Unable to open fstab file ($args{mtab})\n"; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
9
|
|
|
|
|
53
|
delete $self->{canondev}; |
109
|
|
|
|
|
|
|
|
110
|
9
|
|
|
|
|
114
|
$self; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=pod |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 NAME |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Sys::Filesystem::Linux - Return Linux filesystem information to Sys::Filesystem |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 SYNOPSIS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
See L. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 INHERITANCE |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Sys::Filesystem::Linux |
128
|
|
|
|
|
|
|
ISA Sys::Filesystem::Unix |
129
|
|
|
|
|
|
|
ISA UNIVERSAL |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 METHODS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=over 4 |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item version () |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Return the version of the (sub)module. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=back |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
The following is a list of filesystem properties which may |
144
|
|
|
|
|
|
|
be queried as methods through the parent L object. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=over 4 |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item fs_spec |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Describes the block special device or remote filesystem to be mounted. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
For ordinary mounts it will hold (a link to) a block special device |
153
|
|
|
|
|
|
|
node (as created by L) for the device to be mounted, like |
154
|
|
|
|
|
|
|
'/dev/cdrom' or '/dev/sdb7'. For NFS mounts one will have :, |
155
|
|
|
|
|
|
|
e.g., 'knuth.aeb.nl:/'. For procfs, use 'proc'. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Instead of giving the device explicitly, one may indicate the (ext2 or |
158
|
|
|
|
|
|
|
xfs) filesystem that is to be mounted by its UUID or volume label (cf. |
159
|
|
|
|
|
|
|
L or L), writing LABEL= |
160
|
|
|
|
|
|
|
e.g., 'LABEL=Boot' or 'UUID=3e6be9de-8139-11d1-9106-a43f08d823a6'. |
161
|
|
|
|
|
|
|
This will make the system more robust: adding or removing a SCSI disk |
162
|
|
|
|
|
|
|
changes the disk device name but not the filesystem volume label. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item fs_file |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Describes the mount point for the filesystem. For swap partitions, |
167
|
|
|
|
|
|
|
this field should be specified as 'none'. If the name of the mount |
168
|
|
|
|
|
|
|
point contains spaces these can be escaped as '\040'. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item fs_vfstype |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Dscribes the type of the filesystem. |
173
|
|
|
|
|
|
|
Linux supports lots of filesystem types, such as adfs, affs, autofs, |
174
|
|
|
|
|
|
|
coda, coherent, cramfs, devpts, efs, ext2, ext3, hfs, hpfs, iso9660, |
175
|
|
|
|
|
|
|
jfs, minix, msdos, ncpfs, nfs, ntfs, proc, qnx4, reiserfs, romfs, |
176
|
|
|
|
|
|
|
smbfs, sysv, tmpfs, udf, ufs, umsdos, vfat, xenix, xfs, and possibly |
177
|
|
|
|
|
|
|
others. For more details, see L. For the filesystems currently |
178
|
|
|
|
|
|
|
supported by the running kernel, see /proc/filesystems. An entry swap |
179
|
|
|
|
|
|
|
denotes a file or partition to be used for swapping, cf. L. An |
180
|
|
|
|
|
|
|
entry ignore causes the line to be ignored. This is useful to show |
181
|
|
|
|
|
|
|
disk partitions which are currently unused. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item fs_mntops |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Describes the mount options associated with the filesystem. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
It is formatted as a comma separated list of options. It contains at |
188
|
|
|
|
|
|
|
least the type of mount plus any additional options appropriate to the |
189
|
|
|
|
|
|
|
filesystem type. For documentation on the available options for non- |
190
|
|
|
|
|
|
|
nfs file systems, see L. For documentation on all nfs-specific |
191
|
|
|
|
|
|
|
options have a look at L. Common for all types of file system are |
192
|
|
|
|
|
|
|
the options 'noauto' (do not mount when 'mount -a' is given, e.g., at |
193
|
|
|
|
|
|
|
boot time), 'user' (allow a user to mount), and 'owner' (allow |
194
|
|
|
|
|
|
|
device owner to mount), and '_netdev' (device requires network to be |
195
|
|
|
|
|
|
|
available). The 'owner' and '_netdev' options are Linux-specific. |
196
|
|
|
|
|
|
|
For more details, see L. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item fs_freq |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Used for these filesystems by the |
201
|
|
|
|
|
|
|
L command to determine which filesystems need to be dumped. If |
202
|
|
|
|
|
|
|
the fifth field is not present, a value of zero is returned and dump |
203
|
|
|
|
|
|
|
will assume that the filesystem does not need to be dumped. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item fs_passno |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Used by the L program to determine the order in which filesystem |
208
|
|
|
|
|
|
|
checks are done at reboot time. The |
209
|
|
|
|
|
|
|
root filesystem should be specified with a fs_passno of 1, and other |
210
|
|
|
|
|
|
|
filesystems should have a fs_passno of 2. Filesystems within a drive |
211
|
|
|
|
|
|
|
will be checked sequentially, but filesystems on different drives will |
212
|
|
|
|
|
|
|
be checked at the same time to utilize parallelism available in the |
213
|
|
|
|
|
|
|
hardware. If the sixth field is not present or zero, a value of zero |
214
|
|
|
|
|
|
|
is returned and fsck will assume that the filesystem does not need to |
215
|
|
|
|
|
|
|
be checked. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=back |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 SEE ALSO |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
L, L, L |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 VERSION |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
$Id$ |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 AUTHOR |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Nicola Worthington - L |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Jens Rehsack - L |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head1 COPYRIGHT |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Copyright 2004,2005,2006 Nicola Worthington. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Copyright 2009-2014 Jens Rehsack. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
This software is licensed under The Apache Software License, Version 2.0. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
L |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=cut |
244
|
|
|
|
|
|
|
|