13 our @ISA = qw(Exporter DynaLoader);
15 # Items to export into callers namespace by default. Note: do not export
16 # names by default without a very good reason. Use EXPORT_OK instead.
17 # Do not simply export all your public functions/methods/constants.
19 # This allows declaration use Fuse ':all';
20 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
23 'all' => [ qw(FUSE_DEBUG XATTR_CREATE XATTR_REPLACE) ],
24 'debug' => [ qw(FUSE_DEBUG) ],
25 'xattr' => [ qw(XATTR_CREATE XATTR_REPLACE) ]
28 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
33 our $VERSION = '0.06';
36 # This AUTOLOAD is used to 'autoload' constants from the constant()
37 # XS function. If a constant is not found then control is passed
38 # to the AUTOLOAD in AutoLoader.
42 ($constname = $AUTOLOAD) =~ s/.*:://;
43 croak "& not defined" if $constname eq 'constant';
44 my $val = constant($constname, @_ ? $_[0] : 0);
47 $AutoLoader::AUTOLOAD = $AUTOLOAD;
48 goto &AutoLoader::AUTOLOAD;
51 croak "Your vendor has not defined Fuse macro $constname";
56 # Fixed between 5.005_53 and 5.005_61
58 *$AUTOLOAD = sub () { $val };
61 *$AUTOLOAD = sub { $val };
77 bootstrap Fuse $VERSION;
80 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
82 rename link chmod chown truncate utime open read write statfs
83 flush release fsync setxattr getxattr listxattr removexattr);
84 my (@validOpts) = qw(allow_other);
86 my (%mapping) = map { $_ => $tmp++ } (@names);
87 my (%optmap) = map { $_ => 1 } (@validOpts);
88 my (%otherargs) = (debug=>0, mountpoint=>"", mountopts=>"");
89 while(my $name = shift) {
91 if(exists($otherargs{$name})) {
92 $otherargs{$name} = $subref;
94 croak "There is no function $name" unless exists($mapping{$name});
95 croak "Usage: Fuse::main(getattr => &my_getattr, ...)" unless $subref;
96 croak "Usage: Fuse::main(getattr => &my_getattr, ...)" unless ref($subref);
97 croak "Usage: Fuse::main(getattr => &my_getattr, ...)" unless ref($subref) eq "CODE";
98 $subs[$mapping{$name}] = $subref;
101 foreach my $opt ( split(/,/,$otherargs{mountopts}) ) {
102 if ( ! exists($optmap{$opt}) ) {
103 croak "Use of an invalid mountopt argument";
106 perl_fuse_main($otherargs{debug},$otherargs{mountpoint},$otherargs{mountopts},@subs);
109 # Autoload methods go after =cut, and are processed by the autosplit program.
116 Fuse - write filesystems in Perl using FUSE
121 my ($mountpoint) = "";
122 $mountpoint = shift(@ARGV) if @ARGV;
123 Fuse::main(mountpoint=>$mountpoint, getattr=>\&my_getattr, getdir=>\&my_getdir, ...);
127 This lets you implement filesystems in perl, through the FUSE
128 (Filesystem in USErspace) kernel/lib interface.
130 FUSE expects you to implement callbacks for the various functions.
132 NOTE: I have only tested the things implemented in example.pl!
133 It should work, but some things may not.
135 In the following definitions, "errno" can be 0 (for a success),
136 -EINVAL, -ENOENT, -EONFIRE, any integer less than 1 really.
138 You can import standard error constants by saying something like
139 "use POSIX qw(EDOTDOT ENOANO);".
141 Every constant you need (file types, open() flags, error values,
142 etc) can be imported either from POSIX or from Fcntl, often both.
143 See their respective documentations, for more information.
145 =head2 EXPORTED SYMBOLS
147 FUSE_DEBUG by default.
149 You can request all exportable symbols by using the tag ":all".
151 You can request all debug symbols by using the tag ":debug".
152 This will export FUSE_DEBUG.
154 You can request the extended attribute symbols by using the tag ":xattr".
155 This will export XATTR_CREATE and XATTR_REPLACE.
161 Takes arguments in the form of hash key=>value pairs. There are
162 many valid keys. Most of them correspond with names of callback
163 functions, as described in section 'FUNCTIONS YOUR FILESYSTEM MAY IMPLEMENT'.
164 A few special keys also exist:
171 This turns FUSE call tracing on and off. Default is 0 (which means off).
179 The point at which to mount this filesystem. There is no default, you must
180 specify this. An example would be '/mnt'.
188 This is a comma seperated list of mount options to pass to the FUSE kernel
191 At present, it allows the specification of the allow_other
192 argument when mounting the new FUSE filesystem. To use this, you will also
193 need 'user_allow_other' in /etc/fuse.conf as per the FUSE documention
195 mountopts => "allow_other" or
200 unthreaded => boolean
204 This turns FUSE multithreading off and on. NOTE: This perlmodule does not
205 currently work properly in multithreaded mode! The author is unfortunately
206 not familiar enough with perl-threads internals, and according to the
207 documentation available at time of writing (2002-03-08), those internals are
208 subject to changing anyway. Note that singlethreaded mode also means that
209 you will not have to worry about reentrancy, though you will have to worry
210 about recursive lookups (since the kernel holds a global lock on your
211 filesystem and blocks waiting for one callback to complete before calling
214 I hope to add full multithreading functionality later, but for now, I
215 recommend you leave this option at the default, 1 (which means
216 unthreaded, no threads will be used and no reentrancy is needed).
220 =head2 FUNCTIONS YOUR FILESYSTEM MAY IMPLEMENT
225 Returns a list, very similar to the 'stat' function (see
226 perlfunc). On error, simply return a single numeric scalar
227 value (e.g. "return -ENOENT();").
229 FIXME: the "ino" field is currently ignored. I tried setting it to 0
230 in an example script, which consistently caused segfaults.
232 Fields (the following was stolen from perlfunc(1) with apologies):
234 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
235 $atime,$mtime,$ctime,$blksize,$blocks)
236 = getattr($filename);
238 Here are the meaning of the fields:
240 0 dev device number of filesystem
242 2 mode file mode (type and permissions)
243 3 nlink number of (hard) links to the file
244 4 uid numeric user ID of file's owner
245 5 gid numeric group ID of file's owner
246 6 rdev the device identifier (special files only)
247 7 size total size of file, in bytes
248 8 atime last access time in seconds since the epoch
249 9 mtime last modify time in seconds since the epoch
250 10 ctime inode change time (NOT creation time!) in seconds
252 11 blksize preferred block size for file system I/O
253 12 blocks actual number of blocks allocated
255 (The epoch was at 00:00 January 1, 1970 GMT.)
259 Arguments: link pathname.
260 Returns a scalar: either a numeric constant, or a text string.
262 This is called when dereferencing symbolic links, to learn the target.
264 example rv: return "/proc/self/fd/stdin";
268 Arguments: Containing directory name.
269 Returns a list: 0 or more text strings (the filenames), followed by a numeric errno (usually 0).
271 This is used to obtain directory listings. Its opendir(), readdir(), filldir() and closedir() all in one call.
273 example rv: return ('.', 'a', 'b', 0);
277 Arguments: Filename, numeric modes, numeric device
278 Returns an errno (0 upon success, as usual).
280 This function is called for all non-directory, non-symlink nodes,
285 Arguments: New directory pathname, numeric modes.
288 Called to create a directory.
295 Called to remove a file, device, or symlink.
302 Called to remove a directory.
306 Arguments: Existing filename, symlink name.
309 Called to create a symbolic link.
313 Arguments: old filename, new filename.
316 Called to rename a file, and/or move a file from one directory to another.
320 Arguments: Existing filename, hardlink name.
323 Called to create hard links.
327 Arguments: Pathname, numeric modes.
330 Called to change permissions on a file/directory/device/symlink.
334 Arguments: Pathname, numeric uid, numeric gid.
337 Called to change ownership of a file/directory/device/symlink.
341 Arguments: Pathname, numeric offset.
344 Called to truncate a file, at the given offset.
348 Arguments: Pathname, numeric actime, numeric modtime.
351 Called to change access/modification times for a file/directory/device/symlink.
355 Arguments: Pathname, numeric flags (which is an OR-ing of stuff like O_RDONLY
356 and O_SYNC, constants you can import from POSIX).
359 No creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) will be passed to open().
360 Your open() method needs only check if the operation is permitted for the given flags, and return 0 for success.
364 Arguments: Pathname, numeric requestedsize, numeric offset.
365 Returns a numeric errno, or a string scalar with up to $requestedsize bytes of data.
367 Called in an attempt to fetch a portion of the file.
371 Arguments: Pathname, scalar buffer, numeric offset. You can use length($buffer) to
375 Called in an attempt to write (or overwrite) a portion of the file. Be prepared because $buffer could contain random binary data with NULLs and all sorts of other wonderful stuff.
380 Returns any of the following:
386 $namelen, $files, $files_free, $blocks, $blocks_avail, $blocksize
390 -ENOANO(), $namelen, $files, $files_free, $blocks, $blocks_avail, $blocksize
395 Returns an errno or 0 on success.
397 Called to synchronise any cached data. This is called before the file
398 is closed. It may be called multiple times before a file is closed.
402 Arguments: Pathname, numeric flags passed to open
403 Returns an errno or 0 on success.
405 Called to indicate that there are no more references to the file. Called once
406 for every file with the same pathname and flags as were passed to open.
410 Arguments: Pathname, numeric flags
411 Returns an errno or 0 on success.
413 Called to synchronise the file's contents. If flags is non-zero,
414 only synchronise the user data. Otherwise synchronise the user and meta data.
418 Arguments: Pathname, extended attribute's name, extended attribute's value, numeric flags (which is an OR-ing of XATTR_CREATE and XATTR_REPLACE
419 Returns an errno or 0 on success.
421 Called to set the value of the named extended attribute.
423 If you wish to reject setting of a particular form of extended attribute name
424 (e.g.: regexps matching user\..* or security\..*), then return - EOPNOTSUPP.
426 If flags is set to XATTR_CREATE and the extended attribute already exists,
427 this should fail with - EEXIST. If flags is set to XATTR_REPLACE
428 and the extended attribute doesn't exist, this should fail with - ENOATTR.
430 XATTR_CREATE and XATTR_REPLACE are provided by this module, but not exported
431 by default. To import them:
441 Arguments: Pathname, extended attribute's name
442 Returns an errno, 0 if there was no value, or the extended attribute's value.
444 Called to get the value of the named extended attribute.
449 Returns a list: 0 or more text strings (the extended attribute names), followed by a numeric errno (usually 0).
453 Arguments: Pathname, extended attribute's name
454 Returns an errno or 0 on success.
458 Mark Glines, E<lt>mark@glines.orgE<gt>
462 L<perl>, the FUSE documentation.