line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Sys::Filesystem - Retrieve list of filesystems and their properties |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Copyright 2004,2005,2006 Nicola Worthington |
6
|
|
|
|
|
|
|
# Copyright 2008-2020 Jens Rehsack |
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
|
|
5910
|
use 5.008001; |
|
6
|
|
|
|
|
23
|
|
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
6
|
|
54
|
use strict; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
174
|
|
29
|
6
|
|
|
6
|
|
34
|
use warnings; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
199
|
|
30
|
6
|
|
|
6
|
|
33
|
use vars qw($VERSION); |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
404
|
|
31
|
6
|
|
|
6
|
|
2693
|
use parent qw(Sys::Filesystem::Unix); |
|
6
|
|
|
|
|
1742
|
|
|
6
|
|
|
|
|
40
|
|
32
|
|
|
|
|
|
|
|
33
|
6
|
|
|
6
|
|
313
|
use Carp qw(croak); |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
298
|
|
34
|
6
|
|
|
6
|
|
39
|
use Cwd 'abs_path'; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
214
|
|
35
|
6
|
|
|
6
|
|
39
|
use IO::File (); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
3043
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$VERSION = '1.407_001'; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub version() |
40
|
|
|
|
|
|
|
{ |
41
|
0
|
|
|
0
|
1
|
0
|
return $VERSION; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Default fstab and mtab layout |
45
|
|
|
|
|
|
|
my @keys = qw(fs_spec fs_file fs_vfstype fs_mntops fs_freq fs_passno); |
46
|
|
|
|
|
|
|
my %special_fs = ( |
47
|
|
|
|
|
|
|
binfmt_misc => 1, |
48
|
|
|
|
|
|
|
debugfs => 1, |
49
|
|
|
|
|
|
|
devpts => 1, |
50
|
|
|
|
|
|
|
fusectl => 1, |
51
|
|
|
|
|
|
|
'fuse.gvfs-fuse-daemon' => 1, |
52
|
|
|
|
|
|
|
mini_fo => 1, |
53
|
|
|
|
|
|
|
nfsd => 1, |
54
|
|
|
|
|
|
|
proc => 1, |
55
|
|
|
|
|
|
|
procbususb => 1, |
56
|
|
|
|
|
|
|
securityfs => 1, |
57
|
|
|
|
|
|
|
swap => 1, |
58
|
|
|
|
|
|
|
sysfs => 1, |
59
|
|
|
|
|
|
|
tmpfs => 1, |
60
|
|
|
|
|
|
|
udev => 1, |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
## no critic (Subroutines::RequireArgUnpacking) |
64
|
|
|
|
|
|
|
sub new |
65
|
|
|
|
|
|
|
{ |
66
|
9
|
50
|
|
9
|
0
|
36
|
ref(my $class = shift) && croak 'Class name required'; |
67
|
9
|
|
|
|
|
35
|
my %args = @_; |
68
|
9
|
|
|
|
|
26
|
my $self = bless({}, $class); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Defaults |
71
|
9
|
|
50
|
|
|
58
|
$args{fstab} ||= '/etc/fstab'; |
72
|
9
|
50
|
33
|
|
|
477
|
$args{mtab} ||= -r '/proc/mounts' ? '/proc/mounts' : '/etc/mtab'; |
73
|
|
|
|
|
|
|
#$args{xtab} ||= '/etc/lib/nfs/xtab'; |
74
|
9
|
100
|
|
|
|
35
|
$args{canondev} and $self->{canondev} = 1; |
75
|
|
|
|
|
|
|
|
76
|
9
|
|
|
|
|
56
|
local $/ = "\n"; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Read the fstab |
79
|
9
|
50
|
|
|
|
79
|
if (my $fstab = IO::File->new($args{fstab}, 'r')) |
80
|
|
|
|
|
|
|
{ |
81
|
9
|
|
|
|
|
2364
|
while (<$fstab>) |
82
|
|
|
|
|
|
|
{ |
83
|
9
|
50
|
33
|
|
|
168
|
next if (/^\s*#/ || /^\s*$/); |
84
|
0
|
|
|
|
|
0
|
my @vals = split(' ', $_); |
85
|
|
|
|
|
|
|
$vals[0] =~ /^\s*LABEL=(.+)\s*$/ |
86
|
0
|
0
|
|
|
|
0
|
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
|
|
|
|
|
|
|
defined $special_fs{$vals[2]} |
92
|
0
|
0
|
|
|
|
0
|
and $self->{$vals[1]}->{special} = 1; |
93
|
0
|
|
|
|
|
0
|
@{$self->{$vals[1]}}{@keys} = @vals; |
|
0
|
|
|
|
|
0
|
|
94
|
|
|
|
|
|
|
} |
95
|
9
|
|
|
|
|
86
|
$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
|
|
|
|
316
|
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
|
|
|
|
|
109
|
delete $self->{canondev}; |
109
|
|
|
|
|
|
|
|
110
|
9
|
|
|
|
|
60
|
return $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 AUTHOR |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Nicola Worthington - L |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Jens Rehsack - L |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 COPYRIGHT |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Copyright 2004,2005,2006 Nicola Worthington. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Copyright 2009-2020 Jens Rehsack. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
This software is licensed under The Apache Software License, Version 2.0. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
L |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=cut |