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::Snapshot::Inode; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
11
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
2
|
use Filesys::POSIX::Bits; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
220
|
|
14
|
1
|
|
|
1
|
|
4
|
use Filesys::POSIX::Mem::Inode (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
15
|
1
|
|
|
1
|
|
3
|
use Filesys::POSIX::Mem::Directory (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
16
|
1
|
|
|
1
|
|
3
|
use Filesys::POSIX::Mem::Bucket (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
3
|
use Filesys::POSIX::Error qw(throw); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
521
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @ISA = qw(Filesys::POSIX::Mem::Inode); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub from_inode { |
23
|
46
|
|
|
46
|
0
|
52
|
my ( $class, $inode, %opts ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
46
|
|
|
|
|
75
|
my $new_inode = bless { |
26
|
|
|
|
|
|
|
'inode' => $inode, |
27
|
|
|
|
|
|
|
'copied' => 0 |
28
|
|
|
|
|
|
|
}, $class; |
29
|
|
|
|
|
|
|
|
30
|
46
|
|
|
|
|
70
|
my @ATTRIBUTES = qw( |
31
|
|
|
|
|
|
|
size atime mtime ctime uid gid mode dev rdev parent |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
46
|
|
|
|
|
26
|
@{$new_inode}{@ATTRIBUTES} = @{$inode}{@ATTRIBUTES}; |
|
46
|
|
|
|
|
168
|
|
|
46
|
|
|
|
|
75
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
# Overwrite any values within the current inode with ones optionally passed |
38
|
|
|
|
|
|
|
# in %opts. |
39
|
|
|
|
|
|
|
# |
40
|
46
|
|
|
|
|
54
|
foreach my $attribute (@ATTRIBUTES) { |
41
|
|
|
|
|
|
|
$new_inode->{$attribute} = $opts{$attribute} |
42
|
460
|
100
|
|
|
|
556
|
if exists $opts{$attribute}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# |
46
|
|
|
|
|
|
|
# Copy the symlink destination from the given inode provided, if |
47
|
|
|
|
|
|
|
# present. |
48
|
|
|
|
|
|
|
# |
49
|
46
|
100
|
|
|
|
66
|
if ( $inode->link ) { |
50
|
1
|
|
|
|
|
5
|
$new_inode->{'dest'} = $inode->readlink; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# |
54
|
|
|
|
|
|
|
# If it was specified at mount time that we should snapshot directory |
55
|
|
|
|
|
|
|
# listings immediately, then do so. |
56
|
|
|
|
|
|
|
# |
57
|
46
|
100
|
66
|
|
|
71
|
if ( $inode->dir && $opts{'dev'}->{'flags'}->{'immediate_dir_copy'} ) { |
58
|
15
|
|
|
|
|
26
|
$new_inode->{'directory'} = $new_inode->_copy_dir( $inode->directory ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
46
|
|
|
|
|
97
|
return $new_inode; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _copy_dir { |
65
|
17
|
|
|
17
|
|
13
|
my ( $self, $directory ) = @_; |
66
|
|
|
|
|
|
|
|
67
|
17
|
|
|
|
|
25
|
my $new_directory = Filesys::POSIX::Mem::Directory->new; |
68
|
|
|
|
|
|
|
|
69
|
17
|
|
|
|
|
26
|
$directory->open; |
70
|
|
|
|
|
|
|
|
71
|
17
|
|
|
|
|
23
|
while ( defined( my $item = $directory->read ) ) { |
72
|
77
|
100
|
100
|
|
|
210
|
next if $item eq '.' || $item eq '..'; |
73
|
|
|
|
|
|
|
|
74
|
43
|
|
|
|
|
52
|
my $inode = $directory->get($item); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$new_directory->set( |
77
|
|
|
|
|
|
|
$item, |
78
|
|
|
|
|
|
|
__PACKAGE__->from_inode( |
79
|
|
|
|
|
|
|
$inode, |
80
|
|
|
|
|
|
|
'parent' => $self, |
81
|
43
|
|
|
|
|
59
|
'dev' => $self->{'dev'} |
82
|
|
|
|
|
|
|
) |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
17
|
|
|
|
|
28
|
$directory->close; |
87
|
|
|
|
|
|
|
|
88
|
17
|
|
|
|
|
16
|
return $new_directory; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _copy_file { |
92
|
1
|
|
|
1
|
|
1
|
my ($self) = @_; |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
2
|
my $dev_flags = $self->{'dev'}->{'flags'}; |
95
|
1
|
|
|
|
|
4
|
my $inode_file = $self->{'inode'}->open($O_RDONLY); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $bucket = Filesys::POSIX::Mem::Bucket->new( |
98
|
|
|
|
|
|
|
'inode' => $self, |
99
|
|
|
|
|
|
|
'max' => $dev_flags->{'bucket_max'}, |
100
|
1
|
|
|
|
|
5
|
'dir' => $dev_flags->{'bucket_dir'} |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
1
|
|
|
|
|
6
|
while ( my $len = $inode_file->read( my $buf, 4096 ) ) { |
104
|
0
|
|
|
|
|
0
|
$bucket->write( $buf, $len ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
4
|
$inode_file->close; |
108
|
1
|
|
|
|
|
3
|
$bucket->close; |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
1
|
return $bucket; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub directory { |
114
|
10
|
|
|
10
|
1
|
65
|
my ($self) = @_; |
115
|
|
|
|
|
|
|
|
116
|
10
|
100
|
|
|
|
18
|
throw &Errno::ENOTDIR unless $self->dir; |
117
|
|
|
|
|
|
|
|
118
|
9
|
100
|
|
|
|
15
|
unless ( $self->{'directory'} ) { |
119
|
2
|
|
|
|
|
5
|
$self->{'directory'} = $self->_copy_dir( $self->{'inode'}->directory ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
9
|
|
|
|
|
14
|
return $self->{'directory'}; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub open { |
126
|
4
|
|
|
4
|
0
|
5
|
my ( $self, $flags ) = @_; |
127
|
|
|
|
|
|
|
|
128
|
4
|
100
|
|
|
|
8
|
unless ( $self->{'bucket'} ) { |
129
|
2
|
100
|
66
|
|
|
9
|
if ( $self->file && $flags & ( $O_WRONLY | $O_RDWR ) ) { |
130
|
1
|
|
|
|
|
4
|
$self->{'bucket'} = $self->_copy_file; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
4
|
100
|
|
|
|
9
|
if ( $self->{'bucket'} ) { |
135
|
3
|
|
|
|
|
7
|
return $self->{'bucket'}->open($flags); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
1
|
|
|
|
|
5
|
return $self->{'inode'}->open($flags); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |