| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright (c) 2014, cPanel, Inc. |
|
2
|
|
|
|
|
|
|
# All rights reserved. |
|
3
|
|
|
|
|
|
|
# http://cpanel.net/ |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under the same |
|
6
|
|
|
|
|
|
|
# terms as Perl itself. See the LICENSE file for further details. |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Filesys::POSIX::VFS; |
|
9
|
|
|
|
|
|
|
|
|
10
|
25
|
|
|
25
|
|
81
|
use strict; |
|
|
25
|
|
|
|
|
23
|
|
|
|
25
|
|
|
|
|
542
|
|
|
11
|
25
|
|
|
25
|
|
71
|
use warnings; |
|
|
25
|
|
|
|
|
21
|
|
|
|
25
|
|
|
|
|
444
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
25
|
|
|
25
|
|
71
|
use Filesys::POSIX::Bits; |
|
|
25
|
|
|
|
|
22
|
|
|
|
25
|
|
|
|
|
5876
|
|
|
14
|
25
|
|
|
25
|
|
105
|
use Filesys::POSIX::Path (); |
|
|
25
|
|
|
|
|
19
|
|
|
|
25
|
|
|
|
|
276
|
|
|
15
|
25
|
|
|
25
|
|
8077
|
use Filesys::POSIX::VFS::Inode (); |
|
|
25
|
|
|
|
|
36
|
|
|
|
25
|
|
|
|
|
377
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
25
|
|
|
25
|
|
81
|
use Filesys::POSIX::Error qw(throw); |
|
|
25
|
|
|
|
|
23
|
|
|
|
25
|
|
|
|
|
14670
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
|
20
|
40
|
|
|
40
|
0
|
277
|
return bless { |
|
21
|
|
|
|
|
|
|
'mounts' => [], |
|
22
|
|
|
|
|
|
|
'devices' => {}, |
|
23
|
|
|
|
|
|
|
'vnodes' => {} |
|
24
|
|
|
|
|
|
|
}, |
|
25
|
|
|
|
|
|
|
shift; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub statfs { |
|
29
|
17
|
|
|
17
|
0
|
78
|
my ( $self, $start, %opts ) = @_; |
|
30
|
17
|
|
|
|
|
12
|
my $inode = $start; |
|
31
|
17
|
|
|
|
|
10
|
my $ret; |
|
32
|
|
|
|
|
|
|
|
|
33
|
17
|
|
|
|
|
34
|
while ( $inode->{'vnode'} ) { |
|
34
|
0
|
|
|
|
|
0
|
$inode = $inode->{'vnode'}; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
17
|
100
|
|
|
|
21
|
if ( $opts{'exact'} ) { |
|
38
|
11
|
|
|
|
|
18
|
$ret = $self->{'vnodes'}->{$inode}; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
else { |
|
41
|
6
|
|
|
|
|
12
|
$ret = $self->{'devices'}->{ $inode->{'dev'} }; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
17
|
100
|
|
|
|
24
|
unless ($ret) { |
|
45
|
4
|
100
|
|
|
|
10
|
throw &Errno::ENXIO unless $opts{'silent'}; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
16
|
|
|
|
|
35
|
return $ret; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub mountlist { |
|
52
|
1
|
|
|
1
|
0
|
1
|
my ($self) = @_; |
|
53
|
1
|
|
|
|
|
1
|
return @{ $self->{'mounts'} }; |
|
|
1
|
|
|
|
|
3
|
|
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# |
|
57
|
|
|
|
|
|
|
# It should be noted that any usage of pathnames in this module are entirely |
|
58
|
|
|
|
|
|
|
# symbolic and are not used for canonical purposes. The higher-level |
|
59
|
|
|
|
|
|
|
# filesystem layer should take on the responsibility of providing both the |
|
60
|
|
|
|
|
|
|
# canonically-correct absolute pathnames for mount points, and helping locate |
|
61
|
|
|
|
|
|
|
# the appropriate VFS mount point for querying purposes. |
|
62
|
|
|
|
|
|
|
# |
|
63
|
|
|
|
|
|
|
sub mount { |
|
64
|
52
|
|
|
52
|
0
|
108
|
my ( $self, $dev, $path, $mountpoint, %data ) = @_; |
|
65
|
|
|
|
|
|
|
|
|
66
|
52
|
100
|
|
|
|
51
|
if ( grep { $_->{'dev'} eq $dev } @{ $self->{'mounts'} } ) { |
|
|
20
|
|
|
|
|
52
|
|
|
|
52
|
|
|
|
|
246
|
|
|
67
|
2
|
|
|
|
|
6
|
throw &Errno::EBUSY; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
50
|
|
50
|
|
|
259
|
$data{'special'} ||= scalar $dev; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# |
|
73
|
|
|
|
|
|
|
# Generate a generic BSD-style filesystem type string. |
|
74
|
|
|
|
|
|
|
# |
|
75
|
50
|
|
|
|
|
120
|
my $type = lc ref $dev; |
|
76
|
50
|
|
|
|
|
299
|
$type =~ s/^([a-z_][a-z0-9_]*::)*//; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# |
|
79
|
|
|
|
|
|
|
# Create a vnode record munged from the mountpoint and new |
|
80
|
|
|
|
|
|
|
# filesystem root. |
|
81
|
|
|
|
|
|
|
# |
|
82
|
50
|
|
|
|
|
245
|
my $vnode = Filesys::POSIX::VFS::Inode->new( $mountpoint, $dev->{'root'} ); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# |
|
85
|
|
|
|
|
|
|
# Associate the mountpoint and filesystem roots with this vnode. |
|
86
|
|
|
|
|
|
|
# |
|
87
|
50
|
|
|
|
|
106
|
$mountpoint->{'vnode'} = $vnode; |
|
88
|
50
|
|
|
|
|
75
|
$dev->{'root'}->{'vnode'} = $vnode; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# |
|
91
|
|
|
|
|
|
|
# Generate the mount record. |
|
92
|
|
|
|
|
|
|
# |
|
93
|
|
|
|
|
|
|
my $mount = { |
|
94
|
|
|
|
|
|
|
'mountpoint' => $mountpoint, |
|
95
|
|
|
|
|
|
|
'root' => $dev->{'root'}, |
|
96
|
|
|
|
|
|
|
'special' => $data{'special'}, |
|
97
|
|
|
|
|
|
|
'dev' => $dev, |
|
98
|
|
|
|
|
|
|
'type' => $type, |
|
99
|
|
|
|
|
|
|
'path' => $path, |
|
100
|
|
|
|
|
|
|
'vnode' => $vnode, |
|
101
|
|
|
|
|
|
|
|
|
102
|
50
|
|
|
|
|
145
|
'flags' => { map { $_ => $data{$_} } grep { $_ ne 'special' } keys %data } |
|
|
44
|
|
|
|
|
157
|
|
|
|
94
|
|
|
|
|
230
|
|
|
103
|
|
|
|
|
|
|
}; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# |
|
106
|
|
|
|
|
|
|
# Store the mount record in the ordered mount list. |
|
107
|
|
|
|
|
|
|
# |
|
108
|
50
|
|
|
|
|
63
|
push @{ $self->{'mounts'} }, $mount; |
|
|
50
|
|
|
|
|
98
|
|
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# |
|
111
|
|
|
|
|
|
|
# Associate the vnode with the mount rcord. |
|
112
|
|
|
|
|
|
|
# |
|
113
|
50
|
|
|
|
|
121
|
$self->{'vnodes'}->{$vnode} = $mount; |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# |
|
116
|
|
|
|
|
|
|
# Finally, associate the filesystem with the mount record. |
|
117
|
|
|
|
|
|
|
# |
|
118
|
50
|
|
|
|
|
99
|
$self->{'devices'}->{$dev} = $mount; |
|
119
|
|
|
|
|
|
|
|
|
120
|
50
|
|
|
|
|
186
|
return $self; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub vnode { |
|
124
|
1854
|
|
|
1854
|
0
|
1369
|
my ( $self, $start ) = @_; |
|
125
|
1854
|
|
|
|
|
1263
|
my $inode = $start; |
|
126
|
|
|
|
|
|
|
|
|
127
|
1854
|
100
|
|
|
|
2357
|
return undef unless $inode; |
|
128
|
|
|
|
|
|
|
|
|
129
|
1760
|
|
|
|
|
2393
|
while ( $inode->{'vnode'} ) { |
|
130
|
207
|
|
|
|
|
332
|
$inode = $inode->{'vnode'}; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
1760
|
|
|
|
|
2273
|
my $mount = $self->{'devices'}->{ $inode->{'dev'} }; |
|
134
|
|
|
|
|
|
|
|
|
135
|
1760
|
100
|
|
|
|
2157
|
if ( $mount->{'flags'}->{'noexec'} ) { |
|
136
|
9
|
|
|
|
|
8
|
$inode->{'mode'} &= ~$S_IX; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
1760
|
100
|
|
|
|
2063
|
if ( $mount->{'flags'}->{'nosuid'} ) { |
|
140
|
9
|
|
|
|
|
5
|
$inode->{'mode'} &= ~$S_ISUID; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
1760
|
|
|
|
|
1777
|
foreach (qw(uid gid)) { |
|
144
|
3520
|
100
|
|
|
|
4718
|
if ( defined $mount->{'flags'}->{$_} ) { |
|
145
|
66
|
|
|
|
|
78
|
$inode->{$_} = $mount->{'flags'}->{$_}; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
1760
|
|
|
|
|
2897
|
return $inode; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub unmount { |
|
153
|
4
|
|
|
4
|
0
|
3
|
my ( $self, $mount ) = @_; |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# |
|
156
|
|
|
|
|
|
|
# First, check to see that the filesystem mount record found is a |
|
157
|
|
|
|
|
|
|
# dependency for another mounted filesystem. |
|
158
|
|
|
|
|
|
|
# |
|
159
|
4
|
|
|
|
|
3
|
foreach ( @{ $self->{'mounts'} } ) { |
|
|
4
|
|
|
|
|
8
|
|
|
160
|
12
|
100
|
|
|
|
18
|
next if $_ == $mount; |
|
161
|
|
|
|
|
|
|
|
|
162
|
8
|
100
|
|
|
|
21
|
throw &Errno::EBUSY if $_->{'mountpoint'}->{'dev'} == $mount->{'dev'}; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# |
|
166
|
|
|
|
|
|
|
# Pluck the filesystem from the mount list. |
|
167
|
|
|
|
|
|
|
# |
|
168
|
3
|
|
|
|
|
7
|
for ( my $i = 0; $self->{'mounts'}->[$i]; $i++ ) { |
|
169
|
9
|
100
|
|
|
|
20
|
next unless $self->{'mounts'}->[$i] eq $mount; |
|
170
|
3
|
|
|
|
|
2
|
splice @{ $self->{'mounts'} }, $i; |
|
|
3
|
|
|
|
|
5
|
|
|
171
|
3
|
|
|
|
|
4
|
last; |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
# |
|
175
|
|
|
|
|
|
|
# Untie the vnode reference from its original mount point and root. |
|
176
|
|
|
|
|
|
|
# |
|
177
|
3
|
|
|
|
|
4
|
delete $mount->{'mountpoint'}->{'vnode'}; |
|
178
|
3
|
|
|
|
|
2
|
delete $mount->{'root'}->{'vnode'}; |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# |
|
181
|
|
|
|
|
|
|
# Break references to the mount record from the per-vnode hash. |
|
182
|
|
|
|
|
|
|
# |
|
183
|
3
|
|
|
|
|
6
|
delete $self->{'vnodes'}->{ $mount->{'vnode'} }; |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
# |
|
186
|
|
|
|
|
|
|
# Kill references to the mount record from the per-device hash. |
|
187
|
|
|
|
|
|
|
# |
|
188
|
3
|
|
|
|
|
4
|
delete $self->{'devices'}->{ $mount->{'dev'} }; |
|
189
|
|
|
|
|
|
|
|
|
190
|
3
|
|
|
|
|
20
|
return $self; |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
1; |