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::Mem::Inode; |
9
|
|
|
|
|
|
|
|
10
|
26
|
|
|
26
|
|
94
|
use strict; |
|
26
|
|
|
|
|
31
|
|
|
26
|
|
|
|
|
775
|
|
11
|
26
|
|
|
26
|
|
96
|
use warnings; |
|
26
|
|
|
|
|
25
|
|
|
26
|
|
|
|
|
574
|
|
12
|
|
|
|
|
|
|
|
13
|
26
|
|
|
26
|
|
101
|
use Filesys::POSIX::Bits; |
|
26
|
|
|
|
|
40
|
|
|
26
|
|
|
|
|
7117
|
|
14
|
26
|
|
|
26
|
|
10000
|
use Filesys::POSIX::Inode (); |
|
26
|
|
|
|
|
53
|
|
|
26
|
|
|
|
|
461
|
|
15
|
26
|
|
|
26
|
|
11307
|
use Filesys::POSIX::Directory::Handle (); |
|
26
|
|
|
|
|
37
|
|
|
26
|
|
|
|
|
518
|
|
16
|
26
|
|
|
26
|
|
9279
|
use Filesys::POSIX::Mem::Bucket (); |
|
26
|
|
|
|
|
90
|
|
|
26
|
|
|
|
|
570
|
|
17
|
26
|
|
|
26
|
|
9828
|
use Filesys::POSIX::Mem::Directory (); |
|
26
|
|
|
|
|
54
|
|
|
26
|
|
|
|
|
552
|
|
18
|
|
|
|
|
|
|
|
19
|
26
|
|
|
26
|
|
138
|
use Filesys::POSIX::Error qw(throw); |
|
26
|
|
|
|
|
34
|
|
|
26
|
|
|
|
|
13090
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @ISA = qw(Filesys::POSIX::Inode); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
286
|
|
|
286
|
0
|
6310
|
my ( $class, %opts ) = @_; |
25
|
286
|
|
|
|
|
361
|
my $now = time; |
26
|
|
|
|
|
|
|
|
27
|
286
|
100
|
|
|
|
2427
|
my $inode = bless { |
|
|
50
|
|
|
|
|
|
28
|
|
|
|
|
|
|
'size' => 0, |
29
|
|
|
|
|
|
|
'atime' => $now, |
30
|
|
|
|
|
|
|
'mtime' => $now, |
31
|
|
|
|
|
|
|
'ctime' => $now, |
32
|
|
|
|
|
|
|
'uid' => 0, |
33
|
|
|
|
|
|
|
'gid' => 0, |
34
|
|
|
|
|
|
|
'mode' => defined $opts{'mode'} ? $opts{'mode'} : 0, |
35
|
|
|
|
|
|
|
'dev' => $opts{'dev'}, |
36
|
|
|
|
|
|
|
'rdev' => defined $opts{'rdev'} ? $opts{'rdev'} : 0, |
37
|
|
|
|
|
|
|
'parent' => $opts{'parent'} |
38
|
|
|
|
|
|
|
}, $class; |
39
|
|
|
|
|
|
|
|
40
|
286
|
100
|
100
|
|
|
1259
|
if ( exists $opts{'mode'} && ( $opts{'mode'} & $S_IFMT ) == $S_IFDIR ) { |
41
|
175
|
100
|
|
|
|
712
|
$inode->{'directory'} = Filesys::POSIX::Mem::Directory->new( |
42
|
|
|
|
|
|
|
'.' => $inode, |
43
|
|
|
|
|
|
|
'..' => $opts{'parent'} ? $opts{'parent'} : $inode |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
286
|
|
|
|
|
684
|
return $inode; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub child { |
51
|
232
|
|
|
232
|
0
|
292
|
my ( $self, $name, $mode ) = @_; |
52
|
232
|
|
|
|
|
417
|
my $directory = $self->directory; |
53
|
|
|
|
|
|
|
|
54
|
232
|
100
|
|
|
|
474
|
throw &Errno::EEXIST if $directory->exists($name); |
55
|
|
|
|
|
|
|
|
56
|
231
|
|
|
|
|
573
|
my $child = __PACKAGE__->new( |
57
|
|
|
|
|
|
|
'mode' => $mode, |
58
|
|
|
|
|
|
|
'dev' => $self->{'dev'}, |
59
|
|
|
|
|
|
|
'parent' => $directory->get('.') |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
231
|
|
|
|
|
489
|
$directory->set( $name, $child ); |
63
|
|
|
|
|
|
|
|
64
|
231
|
|
|
|
|
529
|
return $child; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub chown { |
68
|
2
|
|
|
2
|
0
|
3
|
my ( $self, $uid, $gid ) = @_; |
69
|
2
|
|
|
|
|
4
|
@{$self}{qw(uid gid)} = ( $uid, $gid ); |
|
2
|
|
|
|
|
6
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub chmod { |
73
|
16
|
|
|
16
|
0
|
31
|
my ( $self, $mode ) = @_; |
74
|
16
|
|
|
|
|
24
|
my $format = $self->{'mode'} & $S_IFMT; |
75
|
16
|
|
|
|
|
22
|
my $perm = $mode & ( $S_IPERM | $S_IPROT ); |
76
|
|
|
|
|
|
|
|
77
|
16
|
|
|
|
|
28
|
$self->{'mode'} = $format | $perm; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub readlink { |
81
|
15
|
|
|
15
|
0
|
22
|
my ($self) = @_; |
82
|
|
|
|
|
|
|
|
83
|
15
|
100
|
|
|
|
35
|
throw &Errno::EINVAL unless $self->link; |
84
|
|
|
|
|
|
|
|
85
|
14
|
|
|
|
|
125
|
return $self->{'dest'}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub symlink { |
89
|
15
|
|
|
15
|
0
|
28
|
my ( $self, $dest ) = @_; |
90
|
|
|
|
|
|
|
|
91
|
15
|
100
|
|
|
|
49
|
throw &Errno::EINVAL unless $self->link; |
92
|
|
|
|
|
|
|
|
93
|
14
|
|
|
|
|
36
|
$self->{'dest'} = $dest; |
94
|
|
|
|
|
|
|
|
95
|
14
|
|
|
|
|
38
|
return $self; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub open { |
99
|
79
|
|
|
79
|
0
|
96
|
my ( $self, $flags ) = @_; |
100
|
|
|
|
|
|
|
|
101
|
79
|
100
|
|
|
|
156
|
if ( $self->dir ) { |
102
|
2
|
|
|
|
|
16
|
return Filesys::POSIX::Directory::Handle->new; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
77
|
|
|
|
|
137
|
my $dev_flags = $self->{'dev'}->{'flags'}; |
106
|
|
|
|
|
|
|
|
107
|
77
|
100
|
|
|
|
160
|
unless ( $self->{'bucket'} ) { |
108
|
60
|
|
|
|
|
344
|
$self->{'bucket'} = Filesys::POSIX::Mem::Bucket->new( |
109
|
|
|
|
|
|
|
'inode' => $self, |
110
|
|
|
|
|
|
|
'max' => $dev_flags->{'bucket_max'}, |
111
|
|
|
|
|
|
|
'dir' => $dev_flags->{'bucket_dir'} |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
77
|
|
|
|
|
334
|
return $self->{'bucket'}->open($flags); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |