133 |
if (! %out) { |
if (! %out) { |
134 |
$out{'no files? bug?'}++; |
$out{'no files? bug?'}++; |
135 |
} |
} |
136 |
print scalar keys %out," files found for '$dirname': ",keys %out,"\n"; |
print scalar keys %out," files in dir '$dirname'\n"; |
137 |
return (keys %out),0; |
return (keys %out),0; |
138 |
} |
} |
139 |
|
|
159 |
# (note: 0 means EOF, "0" will give a byte (ascii "0") |
# (note: 0 means EOF, "0" will give a byte (ascii "0") |
160 |
# to the reading program) |
# to the reading program) |
161 |
my ($file) = filename_fixup(shift); |
my ($file) = filename_fixup(shift); |
162 |
my ($buf,$off) = @_; |
my ($buf_len,$off) = @_; |
163 |
|
|
164 |
return -ENOENT() unless exists($files{$file}); |
return -ENOENT() unless exists($files{$file}); |
165 |
|
|
166 |
my $len = length($files{$file}{cont}); |
my $len = length($files{$file}{cont}); |
167 |
|
|
168 |
print "read '$file' [$len bytes] offset $off length $buf\n"; |
print "read '$file' [$len bytes] offset $off length $buf_len\n"; |
169 |
|
|
170 |
return -EINVAL() if ($off > $len); |
return -EINVAL() if ($off > $len); |
171 |
return 0 if ($off == $len); |
return 0 if ($off == $len); |
172 |
|
|
173 |
$buf = $len-$off if ($off+$buf > $len); |
$buf_len = $buf_len-$off if ($off+$buf_len > $len); |
174 |
|
|
175 |
return substr($files{$file}{cont},$off,$buf); |
return substr($files{$file}{cont},$off,$buf_len); |
176 |
} |
} |
177 |
|
|
178 |
sub clear_cont { |
sub clear_cont { |
190 |
sub update_db { |
sub update_db { |
191 |
my $file = shift || die; |
my $file = shift || die; |
192 |
|
|
193 |
|
$files{$file}{ctime} = time(); |
194 |
|
|
195 |
if (!$sth_update->execute($files{$file}{cont},$files{$file}{id})) { |
if (!$sth_update->execute($files{$file}{cont},$files{$file}{id})) { |
196 |
print "update problem: ",$sth_update->errstr; |
print "update problem: ",$sth_update->errstr; |
197 |
clear_cont; |
clear_cont; |
209 |
|
|
210 |
sub e_write { |
sub e_write { |
211 |
my $file = filename_fixup(shift); |
my $file = filename_fixup(shift); |
212 |
my ($buf,$off) = @_; |
my ($buf_len,$off) = @_; |
213 |
|
|
214 |
return -ENOENT() unless exists($files{$file}); |
return -ENOENT() unless exists($files{$file}); |
215 |
|
|
216 |
my $len = length($files{$file}{cont}); |
my $len = length($files{$file}{cont}); |
217 |
|
|
218 |
print "write '$file' [$len bytes] offset $off length $buf\n"; |
print "write '$file' [$len bytes] offset $off length\n"; |
219 |
|
|
220 |
$files{$file}{cont} = |
$files{$file}{cont} = |
221 |
substr($files{$file}{cont},0,$off) . |
substr($files{$file}{cont},0,$off) . |
222 |
$buf . |
$buf_len . |
223 |
substr($files{$file}{cont},$off+length($buf)); |
substr($files{$file}{cont},$off+length($buf_len)); |
224 |
|
|
225 |
if (! update_db($file)) { |
if (! update_db($file)) { |
226 |
return -ENOSYS(); |
return -ENOSYS(); |
227 |
} else { |
} else { |
228 |
return length($buf); |
return length($buf_len); |
229 |
} |
} |
230 |
} |
} |
231 |
|
|
244 |
|
|
245 |
return -ENOENT() unless exists($files{$file}); |
return -ENOENT() unless exists($files{$file}); |
246 |
|
|
247 |
|
print "utime '$file' $atime $mtime\n"; |
248 |
|
|
249 |
$files{$file}{time} = $mtime; |
$files{$file}{time} = $mtime; |
250 |
return 0; |
return 0; |
251 |
} |
} |