/[fuse-comp]/fuse-comp.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /fuse-comp.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 8 by dpavlin, Sun Jul 8 17:04:18 2007 UTC revision 10 by dpavlin, Sun Jul 8 21:03:26 2007 UTC
# Line 11  use PerlIO::gzip; Line 11  use PerlIO::gzip;
11  use File::Path;  use File::Path;
12  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
13  use Carp qw/confess/;  use Carp qw/confess/;
14    use IO::File;
15    
16  my $mount = {  my $mount = {
17          from    => '/tmp/comp',          from    => '/tmp/comp',
# Line 151  sub x_open { Line 152  sub x_open {
152          warn ">>> open abs path: $path ", -s $path, " bytes\n";          warn ">>> open abs path: $path ", -s $path, " bytes\n";
153          return -$! unless sysopen($fh , $path, $mode);          return -$! unless sysopen($fh , $path, $mode);
154    
         $pending->{$file}->{fh} = $fh;  
155          $pending->{$file}->{path} = $path;          $pending->{$file}->{path} = $path;
         $pending->{$file}->{mode} = {  
                 rdonly => $mode && O_RDONLY,  
                 rdwr => $mode && O_RDWR,  
                 append => $mode && O_APPEND,  
                 create => $mode && O_CREAT,  
         };  
156          return 0;          return 0;
157  }  }
158    
# Line 166  sub x_read { Line 160  sub x_read {
160          my ($file,$bufsize,$off) = @_;          my ($file,$bufsize,$off) = @_;
161          my ($rv) = -ENOSYS();          my ($rv) = -ENOSYS();
162          my $path = fixup( $file );          my $path = fixup( $file );
163    
164          return -ENOENT() unless -e $path;          return -ENOENT() unless -e $path;
165          my ($fsize) = -s $path;  
166          my $fh = $pending->{$file}->{fh} || confess "no fh? ", dump( $pending );          my $fh = new IO::File;
167            return -ENOSYS() unless open($fh,$pending->{$file}->{path});
168    
169          if(seek($fh,$off,SEEK_SET)) {          if(seek($fh,$off,SEEK_SET)) {
170                  read($fh,$rv,$bufsize);                  read($fh,$rv,$bufsize);
171          }          }
172    
173          return $rv;          return $rv;
174  }  }
175    
176  sub x_write {  sub x_write {
177          my ($file,$buf,$off) = @_;          my ($file,$buf,$off) = @_;
178          $pending->{$file}->{write}++;          $pending->{$file}->{write}++;
179          my ($rv);          my $rv;
180          my $path = fixup($file);          my $path = fixup($file);
181    
182          return -ENOENT() unless -e $path;          return -ENOENT() unless -e $path;
183          my ($fsize) = -s $path;  
184          my $fh = $pending->{$file}->{fh};          my $fh = new IO::File;
185          return -ENOSYS() unless $fh;          return -ENOSYS() unless open($fh,'+<',$pending->{$file}->{path});
186          if($rv = seek( $fh ,$off,SEEK_SET)) {          if($rv = seek( $fh ,$off,SEEK_SET)) {
187                  $rv = print( $fh $buf );                  $rv = print( $fh $buf );
188                    warn "## ", $pending->{$file}->{path}, " $off ",length( $buf ), "\n" if $debug;
189          }          }
190          $rv = -ENOSYS() unless $rv;          $rv = -ENOSYS() unless $rv;
191          return length($buf);          return length($buf);
# Line 249  sub x_release { Line 249  sub x_release {
249          } elsif ( ! defined( $pending->{$file}->{write} ) ) {          } elsif ( ! defined( $pending->{$file}->{write} ) ) {
250                  warn "release $file, not written into\n";                  warn "release $file, not written into\n";
251          } elsif ( defined( $pending->{$file}->{open} ) && $pending->{$file}->{open} == 1 ) {          } elsif ( defined( $pending->{$file}->{open} ) && $pending->{$file}->{open} == 1 ) {
                 close( $pending->{$file}->{fh} ) || warn "can't close $file: $!";  
252                  my $path = $pending->{$file}->{path} || confess "no path for $file ? ", dump( $pending );                  my $path = $pending->{$file}->{path} || confess "no path for $file ? ", dump( $pending );
253                  my $dest = fixup( $file );                  my $dest = fixup( $file );
254    

Legend:
Removed from v.8  
changed lines
  Added in v.10

  ViewVC Help
Powered by ViewVC 1.1.26