19 |
# This allows declaration use Fuse ':all'; |
# This allows declaration use Fuse ':all'; |
20 |
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
21 |
# will save memory. |
# will save memory. |
22 |
our %EXPORT_TAGS = ( 'all' => [ qw( |
our %EXPORT_TAGS = ( |
23 |
FUSE_DEBUG |
'all' => [ qw(FUSE_DEBUG XATTR_CREATE XATTR_REPLACE) ], |
24 |
) ] ); |
'debug' => [ qw(FUSE_DEBUG) ], |
25 |
|
'xattr' => [ qw(XATTR_CREATE XATTR_REPLACE) ] |
26 |
|
); |
27 |
|
|
28 |
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
29 |
|
|
30 |
our @EXPORT = qw( |
our @EXPORT = qw( |
31 |
FUSE_DEBUG |
FUSE_DEBUG |
32 |
); |
); |
33 |
our $VERSION = '0.05'; |
our $VERSION = '0.06'; |
34 |
|
|
35 |
sub AUTOLOAD { |
sub AUTOLOAD { |
36 |
# This AUTOLOAD is used to 'autoload' constants from the constant() |
# This AUTOLOAD is used to 'autoload' constants from the constant() |
64 |
goto &$AUTOLOAD; |
goto &$AUTOLOAD; |
65 |
} |
} |
66 |
|
|
67 |
|
sub XATTR_CREATE { |
68 |
|
# See <sys/xattr.h>. |
69 |
|
return 1; |
70 |
|
} |
71 |
|
|
72 |
|
sub XATTR_REPLACE { |
73 |
|
# See <sys/xattr.h>. |
74 |
|
return 2; |
75 |
|
} |
76 |
|
|
77 |
bootstrap Fuse $VERSION; |
bootstrap Fuse $VERSION; |
78 |
|
|
79 |
sub main { |
sub main { |
80 |
my (@subs) = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); |
my (@subs) = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); |
81 |
my (@names) = qw(getattr readlink getdir mknod mkdir unlink rmdir symlink |
my (@names) = qw(getattr readlink getdir mknod mkdir unlink rmdir symlink |
82 |
rename link chmod chown truncate utime open read write statfs); |
rename link chmod chown truncate utime open read write statfs |
83 |
|
flush release fsync setxattr getxattr listxattr removexattr); |
84 |
|
my (@validOpts) = qw(allow_other); |
85 |
my ($tmp) = 0; |
my ($tmp) = 0; |
86 |
my (%mapping) = map { $_ => $tmp++ } (@names); |
my (%mapping) = map { $_ => $tmp++ } (@names); |
87 |
my (%otherargs) = (debug=>0, mountpoint=>""); |
my (%optmap) = map { $_ => 1 } (@validOpts); |
88 |
|
my (%otherargs) = (debug=>0, threaded=>0, mountpoint=>"", mountopts=>""); |
89 |
while(my $name = shift) { |
while(my $name = shift) { |
90 |
my ($subref) = shift; |
my ($subref) = shift; |
91 |
if(exists($otherargs{$name})) { |
if(exists($otherargs{$name})) { |
92 |
$otherargs{$name} = $subref; |
$otherargs{$name} = $subref; |
93 |
} else { |
} else { |
94 |
croak "There is no function $name" unless exists($mapping{$name}); |
croak "There is no function $name" unless exists($mapping{$name}); |
95 |
croak "Usage: Fuse::main(getattr => &my_getattr, ...)" unless $subref; |
croak "Usage: Fuse::main(getattr => \"main::my_getattr\", ...)" unless $subref; |
|
croak "Usage: Fuse::main(getattr => &my_getattr, ...)" unless ref($subref); |
|
|
croak "Usage: Fuse::main(getattr => &my_getattr, ...)" unless ref($subref) eq "CODE"; |
|
96 |
$subs[$mapping{$name}] = $subref; |
$subs[$mapping{$name}] = $subref; |
97 |
} |
} |
98 |
} |
} |
99 |
perl_fuse_main($otherargs{debug},$otherargs{mountpoint},@subs); |
foreach my $opt ( split(/,/,$otherargs{mountopts}) ) { |
100 |
|
if ( ! exists($optmap{$opt}) ) { |
101 |
|
croak "Use of an invalid mountopt argument"; |
102 |
|
} |
103 |
|
} |
104 |
|
perl_fuse_main($otherargs{debug},$otherargs{threaded},$otherargs{mountpoint},$otherargs{mountopts},@subs); |
105 |
} |
} |
106 |
|
|
107 |
# Autoload methods go after =cut, and are processed by the autosplit program. |
# Autoload methods go after =cut, and are processed by the autosplit program. |
118 |
use Fuse; |
use Fuse; |
119 |
my ($mountpoint) = ""; |
my ($mountpoint) = ""; |
120 |
$mountpoint = shift(@ARGV) if @ARGV; |
$mountpoint = shift(@ARGV) if @ARGV; |
121 |
Fuse::main(mountpoint=>$mountpoint, getattr=>\&my_getattr, getdir=>\&my_getdir, ...); |
Fuse::main(mountpoint=>$mountpoint, getattr=>"main::my_getattr", getdir=>"main::my_getdir", ...); |
122 |
|
|
123 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
124 |
|
|
127 |
|
|
128 |
FUSE expects you to implement callbacks for the various functions. |
FUSE expects you to implement callbacks for the various functions. |
129 |
|
|
|
NOTE: I have only tested the things implemented in example.pl! |
|
|
It should work, but some things may not. |
|
|
|
|
130 |
In the following definitions, "errno" can be 0 (for a success), |
In the following definitions, "errno" can be 0 (for a success), |
131 |
-EINVAL, -ENOENT, -EONFIRE, any integer less than 1 really. |
-EINVAL, -ENOENT, -EONFIRE, any integer less than 1 really. |
132 |
|
|
137 |
etc) can be imported either from POSIX or from Fcntl, often both. |
etc) can be imported either from POSIX or from Fcntl, often both. |
138 |
See their respective documentations, for more information. |
See their respective documentations, for more information. |
139 |
|
|
140 |
=head2 EXPORT |
=head2 EXPORTED SYMBOLS |
141 |
|
|
142 |
None by default. |
FUSE_DEBUG by default. |
143 |
|
|
144 |
=head2 EXPORTABLE CONSTANTS |
You can request all exportable symbols by using the tag ":all". |
145 |
|
|
146 |
None. |
You can request all debug symbols by using the tag ":debug". |
147 |
|
This will export FUSE_DEBUG. |
148 |
|
|
149 |
|
You can request the extended attribute symbols by using the tag ":xattr". |
150 |
|
This will export XATTR_CREATE and XATTR_REPLACE. |
151 |
|
|
152 |
=head2 FUNCTIONS |
=head2 FUNCTIONS |
153 |
|
|
176 |
|
|
177 |
=back |
=back |
178 |
|
|
179 |
unthreaded => boolean |
mountopts => string |
180 |
|
|
181 |
=over 1 |
=over 1 |
182 |
|
|
183 |
This turns FUSE multithreading off and on. NOTE: This perlmodule does not |
This is a comma seperated list of mount options to pass to the FUSE kernel |
184 |
currently work properly in multithreaded mode! The author is unfortunately |
module. |
185 |
not familiar enough with perl-threads internals, and according to the |
|
186 |
documentation available at time of writing (2002-03-08), those internals are |
At present, it allows the specification of the allow_other |
187 |
subject to changing anyway. Note that singlethreaded mode also means that |
argument when mounting the new FUSE filesystem. To use this, you will also |
188 |
you will not have to worry about reentrancy, though you will have to worry |
need 'user_allow_other' in /etc/fuse.conf as per the FUSE documention |
189 |
about recursive lookups (since the kernel holds a global lock on your |
|
190 |
filesystem and blocks waiting for one callback to complete before calling |
mountopts => "allow_other" or |
191 |
another). |
mountopts => "" |
192 |
|
|
193 |
I hope to add full multithreading functionality later, but for now, I |
=back |
194 |
recommend you leave this option at the default, 1 (which means |
|
195 |
unthreaded, no threads will be used and no reentrancy is needed). |
threaded => boolean |
196 |
|
|
197 |
|
=over 1 |
198 |
|
|
199 |
|
This turns FUSE multithreading on and off. The default is 0, meaning your FUSE |
200 |
|
script will run in single-threaded mode. Note that single-threaded mode also |
201 |
|
means that you will not have to worry about reentrancy, though you will have to |
202 |
|
worry about recursive lookups. In single-threaded mode, FUSE holds a global |
203 |
|
lock on your filesystem, and will wait for one callback to return before |
204 |
|
calling another. This can lead to deadlocks, if your script makes any attempt |
205 |
|
to access files or directories in the filesystem it is providing. (This |
206 |
|
includes calling stat() on the mount-point, statfs() calls from the 'df' |
207 |
|
command, and so on and so forth.) It is worth paying a little attention and |
208 |
|
being careful about this. |
209 |
|
|
210 |
|
Enabling multithreading will cause FUSE to make multiple simultaneous calls |
211 |
|
into the various callback functions of your perl script. If you enable |
212 |
|
threaded mode, you can enjoy all the parallel execution and interactive |
213 |
|
response benefits of threads, and you get to enjoy all the benefits of race |
214 |
|
conditions and locking bugs, too. Please also ensure any other perl modules |
215 |
|
you're using are also thread-safe. |
216 |
|
|
217 |
|
(If enabled, this option will cause a warning if your perl interpreter was not |
218 |
|
built with USE_ITHREADS.) |
219 |
|
|
220 |
=back |
=back |
221 |
|
|
391 |
|
|
392 |
-ENOANO(), $namelen, $files, $files_free, $blocks, $blocks_avail, $blocksize |
-ENOANO(), $namelen, $files, $files_free, $blocks, $blocks_avail, $blocksize |
393 |
|
|
394 |
|
=head3 flush |
395 |
|
|
396 |
|
Arguments: Pathname |
397 |
|
Returns an errno or 0 on success. |
398 |
|
|
399 |
|
Called to synchronise any cached data. This is called before the file |
400 |
|
is closed. It may be called multiple times before a file is closed. |
401 |
|
|
402 |
|
=head3 release |
403 |
|
|
404 |
|
Arguments: Pathname, numeric flags passed to open |
405 |
|
Returns an errno or 0 on success. |
406 |
|
|
407 |
|
Called to indicate that there are no more references to the file. Called once |
408 |
|
for every file with the same pathname and flags as were passed to open. |
409 |
|
|
410 |
|
=head3 fsync |
411 |
|
|
412 |
|
Arguments: Pathname, numeric flags |
413 |
|
Returns an errno or 0 on success. |
414 |
|
|
415 |
|
Called to synchronise the file's contents. If flags is non-zero, |
416 |
|
only synchronise the user data. Otherwise synchronise the user and meta data. |
417 |
|
|
418 |
|
=head3 setxattr |
419 |
|
|
420 |
|
Arguments: Pathname, extended attribute's name, extended attribute's value, numeric flags (which is an OR-ing of XATTR_CREATE and XATTR_REPLACE |
421 |
|
Returns an errno or 0 on success. |
422 |
|
|
423 |
|
Called to set the value of the named extended attribute. |
424 |
|
|
425 |
|
If you wish to reject setting of a particular form of extended attribute name |
426 |
|
(e.g.: regexps matching user\..* or security\..*), then return - EOPNOTSUPP. |
427 |
|
|
428 |
|
If flags is set to XATTR_CREATE and the extended attribute already exists, |
429 |
|
this should fail with - EEXIST. If flags is set to XATTR_REPLACE |
430 |
|
and the extended attribute doesn't exist, this should fail with - ENOATTR. |
431 |
|
|
432 |
|
XATTR_CREATE and XATTR_REPLACE are provided by this module, but not exported |
433 |
|
by default. To import them: |
434 |
|
|
435 |
|
use Fuse ':xattr'; |
436 |
|
|
437 |
|
or: |
438 |
|
|
439 |
|
use Fuse ':all'; |
440 |
|
|
441 |
|
=head3 getxattr |
442 |
|
|
443 |
|
Arguments: Pathname, extended attribute's name |
444 |
|
Returns an errno, 0 if there was no value, or the extended attribute's value. |
445 |
|
|
446 |
|
Called to get the value of the named extended attribute. |
447 |
|
|
448 |
|
=head3 listxattr |
449 |
|
|
450 |
|
Arguments: Pathname |
451 |
|
Returns a list: 0 or more text strings (the extended attribute names), followed by a numeric errno (usually 0). |
452 |
|
|
453 |
|
=head3 removexattr |
454 |
|
|
455 |
|
Arguments: Pathname, extended attribute's name |
456 |
|
Returns an errno or 0 on success. |
457 |
|
|
458 |
=head1 AUTHOR |
=head1 AUTHOR |
459 |
|
|
460 |
Mark Glines, E<lt>mark@glines.orgE<gt> |
Mark Glines, E<lt>mark@glines.orgE<gt> |