Fuse::Class - Base clsas for Fuse module implementation using class.
Version 0.03
Fuse::Class is just a abstract class. First, you must write subclass overriding methods like named 'getattr'. (callbacks defined in Fuse)
Subclass will be written like following:
package SampleFS; use base qw(Fuse::Class); sub getattr { my $self = shift; # instance or class is passed as first argment. my ($fname) = @_; # same as Fuse. ... return @attr; # same as Fuse. } ...
To mount your filesystem:
use SampleFS; my $fuse = SampleFS->new("your", "parameters", "here"); $fuse->main(mountpoint => '/mnt/sample', mountopts => "allow_other"); # control will be not returned until file system is unmouted...
When file on your filesystem is opened, it will be seen that method is called like this:
$fuse->open($path_name, $flags, $file_info);
This module supports writing Fuse callback as method. Method name is same as Fuse callback, but first argment is an object (it's named '$self' usually).
This is a small change for Fuse, but you can use power of OO like inheritance, encapsulation, ...
Exception handling:
Returned value will be treated as negative errno in Fuse way, but you can use exception, too. If exception is thrown in your method ("die" is called), $! will be used as errno to notify error to Fuse.
Nothing.
Create a new instance. This method is defined just for your convenience. Default implementation returns blessed empty HASHREF.
Start a main loop. Filesystem is mounted to the mountpoint pointed by option "mountpoint".
Options are taken as key=>value pair selected from following:
This option controls tracing on or off. (Default is off).
Directory name to mount filesystem like "/mnt/mypoint". This option has no default value and is mandatory.
Comma separated options for FUSE kernel module.
If true, empty pathname is passed to the methods like read, write, flush, release, fsync, readdir, releasedir, fsyncdir, ftruncate, fgetattr and lock.
To use this option, you must return file/directory handle from open, opendir and create, and you must operate file/directory by that handle insted of pathname.
Only effective on Fuse 2.8 or later.
For more information, see the documentation of Fuse.
Return a list of file attributes. Meaning of fields are same as "stat" function like this:
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks)
On error, return scalar value like -ENOENT().
This method is called to dereference symbolic link. Return a destination path string or numeric error value.
By Default implementation, returns -ENOENT(). You can leave this method if your FS does not have symlink.
Return a list of file/directory names and an errno (0 if success). ex: ('..', '.', 'a', 'b', 0)
If 'readdir' method is implemented, this function will never be called.
Return an errno (0 if success). This method is called to create an entity (device or file).
Return an errno (0 if success). This method is called to create a directory.
Return an errno (0 if success). This method is called to remove an entity (device, file or symlink).
Return an errno (0 if success). This method is called to remove a directory.
Return an errno (0 if success). This method is called to create a symbolic link.
Return an errno (0 if success). This method is called to rename/move a entity.
Return an errno (0 if success). This method is called to create a hard link.
Return an errno (0 if success). This method is called to change permissions on a entity.
Return an errno (0 if success). This method is called to change ownership of a entity.
Return an errno (0 if success). This method is called to truncate a file at the given offset.
Return an errno (0 if success). This method is called to change atime/mtime on a entity.
Return an errno, and a file handle (optional)
First style means like this:
return 0; # success
and second one is following:
return (0, $file_handle_you_made); # success and handle
FLAGS is an OR-combined value of flags (O_RDONLY, O_SYNC, etc). FILE_INFO is a hashref.
Returned file handle will be passed to subsequent method call to operate on opend file.
Return an errno, or string scalar of read data.
This method is called to read data (SIZE bytes) at the given offset of opened file.
Return a written byte size or an errno.
This method is called to write data (BUFFER) at the given offset of opened file.
Return status of filesystem in one of follwing style:
or
Return an errno (0 if success). This method is called to synchronize any cached data.
Return an errno (0 if success).
FLAGS is a same value passed when 'open' is called.
Called to indicate that there are no more references to the file and flags.
Called to synchronize file contents.
DATA_SYNC indicates 'user data only'. If DATA_SYNC is non-zero, only the user data should be synchronized. Otherwise synchronize user and meta data.
FLAGS is OR-ed value of Fuse::XATTR_CREATE and Fuse::XATTR_REPLACE
This method is called to set extended attribute.
-EOPNOTSUPP means that setting the attribute is rejected.
If XATTR_CREATE is passed and the attribute already exists, return -EEXIST.
If XATTR_REPLACE is passed and the attribute does not exist, return -ENOATTR.
By default implementation, returns -EOPNOTSUPP. You can leave this method if your FS does not have any extended attributes.
Return attribute value or errno (0 if no value).
This method is called to get extended attribute value.
By default implementation, returns 0. You can leave this method if your FS does not have any extended attributes.
Return a list of attribute names and an errno (0 if success). ex: ('attr1', 'attr2', 'attr3', 0)
This method is called to remove an attribute from entity.
Return an errno, and a directory handle (optional).
This method is called to open a directory for reading. If special handling is required to open a directory, this method can be implemented.
Supported by Fuse version 2.3 or later.
(HANDLE is optional. see opendir)
Return list consists of entries and an errno. Most simple style is same as getdir(). ex: ('..', '.', 'a', 'b', 0)
Entry can be array ref containing offset and attributes in following way:
([1, '..'], [2, '.'], [3, 'a'], [4, 'b', ], 0)
or ([1, '..', [array_like_getattr]], [2, '.', [array_like_getattr]], 0)
Called to indicate that there are no more references to the opened directory.
Return an errno (0 if success). This method is called to synchronize user data (FLAG is non-zero value) or user data and meta data in directory.
You can return scalar. It can be accessed using fuse_get_context().
(SCALAR_VALUE is returned value by init method)
This method is called to determine if user can access the file. For more information, see Fuse document and manual for access(2).
Supported by Fuse version 2.5 or later.
This method is called to create a file with MASK (like mknod) and open it with MODE atomically. If this method is not implemented, mknod() and open() will be used.
(HANDLE is optional. see open)
Return an errno (0 if success). This method is called to truncate an opened file at the given offset.
Return a list of file attributes like getattr(). This method is called to get attributes for opened file.
This method is called to lock or unlock regions of file. Parameters for locking is passed in LOCK_PARAMS as hashref.
Supported by Fuse version 2.6 or later.
Return an errno (0 if success). This method is called to change atime/mtime on a entity. (Time has a resolution in nanosecond.)
Return 0 and physical block numeber on success, otherwise errno.
This method is called to get physical block offset on block device.
Toshimitsu FUJIWARA, <tttfjw at gmail.com>
<tttfjw at gmail.com>
Threading is not tested.
Copyright 2008-2011 Toshimitsu FUJIWARA, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Fuse
To install Fuse::Class, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Fuse::Class
CPAN shell
perl -MCPAN -e shell install Fuse::Class
For more information on module installation, please visit the detailed CPAN module installation guide.