line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# SMB-Perl library, Copyright (C) 2014-2018 Mikhael Goikhman, migo@cpan.org |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify |
4
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
5
|
|
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
6
|
|
|
|
|
|
|
# (at your option) any later version. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
9
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11
|
|
|
|
|
|
|
# GNU General Public License for more details. |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
14
|
|
|
|
|
|
|
# along with this program. If not, see . |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package SMB::OpenFile; |
17
|
|
|
|
|
|
|
|
18
|
3
|
|
|
3
|
|
21
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
89
|
|
19
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
88
|
|
20
|
|
|
|
|
|
|
|
21
|
3
|
|
|
3
|
|
16
|
use parent 'SMB'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
17
|
|
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
3
|
|
173
|
use Fcntl 'SEEK_SET'; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
152
|
|
24
|
3
|
|
|
3
|
|
387
|
use SMB::File; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
1236
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new ($$$$%) { |
27
|
17
|
|
|
17
|
1
|
36
|
my $class = shift; |
28
|
17
|
|
50
|
|
|
42
|
my $file = shift || die "No file\n"; |
29
|
17
|
|
50
|
|
|
50
|
my $handle = shift || 0; |
30
|
17
|
|
50
|
|
|
43
|
my $action = shift || SMB::File::ACTION_NONE; |
31
|
17
|
|
|
|
|
32
|
my %options = @_; |
32
|
|
|
|
|
|
|
|
33
|
17
|
|
|
|
|
72
|
my $self = $class->SUPER::new( |
34
|
|
|
|
|
|
|
file => $file, |
35
|
|
|
|
|
|
|
handle => $handle, |
36
|
|
|
|
|
|
|
action => $action, |
37
|
|
|
|
|
|
|
last_index => 0, |
38
|
|
|
|
|
|
|
delete_on_close => 0, |
39
|
|
|
|
|
|
|
%options, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
17
|
|
|
|
|
50
|
return $self; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub close ($) { |
46
|
17
|
|
|
17
|
1
|
11117
|
my $self = shift; |
47
|
|
|
|
|
|
|
|
48
|
17
|
|
|
|
|
58
|
$self->file->delete_openfile($self); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub read ($%) { |
52
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
53
|
0
|
|
|
|
|
|
my %params = @_; # length offset minlen remain |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
my $fh = $self->{handle} or return ''; |
56
|
0
|
|
0
|
|
|
|
my $offset = $params{offset} || 0; |
57
|
0
|
|
0
|
|
|
|
sysseek($fh, $offset, SEEK_SET) // return; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
0
|
|
|
|
my $length = $params{length} // return; |
60
|
0
|
|
0
|
|
|
|
my $minlen = $params{minlen} || 0; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $buffer; |
63
|
|
|
|
|
|
|
$self->msg("Read $self->{file}{filename} - $length bytes offset=$offset") |
64
|
0
|
0
|
|
|
|
|
unless $params{quiet}; |
65
|
0
|
|
0
|
|
|
|
sysread($fh, $buffer, $length) // return; |
66
|
0
|
0
|
|
|
|
|
return if length($buffer) < $minlen; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return $buffer; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |