+sub clear_cont {
+ print "invalidate all cached content\n";
+ foreach my $f (keys %files) {
+ delete $files{$f}{cont};
+ }
+}
+
+
+sub update_db {
+ my $file = shift || die;
+
+ if (!$sth_update->execute($files{$file}{cont},$files{$file}{id})) {
+ print "update problem: ",$sth_update->errstr;
+ $dbh->rollback;
+ clear_cont;
+ $dbh->begin_work;
+ return 0;
+ } else {
+ if ($dbh->commit) {
+ print "commit problem: ",$sth_update->errstr;
+ $dbh->rollback;
+ clear_cont;
+ $dbh->begin_work;
+ return 0;
+ }
+ print "updated '$file' [",$files{$file}{id},"]\n";
+ }
+ return 1;
+}
+
+sub e_write {
+ my $file = filename_fixup(shift);
+ my ($buf,$off) = @_;
+
+ return -ENOENT() unless exists($files{$file});
+
+ my $len = length($files{$file}{cont});
+
+ print "write '$file' [$len bytes] offset $off length $buf\n";
+
+ $files{$file}{cont} =
+ substr($files{$file}{cont},0,$off) .
+ $buf .
+ substr($files{$file}{cont},$off+length($buf));
+
+ if (! update_db($file)) {
+ return -ENOSYS();
+ } else {
+ return length($buf);
+ }
+}
+
+sub e_truncate {
+ my $file = filename_fixup(shift);
+ my $size = shift;
+
+ $files{$file}{cont} = substr($files{$file}{cont},0,$size);
+ return 0
+};
+
+
+sub e_utime {
+ my ($atime,$mtime,$file) = @_;
+ $file = filename_fixup($file);
+
+ return -ENOENT() unless exists($files{$file});
+
+ $files{$file}{time} = $mtime;
+ return 0;
+}
+