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
|
27
|
|
|
27
|
|
84
|
use strict; |
|
27
|
|
|
|
|
25
|
|
|
27
|
|
|
|
|
542
|
|
11
|
27
|
|
|
27
|
|
77
|
use warnings; |
|
27
|
|
|
|
|
29
|
|
|
27
|
|
|
|
|
477
|
|
12
|
|
|
|
|
|
|
|
13
|
27
|
|
|
27
|
|
87
|
use Filesys::POSIX::Bits; |
|
27
|
|
|
|
|
26
|
|
|
27
|
|
|
|
|
5879
|
|
14
|
27
|
|
|
27
|
|
8569
|
use Filesys::POSIX::Inode (); |
|
27
|
|
|
|
|
39
|
|
|
27
|
|
|
|
|
368
|
|
15
|
27
|
|
|
27
|
|
10109
|
use Filesys::POSIX::Directory::Handle (); |
|
27
|
|
|
|
|
36
|
|
|
27
|
|
|
|
|
504
|
|
16
|
27
|
|
|
27
|
|
8978
|
use Filesys::POSIX::Mem::Bucket (); |
|
27
|
|
|
|
|
52
|
|
|
27
|
|
|
|
|
499
|
|
17
|
27
|
|
|
27
|
|
9477
|
use Filesys::POSIX::Mem::Directory (); |
|
27
|
|
|
|
|
43
|
|
|
27
|
|
|
|
|
489
|
|
18
|
|
|
|
|
|
|
|
19
|
27
|
|
|
27
|
|
119
|
use Filesys::POSIX::Error qw(throw); |
|
27
|
|
|
|
|
31
|
|
|
27
|
|
|
|
|
11770
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @ISA = qw(Filesys::POSIX::Inode); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
289
|
|
|
289
|
0
|
3615
|
my ( $class, %opts ) = @_; |
25
|
289
|
|
|
|
|
335
|
my $now = time; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $inode = bless { |
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
|
289
|
100
|
|
|
|
1745
|
'parent' => $opts{'parent'} |
|
|
50
|
|
|
|
|
|
38
|
|
|
|
|
|
|
}, $class; |
39
|
|
|
|
|
|
|
|
40
|
289
|
100
|
100
|
|
|
1153
|
if ( exists $opts{'mode'} && ( $opts{'mode'} & $S_IFMT ) == $S_IFDIR ) { |
41
|
|
|
|
|
|
|
$inode->{'directory'} = Filesys::POSIX::Mem::Directory->new( |
42
|
|
|
|
|
|
|
'.' => $inode, |
43
|
177
|
100
|
|
|
|
567
|
'..' => $opts{'parent'} ? $opts{'parent'} : $inode |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
289
|
|
|
|
|
523
|
return $inode; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub child { |
51
|
235
|
|
|
235
|
0
|
227
|
my ( $self, $name, $mode ) = @_; |
52
|
235
|
|
|
|
|
379
|
my $directory = $self->directory; |
53
|
|
|
|
|
|
|
|
54
|
235
|
100
|
|
|
|
422
|
throw &Errno::EEXIST if $directory->exists($name); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $child = __PACKAGE__->new( |
57
|
|
|
|
|
|
|
'mode' => $mode, |
58
|
234
|
|
|
|
|
469
|
'dev' => $self->{'dev'}, |
59
|
|
|
|
|
|
|
'parent' => $directory->get('.') |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
234
|
|
|
|
|
427
|
$directory->set( $name, $child ); |
63
|
|
|
|
|
|
|
|
64
|
234
|
|
|
|
|
430
|
return $child; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub chown { |
68
|
2
|
|
|
2
|
0
|
5
|
my ( $self, $uid, $gid ) = @_; |
69
|
2
|
|
|
|
|
3
|
@{$self}{qw(uid gid)} = ( $uid, $gid ); |
|
2
|
|
|
|
|
6
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub chmod { |
73
|
16
|
|
|
16
|
0
|
17
|
my ( $self, $mode ) = @_; |
74
|
16
|
|
|
|
|
19
|
my $format = $self->{'mode'} & $S_IFMT; |
75
|
16
|
|
|
|
|
20
|
my $perm = $mode & ( $S_IPERM | $S_IPROT ); |
76
|
|
|
|
|
|
|
|
77
|
16
|
|
|
|
|
26
|
$self->{'mode'} = $format | $perm; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub readlink { |
81
|
16
|
|
|
16
|
0
|
23
|
my ($self) = @_; |
82
|
|
|
|
|
|
|
|
83
|
16
|
100
|
|
|
|
42
|
throw &Errno::EINVAL unless $self->link; |
84
|
|
|
|
|
|
|
|
85
|
15
|
|
|
|
|
111
|
return $self->{'dest'}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub symlink { |
89
|
16
|
|
|
16
|
0
|
43
|
my ( $self, $dest ) = @_; |
90
|
|
|
|
|
|
|
|
91
|
16
|
100
|
|
|
|
39
|
throw &Errno::EINVAL unless $self->link; |
92
|
|
|
|
|
|
|
|
93
|
15
|
|
|
|
|
34
|
$self->{'dest'} = $dest; |
94
|
|
|
|
|
|
|
|
95
|
15
|
|
|
|
|
40
|
return $self; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub open { |
99
|
79
|
|
|
79
|
0
|
71
|
my ( $self, $flags ) = @_; |
100
|
|
|
|
|
|
|
|
101
|
79
|
100
|
|
|
|
149
|
if ( $self->dir ) { |
102
|
2
|
|
|
|
|
15
|
return Filesys::POSIX::Directory::Handle->new; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
77
|
|
|
|
|
125
|
my $dev_flags = $self->{'dev'}->{'flags'}; |
106
|
|
|
|
|
|
|
|
107
|
77
|
100
|
|
|
|
143
|
unless ( $self->{'bucket'} ) { |
108
|
|
|
|
|
|
|
$self->{'bucket'} = Filesys::POSIX::Mem::Bucket->new( |
109
|
|
|
|
|
|
|
'inode' => $self, |
110
|
|
|
|
|
|
|
'max' => $dev_flags->{'bucket_max'}, |
111
|
60
|
|
|
|
|
318
|
'dir' => $dev_flags->{'bucket_dir'} |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
77
|
|
|
|
|
296
|
return $self->{'bucket'}->open($flags); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |