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, threaded=>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 => \"main::my_getattr\", ...)" unless $subref;
96 $subs[$mapping{$name}] = $subref;
99 foreach my $opt ( split(/,/,$otherargs{mountopts}) ) {
100 if ( ! exists($optmap{$opt}) ) {
101 croak "Use of an invalid mountopt argument";
104 perl_fuse_main($otherargs{debug},$otherargs{threaded},$otherargs{mountpoint},$otherargs{mountopts},@subs);
107 # Autoload methods go after =cut, and are processed by the autosplit program.
114 Fuse - write filesystems in Perl using FUSE
119 my ($mountpoint) = "";
120 $mountpoint = shift(@ARGV) if @ARGV;
121 Fuse::main(mountpoint=>$mountpoint, getattr=>"main::my_getattr", getdir=>"main::my_getdir", ...);
125 This lets you implement filesystems in perl, through the FUSE
126 (Filesystem in USErspace) kernel/lib interface.
128 FUSE expects you to implement callbacks for the various functions.
130 In the following definitions, "errno" can be 0 (for a success),
131 -EINVAL, -ENOENT, -EONFIRE, any integer less than 1 really.
133 You can import standard error constants by saying something like
134 "use POSIX qw(EDOTDOT ENOANO);".
136 Every constant you need (file types, open() flags, error values,
137 etc) can be imported either from POSIX or from Fcntl, often both.
138 See their respective documentations, for more information.
140 =head2 EXPORTED SYMBOLS
142 FUSE_DEBUG by default.
144 You can request all exportable symbols by using the tag ":all".
146 You can request all debug symbols by using the tag ":debug".
147 This will export FUSE_DEBUG.
149 You can request the extended attribute symbols by using the tag ":xattr".
150 This will export XATTR_CREATE and XATTR_REPLACE.
156 Takes arguments in the form of hash key=>value pairs. There are
157 many valid keys. Most of them correspond with names of callback
158 functions, as described in section 'FUNCTIONS YOUR FILESYSTEM MAY IMPLEMENT'.
159 A few special keys also exist:
166 This turns FUSE call tracing on and off. Default is 0 (which means off).
174 The point at which to mount this filesystem. There is no default, you must
175 specify this. An example would be '/mnt'.
183 This is a comma seperated list of mount options to pass to the FUSE kernel
186 At present, it allows the specification of the allow_other
187 argument when mounting the new FUSE filesystem. To use this, you will also
188 need 'user_allow_other' in /etc/fuse.conf as per the FUSE documention
190 mountopts => "allow_other" or
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.
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.
217 (If enabled, this option will cause a warning if your perl interpreter was not
218 built with USE_ITHREADS.)
222 =head2 FUNCTIONS YOUR FILESYSTEM MAY IMPLEMENT
227 Returns a list, very similar to the 'stat' function (see
228 perlfunc). On error, simply return a single numeric scalar
229 value (e.g. "return -ENOENT();").
231 FIXME: the "ino" field is currently ignored. I tried setting it to 0
232 in an example script, which consistently caused segfaults.
234 Fields (the following was stolen from perlfunc(1) with apologies):
236 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
237 $atime,$mtime,$ctime,$blksize,$blocks)
238 = getattr($filename);
240 Here are the meaning of the fields:
242 0 dev device number of filesystem
244 2 mode file mode (type and permissions)
245 3 nlink number of (hard) links to the file
246 4 uid numeric user ID of file's owner
247 5 gid numeric group ID of file's owner
248 6 rdev the device identifier (special files only)
249 7 size total size of file, in bytes
250 8 atime last access time in seconds since the epoch
251 9 mtime last modify time in seconds since the epoch
252 10 ctime inode change time (NOT creation time!) in seconds
254 11 blksize preferred block size for file system I/O
255 12 blocks actual number of blocks allocated
257 (The epoch was at 00:00 January 1, 1970 GMT.)
261 Arguments: link pathname.
262 Returns a scalar: either a numeric constant, or a text string.
264 This is called when dereferencing symbolic links, to learn the target.
266 example rv: return "/proc/self/fd/stdin";
270 Arguments: Containing directory name.
271 Returns a list: 0 or more text strings (the filenames), followed by a numeric errno (usually 0).
273 This is used to obtain directory listings. Its opendir(), readdir(), filldir() and closedir() all in one call.
275 example rv: return ('.', 'a', 'b', 0);
279 Arguments: Filename, numeric modes, numeric device
280 Returns an errno (0 upon success, as usual).
282 This function is called for all non-directory, non-symlink nodes,
287 Arguments: New directory pathname, numeric modes.
290 Called to create a directory.
297 Called to remove a file, device, or symlink.
304 Called to remove a directory.
308 Arguments: Existing filename, symlink name.
311 Called to create a symbolic link.
315 Arguments: old filename, new filename.
318 Called to rename a file, and/or move a file from one directory to another.
322 Arguments: Existing filename, hardlink name.
325 Called to create hard links.
329 Arguments: Pathname, numeric modes.
332 Called to change permissions on a file/directory/device/symlink.
336 Arguments: Pathname, numeric uid, numeric gid.
339 Called to change ownership of a file/directory/device/symlink.
343 Arguments: Pathname, numeric offset.
346 Called to truncate a file, at the given offset.
350 Arguments: Pathname, numeric actime, numeric modtime.
353 Called to change access/modification times for a file/directory/device/symlink.
357 Arguments: Pathname, numeric flags (which is an OR-ing of stuff like O_RDONLY
358 and O_SYNC, constants you can import from POSIX).
361 No creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) will be passed to open().
362 Your open() method needs only check if the operation is permitted for the given flags, and return 0 for success.
366 Arguments: Pathname, numeric requestedsize, numeric offset.
367 Returns a numeric errno, or a string scalar with up to $requestedsize bytes of data.
369 Called in an attempt to fetch a portion of the file.
373 Arguments: Pathname, scalar buffer, numeric offset. You can use length($buffer) to
377 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.
382 Returns any of the following:
388 $namelen, $files, $files_free, $blocks, $blocks_avail, $blocksize
392 -ENOANO(), $namelen, $files, $files_free, $blocks, $blocks_avail, $blocksize
397 Returns an errno or 0 on success.
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.
404 Arguments: Pathname, numeric flags passed to open
405 Returns an errno or 0 on success.
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.
412 Arguments: Pathname, numeric flags
413 Returns an errno or 0 on success.
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.
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.
423 Called to set the value of the named extended attribute.
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.
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.
432 XATTR_CREATE and XATTR_REPLACE are provided by this module, but not exported
433 by default. To import them:
443 Arguments: Pathname, extended attribute's name
444 Returns an errno, 0 if there was no value, or the extended attribute's value.
446 Called to get the value of the named extended attribute.
451 Returns a list: 0 or more text strings (the extended attribute names), followed by a numeric errno (usually 0).
455 Arguments: Pathname, extended attribute's name
456 Returns an errno or 0 on success.
460 Mark Glines, E<lt>mark@glines.orgE<gt>
464 L<perl>, the FUSE documentation.