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
|
|
83
|
use strict; |
|
27
|
|
|
|
|
28
|
|
|
27
|
|
|
|
|
551
|
|
11
|
27
|
|
|
27
|
|
72
|
use warnings; |
|
27
|
|
|
|
|
23
|
|
|
27
|
|
|
|
|
467
|
|
12
|
|
|
|
|
|
|
|
13
|
27
|
|
|
27
|
|
75
|
use Filesys::POSIX::Bits; |
|
27
|
|
|
|
|
22
|
|
|
27
|
|
|
|
|
6073
|
|
14
|
27
|
|
|
27
|
|
8558
|
use Filesys::POSIX::Inode (); |
|
27
|
|
|
|
|
37
|
|
|
27
|
|
|
|
|
365
|
|
15
|
27
|
|
|
27
|
|
10054
|
use Filesys::POSIX::Directory::Handle (); |
|
27
|
|
|
|
|
39
|
|
|
27
|
|
|
|
|
481
|
|
16
|
27
|
|
|
27
|
|
9077
|
use Filesys::POSIX::Mem::Bucket (); |
|
27
|
|
|
|
|
49
|
|
|
27
|
|
|
|
|
471
|
|
17
|
27
|
|
|
27
|
|
9275
|
use Filesys::POSIX::Mem::Directory (); |
|
27
|
|
|
|
|
47
|
|
|
27
|
|
|
|
|
556
|
|
18
|
|
|
|
|
|
|
|
19
|
27
|
|
|
27
|
|
111
|
use Filesys::POSIX::Error qw(throw); |
|
27
|
|
|
|
|
42
|
|
|
27
|
|
|
|
|
11727
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @ISA = qw(Filesys::POSIX::Inode); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
289
|
|
|
289
|
0
|
5473
|
my ( $class, %opts ) = @_; |
25
|
289
|
|
|
|
|
326
|
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
|
|
|
|
1627
|
'parent' => $opts{'parent'} |
|
|
50
|
|
|
|
|
|
38
|
|
|
|
|
|
|
}, $class; |
39
|
|
|
|
|
|
|
|
40
|
289
|
100
|
100
|
|
|
1067
|
if ( exists $opts{'mode'} && ( $opts{'mode'} & $S_IFMT ) == $S_IFDIR ) { |
41
|
|
|
|
|
|
|
$inode->{'directory'} = Filesys::POSIX::Mem::Directory->new( |
42
|
|
|
|
|
|
|
'.' => $inode, |
43
|
177
|
100
|
|
|
|
551
|
'..' => $opts{'parent'} ? $opts{'parent'} : $inode |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
289
|
|
|
|
|
487
|
return $inode; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub child { |
51
|
235
|
|
|
235
|
0
|
220
|
my ( $self, $name, $mode ) = @_; |
52
|
235
|
|
|
|
|
378
|
my $directory = $self->directory; |
53
|
|
|
|
|
|
|
|
54
|
235
|
100
|
|
|
|
446
|
throw &Errno::EEXIST if $directory->exists($name); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $child = __PACKAGE__->new( |
57
|
|
|
|
|
|
|
'mode' => $mode, |
58
|
234
|
|
|
|
|
477
|
'dev' => $self->{'dev'}, |
59
|
|
|
|
|
|
|
'parent' => $directory->get('.') |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
234
|
|
|
|
|
413
|
$directory->set( $name, $child ); |
63
|
|
|
|
|
|
|
|
64
|
234
|
|
|
|
|
422
|
return $child; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub chown { |
68
|
2
|
|
|
2
|
0
|
4
|
my ( $self, $uid, $gid ) = @_; |
69
|
2
|
|
|
|
|
2
|
@{$self}{qw(uid gid)} = ( $uid, $gid ); |
|
2
|
|
|
|
|
6
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub chmod { |
73
|
16
|
|
|
16
|
0
|
16
|
my ( $self, $mode ) = @_; |
74
|
16
|
|
|
|
|
21
|
my $format = $self->{'mode'} & $S_IFMT; |
75
|
16
|
|
|
|
|
16
|
my $perm = $mode & ( $S_IPERM | $S_IPROT ); |
76
|
|
|
|
|
|
|
|
77
|
16
|
|
|
|
|
22
|
$self->{'mode'} = $format | $perm; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub readlink { |
81
|
16
|
|
|
16
|
0
|
20
|
my ($self) = @_; |
82
|
|
|
|
|
|
|
|
83
|
16
|
100
|
|
|
|
32
|
throw &Errno::EINVAL unless $self->link; |
84
|
|
|
|
|
|
|
|
85
|
15
|
|
|
|
|
90
|
return $self->{'dest'}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub symlink { |
89
|
16
|
|
|
16
|
0
|
25
|
my ( $self, $dest ) = @_; |
90
|
|
|
|
|
|
|
|
91
|
16
|
100
|
|
|
|
38
|
throw &Errno::EINVAL unless $self->link; |
92
|
|
|
|
|
|
|
|
93
|
15
|
|
|
|
|
41
|
$self->{'dest'} = $dest; |
94
|
|
|
|
|
|
|
|
95
|
15
|
|
|
|
|
41
|
return $self; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub open { |
99
|
79
|
|
|
79
|
0
|
84
|
my ( $self, $flags ) = @_; |
100
|
|
|
|
|
|
|
|
101
|
79
|
100
|
|
|
|
137
|
if ( $self->dir ) { |
102
|
2
|
|
|
|
|
12
|
return Filesys::POSIX::Directory::Handle->new; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
77
|
|
|
|
|
102
|
my $dev_flags = $self->{'dev'}->{'flags'}; |
106
|
|
|
|
|
|
|
|
107
|
77
|
100
|
|
|
|
141
|
unless ( $self->{'bucket'} ) { |
108
|
|
|
|
|
|
|
$self->{'bucket'} = Filesys::POSIX::Mem::Bucket->new( |
109
|
|
|
|
|
|
|
'inode' => $self, |
110
|
|
|
|
|
|
|
'max' => $dev_flags->{'bucket_max'}, |
111
|
60
|
|
|
|
|
283
|
'dir' => $dev_flags->{'bucket_dir'} |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
77
|
|
|
|
|
272
|
return $self->{'bucket'}->open($flags); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |