line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2016, 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::Real::Inode; |
9
|
|
|
|
|
|
|
|
10
|
13
|
|
|
13
|
|
413
|
use strict; |
|
13
|
|
|
|
|
12
|
|
|
13
|
|
|
|
|
275
|
|
11
|
13
|
|
|
13
|
|
34
|
use warnings; |
|
13
|
|
|
|
|
13
|
|
|
13
|
|
|
|
|
265
|
|
12
|
|
|
|
|
|
|
|
13
|
13
|
|
|
13
|
|
335
|
use Filesys::POSIX::Bits; |
|
13
|
|
|
|
|
11
|
|
|
13
|
|
|
|
|
2806
|
|
14
|
13
|
|
|
13
|
|
528
|
use Filesys::POSIX::Bits::System; |
|
13
|
|
|
|
|
17
|
|
|
13
|
|
|
|
|
263
|
|
15
|
13
|
|
|
13
|
|
354
|
use Filesys::POSIX::Inode (); |
|
13
|
|
|
|
|
17
|
|
|
13
|
|
|
|
|
197
|
|
16
|
13
|
|
|
13
|
|
363
|
use Filesys::POSIX::Mem::Inode (); |
|
13
|
|
|
|
|
16
|
|
|
13
|
|
|
|
|
134
|
|
17
|
13
|
|
|
13
|
|
64
|
use Filesys::POSIX::IO::Handle (); |
|
13
|
|
|
|
|
16
|
|
|
13
|
|
|
|
|
213
|
|
18
|
13
|
|
|
13
|
|
39
|
use Filesys::POSIX::Error qw(throw); |
|
13
|
|
|
|
|
19
|
|
|
13
|
|
|
|
|
465
|
|
19
|
|
|
|
|
|
|
|
20
|
13
|
|
|
13
|
|
43
|
use Fcntl qw(:DEFAULT :mode); |
|
13
|
|
|
|
|
8
|
|
|
13
|
|
|
|
|
14982
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @ISA = qw(Filesys::POSIX::Inode); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
25
|
46
|
|
|
46
|
0
|
118
|
my ( $class, $path, %opts ) = @_; |
26
|
|
|
|
|
|
|
|
27
|
46
|
|
|
|
|
378
|
my $sticky = 0; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# |
30
|
|
|
|
|
|
|
# Allow the sticky flag to be set for every inode belonging to a |
31
|
|
|
|
|
|
|
# Filesys::POSIX::Real filesystem, with usage of a special mount flag. |
32
|
|
|
|
|
|
|
# However, allow this flag to be overridden on a per-inode basis, which |
33
|
|
|
|
|
|
|
# happens with each call from Filesys::POSIX::Extensions->map and the like. |
34
|
|
|
|
|
|
|
# |
35
|
46
|
50
|
|
|
|
107
|
if ( defined $opts{'dev'}->{'sticky'} ) { |
36
|
0
|
0
|
|
|
|
0
|
$sticky = $opts{'dev'}->{'sticky'} ? 1 : 0; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
46
|
100
|
|
|
|
75
|
if ( defined $opts{'sticky'} ) { |
40
|
11
|
100
|
|
|
|
26
|
$sticky = $opts{'sticky'} ? 1 : 0; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return bless { |
44
|
|
|
|
|
|
|
'path' => $path, |
45
|
|
|
|
|
|
|
'dev' => $opts{'dev'}, |
46
|
46
|
|
|
|
|
295
|
'parent' => $opts{'parent'}, |
47
|
|
|
|
|
|
|
'sticky' => $sticky, |
48
|
|
|
|
|
|
|
'dirty' => 0 |
49
|
|
|
|
|
|
|
}, $class; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub from_disk { |
53
|
46
|
|
|
46
|
0
|
136
|
my ( $class, $path, %opts ) = @_; |
54
|
46
|
100
|
|
|
|
606
|
my @st = $opts{'st_info'} ? @{ $opts{'st_info'} } : lstat $path or Carp::confess("$!"); |
|
23
|
50
|
|
|
|
56
|
|
55
|
|
|
|
|
|
|
|
56
|
46
|
|
|
|
|
210
|
my $inode = $class->new( $path, %opts )->update(@st); |
57
|
|
|
|
|
|
|
|
58
|
46
|
100
|
|
|
|
175
|
if ( S_IFMT( $st[2] ) == S_IFDIR ) { |
59
|
24
|
|
|
|
|
132
|
$inode->{'directory'} = Filesys::POSIX::Real::Directory->new( $path, $inode ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
46
|
|
|
|
|
164
|
return $inode; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub child { |
66
|
4
|
|
|
4
|
0
|
5
|
my ( $self, $name, $mode ) = @_; |
67
|
4
|
|
|
|
|
7
|
my $directory = $self->directory; |
68
|
|
|
|
|
|
|
|
69
|
4
|
50
|
|
|
|
9
|
throw &Errno::EINVAL if $name =~ /\//; |
70
|
4
|
50
|
|
|
|
10
|
throw &Errno::EEXIST if $directory->exists($name); |
71
|
|
|
|
|
|
|
|
72
|
4
|
|
|
|
|
11
|
my $path = "$self->{'path'}/$name"; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my %data = ( |
75
|
|
|
|
|
|
|
'dev' => $self->{'dev'}, |
76
|
4
|
|
|
|
|
12
|
'sticky' => $self->{'sticky'}, |
77
|
|
|
|
|
|
|
'parent' => $directory->get('.') |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
4
|
100
|
|
|
|
11
|
if ( ( $mode & $S_IFMT ) == $S_IFREG ) { |
|
|
50
|
|
|
|
|
|
81
|
2
|
50
|
|
|
|
11
|
sysopen( |
82
|
|
|
|
|
|
|
my $fh, $path, |
83
|
|
|
|
|
|
|
O_CREAT | O_EXCL | O_WRONLY, |
84
|
|
|
|
|
|
|
Filesys::POSIX::Bits::System::convertModeToSystem($mode) |
85
|
|
|
|
|
|
|
) or Carp::confess("$!"); |
86
|
2
|
|
|
|
|
55
|
close($fh); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
elsif ( ( $mode & $S_IFMT ) == $S_IFDIR ) { |
89
|
2
|
50
|
|
|
|
124
|
mkdir( $path, $mode ) or Carp::confess("$!"); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
4
|
|
|
|
|
5
|
my $inode; |
93
|
|
|
|
|
|
|
|
94
|
4
|
50
|
|
|
|
8
|
if ( ( $mode & $S_IFMT ) == $S_IFLNK ) { |
95
|
0
|
0
|
|
|
|
0
|
throw &Errno::EPERM unless $self->{'sticky'}; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
0
|
$inode = Filesys::POSIX::Mem::Inode->new( %data, 'mode' => $mode ); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
else { |
100
|
4
|
|
|
|
|
7
|
my $class = ref $self; |
101
|
4
|
|
|
|
|
21
|
$inode = $class->from_disk( $path, %data ); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
4
|
|
|
|
|
11
|
return $directory->set( $name, $inode ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub taint { |
108
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
0
|
$self->{'dirty'} = 1; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
0
|
return $self; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub update { |
116
|
53
|
|
|
53
|
1
|
82
|
my ( $self, @st ) = @_; |
117
|
|
|
|
|
|
|
|
118
|
53
|
50
|
66
|
|
|
196
|
if ( $self->{'sticky'} && $self->{'dirty'} ) { |
119
|
0
|
|
|
|
|
0
|
@{$self}{qw(rdev size atime mtime ctime)} = @st[ 6 .. 10 ]; |
|
0
|
|
|
|
|
0
|
|
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
else { |
122
|
53
|
|
|
|
|
224
|
$self->SUPER::update(@st); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
53
|
|
|
|
|
91
|
return $self; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub open { |
129
|
7
|
|
|
7
|
0
|
9
|
my ( $self, $flags ) = @_; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sysopen( |
132
|
7
|
100
|
|
|
|
65
|
my $fh, $self->{'path'}, |
133
|
|
|
|
|
|
|
Filesys::POSIX::Bits::System::convertFlagsToSystem($flags) |
134
|
|
|
|
|
|
|
) or Carp::confess("$!"); |
135
|
|
|
|
|
|
|
|
136
|
5
|
|
|
|
|
31
|
return Filesys::POSIX::IO::Handle->new($fh); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub chown { |
140
|
0
|
|
|
0
|
0
|
|
my ( $self, $uid, $gid ) = @_; |
141
|
|
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
|
unless ( $self->{'sticky'} ) { |
143
|
0
|
0
|
|
|
|
|
CORE::chown( $uid, $gid, $self->{'path'} ) or Carp::confess("$!"); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
@{$self}{qw(uid gid)} = ( $uid, $gid ); |
|
0
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
return $self->taint; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub chmod { |
152
|
0
|
|
|
0
|
0
|
|
my ( $self, $mode ) = @_; |
153
|
0
|
|
|
|
|
|
my $format = $self->{'mode'} & $S_IFMT; |
154
|
0
|
|
|
|
|
|
my $perm = $mode & ( $S_IPERM | $S_IPROT ); |
155
|
|
|
|
|
|
|
|
156
|
0
|
0
|
|
|
|
|
unless ( $self->{'sticky'} ) { |
157
|
0
|
0
|
|
|
|
|
CORE::chmod( $perm, $self->{'path'} ) or Carp::confess("$!"); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
$self->{'mode'} = $format | $perm; |
161
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
return $self->taint; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub readlink { |
166
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
167
|
|
|
|
|
|
|
|
168
|
0
|
0
|
|
|
|
|
unless ( $self->{'dest'} ) { |
169
|
0
|
0
|
|
|
|
|
$self->{'dest'} = CORE::readlink( $self->{'path'} ) or Carp::confess("$!"); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
return $self->{'dest'}; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub symlink { |
176
|
0
|
|
|
0
|
0
|
|
my ( $self, $dest ) = @_; |
177
|
|
|
|
|
|
|
|
178
|
0
|
0
|
|
|
|
|
unless ( $self->{'sticky'} ) { |
179
|
0
|
0
|
|
|
|
|
symlink( $dest, $self->{'path'} ) or Carp::confess("$!"); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
$self->{'dest'} = $dest; |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
return $self->taint; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
1; |