/[fuse_dbi]/trunk/DBI.pm
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 /trunk/DBI.pm

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

revision 21 by dpavlin, Sat Oct 2 15:29:02 2004 UTC revision 24 by dpavlin, Fri Oct 8 20:07:12 2004 UTC
# Line 24  Fuse::DBI - mount your database as files Line 24  Fuse::DBI - mount your database as files
24    use Fuse::DBI;    use Fuse::DBI;
25    Fuse::DBI->mount( ... );    Fuse::DBI->mount( ... );
26    
27  See L<run> below for examples how to set parametars.  See C<run> below for examples how to set parametars.
28    
29  =head1 DESCRIPTION  =head1 DESCRIPTION
30    
31  This module will use L<Fuse> module, part of C<FUSE (Filesystem in USErspace)>  This module will use C<Fuse> module, part of C<FUSE (Filesystem in USErspace)>
32  available at L<http://sourceforge.net/projects/avf> to mount  available at L<http://sourceforge.net/projects/avf> to mount
33  your database as file system.  your database as file system.
34    
# Line 64  my $ctime_start; Line 64  my $ctime_start;
64  sub read_filenames;  sub read_filenames;
65  sub fuse_module_loaded;  sub fuse_module_loaded;
66    
67    # evil, evil way to solve this. It makes this module non-reentrant. But, since
68    # fuse calls another copy of this script for each mount anyway, this shouldn't
69    # be a problem.
70    my $fuse_self;
71    
72  sub mount {  sub mount {
73          my $class = shift;          my $class = shift;
74          my $self = {};          my $self = {};
# Line 77  sub mount { Line 82  sub mount {
82          carp "mount needs 'mount' as mountpoint" unless ($arg->{'mount'});          carp "mount needs 'mount' as mountpoint" unless ($arg->{'mount'});
83    
84          # save (some) arguments in self          # save (some) arguments in self
85          $self->{$_} = $arg->{$_} foreach (qw(mount));          foreach (qw(mount invalidate)) {
86                    $self->{$_} = $arg->{$_};
87                    $fuse_self->{$_} = $arg->{$_};
88            }
89    
90          foreach (qw(filenames read update)) {          foreach (qw(filenames read update)) {
91                  carp "mount needs '$_' SQL" unless ($arg->{$_});                  carp "mount needs '$_' SQL" unless ($arg->{$_});
# Line 85  sub mount { Line 93  sub mount {
93    
94          $ctime_start = time();          $ctime_start = time();
95    
96            my $pid;
97          if ($arg->{'fork'}) {          if ($arg->{'fork'}) {
98                  my $pid = fork();                  $pid = fork();
99                  die "fork() failed: $!" unless defined $pid;                  die "fork() failed: $!" unless defined $pid;
100                  # child will return to caller                  # child will return to caller
101                  if ($pid) {                  if ($pid) {
102                          $self ? return $self : return undef;                          return $self;
103                  }                  }
104          }          }
105    
# Line 103  sub mount { Line 112  sub mount {
112    
113          $self->read_filenames;          $self->read_filenames;
114    
115          my $mount = Fuse::main(          Fuse::main(
116                  mountpoint=>$arg->{'mount'},                  mountpoint=>$arg->{'mount'},
117                  getattr=>\&e_getattr,                  getattr=>\&e_getattr,
118                  getdir=>\&e_getdir,                  getdir=>\&e_getdir,
# Line 117  sub mount { Line 126  sub mount {
126                  debug=>0,                  debug=>0,
127          );          );
128    
129          if (! $mount) {          exit(0) if ($arg->{'fork'});
130                  warn "mount on ",$arg->{'mount'}," failed!\n";  
131                  return undef;          return 1;
132          }  
133  };  };
134    
135  =head2 umount  =head2 umount
# Line 142  sub umount { Line 151  sub umount {
151          return 1;          return 1;
152  }  }
153    
154    #$SIG{'INT'} = sub {
155    #       print STDERR "umount called by SIG INT\n";
156    #       umount;
157    #};
158    
159    sub DESTROY {
160            my $self = shift;
161            print STDERR "umount called by DESTROY\n";
162            $self->umount;
163    }
164    
165  =head2 fuse_module_loaded  =head2 fuse_module_loaded
166    
167  Checks if C<fuse> module is loaded in kernel.  Checks if C<fuse> module is loaded in kernel.
# Line 347  sub update_db { Line 367  sub update_db {
367                          return 0;                          return 0;
368                  }                  }
369                  print "updated '$file' [",$files{$file}{id},"]\n";                  print "updated '$file' [",$files{$file}{id},"]\n";
370    
371                    $fuse_self->{'invalidate'}->() if (ref $fuse_self->{'invalidate'});
372          }          }
373          return 1;          return 1;
374  }  }

Legend:
Removed from v.21  
changed lines
  Added in v.24

  ViewVC Help
Powered by ViewVC 1.1.26