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 |
|
|
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 = {}; |
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->{$_}); |
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 |
|
|
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, |
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 |
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. |
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 |
} |
} |