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
22 our %EXPORT_TAGS = ( 'all' => [ qw(
26 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
31 our $VERSION = '0.04';
34 # This AUTOLOAD is used to 'autoload' constants from the constant()
35 # XS function. If a constant is not found then control is passed
36 # to the AUTOLOAD in AutoLoader.
40 ($constname = $AUTOLOAD) =~ s/.*:://;
41 croak "& not defined" if $constname eq 'constant';
42 my $val = constant($constname, @_ ? $_[0] : 0);
45 $AutoLoader::AUTOLOAD = $AUTOLOAD;
46 goto &AutoLoader::AUTOLOAD;
49 croak "Your vendor has not defined Fuse macro $constname";
54 # Fixed between 5.005_53 and 5.005_61
56 *$AUTOLOAD = sub () { $val };
59 *$AUTOLOAD = sub { $val };
65 bootstrap Fuse $VERSION;
68 my (@subs) = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
69 my (@names) = qw(getattr readlink getdir mknod mkdir unlink rmdir symlink
70 rename link chmod chown truncate utime open read write statfs);
72 my (%mapping) = map { $_ => $tmp++ } (@names);
73 my (%otherargs) = (debug=>0, mountpoint=>"");
74 while(my $name = shift) {
76 if(exists($otherargs{$name})) {
77 $otherargs{$name} = $subref;
79 croak "There is no function $name" unless exists($mapping{$name});
80 croak "Usage: Fuse::main(getattr => &my_getattr, ...)" unless $subref;
81 croak "Usage: Fuse::main(getattr => &my_getattr, ...)" unless ref($subref);
82 croak "Usage: Fuse::main(getattr => &my_getattr, ...)" unless ref($subref) eq "CODE";
83 $subs[$mapping{$name}] = $subref;
86 perl_fuse_main($otherargs{debug},$otherargs{mountpoint},@subs);
89 # Autoload methods go after =cut, and are processed by the autosplit program.
96 Fuse - write filesystems in Perl using FUSE
101 my ($mountpoint) = "";
102 $mountpoint = shift(@ARGV) if @ARGV;
103 Fuse::main(mountpoint=>$mountpoint, getattr=>\&my_getattr, getdir=>\&my_getdir, ...);
107 This lets you implement filesystems in perl, through the FUSE
108 (Filesystem in USErspace) kernel/lib interface.
110 FUSE expects you to implement callbacks for the various functions.
112 NOTE: I have only tested the things implemented in example.pl!
113 It should work, but some things may not.
115 In the following definitions, "errno" can be 0 (for a success),
116 -EINVAL, -ENOENT, -EONFIRE, any integer less than 1 really.
118 You can import standard error constants by saying something like
119 "use POSIX qw(EDOTDOT ENOANO);".
121 Every constant you need (file types, open() flags, error values,
122 etc) can be imported either from POSIX or from Fcntl, often both.
123 See their respective documentations, for more information.
129 =head2 EXPORTABLE CONSTANTS
137 Takes arguments in the form of hash key=>value pairs. There are
138 many valid keys. Most of them correspond with names of callback
139 functions, as described in section 'FUNCTIONS YOUR FILESYSTEM MAY IMPLEMENT'.
140 A few special keys also exist:
147 This turns FUSE call tracing on and off. Default is 0 (which means off).
155 The point at which to mount this filesystem. There is no default, you must
156 specify this. An example would be '/mnt'.
160 unthreaded => boolean
164 This turns FUSE multithreading off and on. NOTE: This perlmodule does not
165 currently work properly in multithreaded mode! The author is unfortunately
166 not familiar enough with perl-threads internals, and according to the
167 documentation available at time of writing (2002-03-08), those internals are
168 subject to changing anyway. Note that singlethreaded mode also means that
169 you will not have to worry about reentrancy, though you will have to worry
170 about recursive lookups (since the kernel holds a global lock on your
171 filesystem and blocks waiting for one callback to complete before calling
174 I hope to add full multithreading functionality later, but for now, I
175 recommend you leave this option at the default, 1 (which means
176 unthreaded, no threads will be used and no reentrancy is needed).
180 =head2 FUNCTIONS YOUR FILESYSTEM MAY IMPLEMENT
185 Returns a list, very similar to the 'stat' function (see
186 perlfunc). On error, simply return a single numeric scalar
187 value (e.g. "return -ENOENT();").
189 FIXME: the "ino" field is currently ignored. I tried setting it to 0
190 in an example script, which consistently caused segfaults.
192 Fields (the following was stolen from perlfunc(1) with apologies):
194 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
195 $atime,$mtime,$ctime,$blksize,$blocks)
196 = getattr($filename);
198 Here are the meaning of the fields:
200 0 dev device number of filesystem
202 2 mode file mode (type and permissions)
203 3 nlink number of (hard) links to the file
204 4 uid numeric user ID of file's owner
205 5 gid numeric group ID of file's owner
206 6 rdev the device identifier (special files only)
207 7 size total size of file, in bytes
208 8 atime last access time in seconds since the epoch
209 9 mtime last modify time in seconds since the epoch
210 10 ctime inode change time (NOT creation time!) in seconds
212 11 blksize preferred block size for file system I/O
213 12 blocks actual number of blocks allocated
215 (The epoch was at 00:00 January 1, 1970 GMT.)
219 Arguments: link pathname.
220 Returns a scalar: either a numeric constant, or a text string.
222 This is called when dereferencing symbolic links, to learn the target.
224 example rv: return "/proc/self/fd/stdin";
228 Arguments: Containing directory name.
229 Returns a list: 0 or more text strings (the filenames), followed by a numeric errno (usually 0).
231 This is used to obtain directory listings. Its opendir(), readdir(), filldir() and closedir() all in one call.
233 example rv: return ('.', 'a', 'b', 0);
237 Arguments: Filename, numeric modes, numeric device
238 Returns an errno (0 upon success, as usual).
240 This function is called for all non-directory, non-symlink nodes,
245 Arguments: New directory pathname, numeric modes.
248 Called to create a directory.
255 Called to remove a file, device, or symlink.
262 Called to remove a directory.
266 Arguments: Existing filename, symlink name.
269 Called to create a symbolic link.
273 Arguments: old filename, new filename.
276 Called to rename a file, and/or move a file from one directory to another.
280 Arguments: Existing filename, hardlink name.
283 Called to create hard links.
287 Arguments: Pathname, numeric modes.
290 Called to change permissions on a file/directory/device/symlink.
294 Arguments: Pathname, numeric uid, numeric gid.
297 Called to change ownership of a file/directory/device/symlink.
301 Arguments: Pathname, numeric offset.
304 Called to truncate a file, at the given offset.
308 Arguments: Pathname, numeric actime, numeric modtime.
311 Called to change access/modification times for a file/directory/device/symlink.
315 Arguments: Pathname, numeric flags (which is an OR-ing of stuff like O_RDONLY
316 and O_SYNC, constants you can import from POSIX).
319 No creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) will be passed to open().
320 Your open() method needs only check if the operation is permitted for the given flags, and return 0 for success.
324 Arguments: Pathname, numeric requestedsize, numeric offset.
325 Returns a numeric errno, or a string scalar with up to $requestedsize bytes of data.
327 Called in an attempt to fetch a portion of the file.
331 Arguments: Pathname, scalar buffer, numeric offset. You can use length($buffer) to
335 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.
340 Returns any of the following:
346 $namelen, $files, $files_free, $blocks, $blocks_avail, $blocksize
350 -ENOANO(), $namelen, $files, $files_free, $blocks, $blocks_avail, $blocksize
354 Mark Glines, E<lt>mark@glines.orgE<gt>
358 L<perl>, the FUSE documentation.