--- fuse-comp.pl 2007/07/08 17:04:32 9 +++ fuse-comp.pl 2007/07/08 21:03:26 10 @@ -11,6 +11,7 @@ use File::Path; use Data::Dump qw/dump/; use Carp qw/confess/; +use IO::File; my $mount = { from => '/tmp/comp', @@ -151,14 +152,7 @@ warn ">>> open abs path: $path ", -s $path, " bytes\n"; return -$! unless sysopen($fh , $path, $mode); - $pending->{$file}->{fh} = $fh; $pending->{$file}->{path} = $path; - $pending->{$file}->{mode} = { - rdonly => $mode && O_RDONLY, - rdwr => $mode && O_RDWR, - append => $mode && O_APPEND, - create => $mode && O_CREAT, - }; return 0; } @@ -166,26 +160,32 @@ my ($file,$bufsize,$off) = @_; my ($rv) = -ENOSYS(); my $path = fixup( $file ); + return -ENOENT() unless -e $path; - my ($fsize) = -s $path; - my $fh = $pending->{$file}->{fh} || confess "no fh? ", dump( $pending ); + + my $fh = new IO::File; + return -ENOSYS() unless open($fh,$pending->{$file}->{path}); + if(seek($fh,$off,SEEK_SET)) { read($fh,$rv,$bufsize); } + return $rv; } sub x_write { my ($file,$buf,$off) = @_; $pending->{$file}->{write}++; - my ($rv); + my $rv; my $path = fixup($file); + return -ENOENT() unless -e $path; - my ($fsize) = -s $path; - my $fh = $pending->{$file}->{fh}; - return -ENOSYS() unless $fh; + + my $fh = new IO::File; + return -ENOSYS() unless open($fh,'+<',$pending->{$file}->{path}); if($rv = seek( $fh ,$off,SEEK_SET)) { $rv = print( $fh $buf ); + warn "## ", $pending->{$file}->{path}, " $off ",length( $buf ), "\n" if $debug; } $rv = -ENOSYS() unless $rv; return length($buf); @@ -249,7 +249,6 @@ } elsif ( ! defined( $pending->{$file}->{write} ) ) { warn "release $file, not written into\n"; } elsif ( defined( $pending->{$file}->{open} ) && $pending->{$file}->{open} == 1 ) { - close( $pending->{$file}->{fh} ) || warn "can't close $file: $!"; my $path = $pending->{$file}->{path} || confess "no path for $file ? ", dump( $pending ); my $dest = fixup( $file );