Fuse

 view release on metacpan or  search on metacpan

Fuse.pm  view on Meta::CPAN

# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.

# This allows declaration	use Fuse ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = (
		    'all' => [ qw(FUSE_BUF_IS_FD FUSE_BUF_FD_SEEK FUSE_BUF_FD_RETRY UTIME_NOW UTIME_OMIT XATTR_CREATE XATTR_REPLACE fuse_get_context fuse_version fuse_buf_copy fuse_buf_size FUSE_IOCTL_COMPAT FUSE_IOCTL_UNRESTRICTED FUSE_IOCTL_RETRY FUSE_IOCTL_MAX_...
		    'xattr' => [ qw(XATTR_CREATE XATTR_REPLACE) ],
		    'utime' => [ qw(UTIME_NOW UTIME_OMIT) ],
		    'zerocopy' => [ qw(FUSE_BUF_IS_FD FUSE_BUF_FD_SEEK FUSE_BUF_FD_RETRY) ],
		    'ioctl' => [ qw(FUSE_IOCTL_COMPAT FUSE_IOCTL_UNRESTRICTED FUSE_IOCTL_RETRY FUSE_IOCTL_MAX_IOV) ],
		    );

our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );

our @EXPORT = ();
our $VERSION = '0.16';

sub AUTOLOAD {
    # This AUTOLOAD is used to 'autoload' constants from the constant()
    # XS function.  If a constant is not found then control is passed
    # to the AUTOLOAD in AutoLoader.

    my $constname;
    our $AUTOLOAD;
    ($constname = $AUTOLOAD) =~ s/.*:://;
    croak "& not defined" if $constname eq 'constant';
    my $val = constant($constname, @_ ? $_[0] : 0);
    if ($! != 0) {
	if ($!{EINVAL}) {
	    $AutoLoader::AUTOLOAD = $AUTOLOAD;
	    goto &AutoLoader::AUTOLOAD;
	}
	else {
	    croak "Your vendor has not defined Fuse macro $constname";
	}
    }
    {
	no strict 'refs';
	# Fixed between 5.005_53 and 5.005_61
	if ($] >= 5.00561) {
	    *$AUTOLOAD = sub () { $val };
	}
	else {
	    *$AUTOLOAD = sub { $val };
	}
    }
    goto &$AUTOLOAD;
}

bootstrap Fuse $VERSION;

use constant FUSE_IOCTL_COMPAT		=> (1 << 0);
use constant FUSE_IOCTL_UNRESTRICTED	=> (1 << 1);
use constant FUSE_IOCTL_RETRY		=> (1 << 2);
use constant FUSE_IOCTL_MAX_IOV		=> 256;

sub main {
	my @names = qw(getattr readlink getdir mknod mkdir unlink rmdir symlink
			rename link chmod chown truncate utime open read write statfs
			flush release fsync setxattr getxattr listxattr removexattr
			opendir readdir releasedir fsyncdir init destroy access
			create ftruncate fgetattr lock utimens bmap);
	my ($fuse_vmajor, $fuse_vminor, $fuse_vmicro) = fuse_version();
	my $fuse_version = $fuse_vmajor + ($fuse_vminor * 1.0 / 1_000) +
		($fuse_vmicro * 1.0 / 1_000_000);
	if ($fuse_version >= 2.008) {
		# junk doesn't contain a function pointer, and hopefully
		# never will; it's a "dead" zone in the struct
		# fuse_operations where a flag bit is declared. we don't
		# need to concern ourselves with it, and it appears any
		# arch with a 64 bit pointer will align everything to
		# 8 bytes, making the question of pointer alignment for
		# the last 2 wrapper functions no big thing.
		push(@names, qw/junk ioctl poll/);
	}
	if ($fuse_version >= 2.009) {
		push(@names, qw/write_buf read_buf flock/);
	}
	if ($fuse_version >= 2.009001) {
		push(@names, qw/fallocate/);
	}
	my @subs = map {undef} @names;
	my $tmp = 0;
	my %mapping = map { $_ => $tmp++ } @names;
	my @otherargs = qw(debug threaded mountpoint mountopts nullpath_ok utimens_as_array nopath utime_omit_ok);
	my %otherargs = (
			  debug			=> 0,
			  threaded		=> 0,
			  mountpoint		=> "",
			  mountopts		=> "",
			  nullpath_ok		=> 0,
			  utimens_as_array	=> 0,
			  nopath		=> 0,
			  utime_omit_ok		=> 0,
			);
	while(my $name = shift) {
		my ($subref) = shift;
		if(exists($otherargs{$name})) {
			$otherargs{$name} = $subref;
		} else {
			croak "Usage: Fuse::main(getattr => \"main::my_getattr\", ...)" unless $subref;
			if (exists $mapping{$name}) {
				$subs[$mapping{$name}] = $subref;
			}
			else {
				carp "There is no function $name";
			}
		}
	}
	if($otherargs{threaded}) {
		# make sure threads are both available, and loaded.
		if($Config{useithreads}) {
			if(exists($threads::{VERSION})) {
				if(exists($threads::shared::{VERSION})) {
					# threads will work.
				} else {
					carp("Thread support requires you to use threads::shared.\nThreads are disabled.\n");
					$otherargs{threaded} = 0;
				}

Fuse.pm  view on Meta::CPAN


This function is called for all non-directory, non-symlink nodes,
not just devices.

=head3 mkdir

Arguments:  New directory pathname, numeric modes.

Returns an errno.

Called to create a directory.

=head3 unlink

Arguments:  Filename.

Returns an errno.

Called to remove a file, device, or symlink.

=head3 rmdir

Arguments:  Pathname.

Returns an errno.

Called to remove a directory.

=head3 symlink

Arguments:  Existing filename, symlink name.

Returns an errno.

Called to create a symbolic link.

=head3 rename

Arguments:  old filename, new filename.

Returns an errno.

Called to rename a file, and/or move a file from one directory to another.

=head3 link

Arguments:  Existing filename, hardlink name.

Returns an errno.

Called to create hard links.

=head3 chmod

Arguments:  Pathname, numeric modes.

Returns an errno.

Called to change permissions on a file/directory/device/symlink.

=head3 chown

Arguments:  Pathname, numeric uid, numeric gid.

Returns an errno.

Called to change ownership of a file/directory/device/symlink.

=head3 truncate

Arguments:  Pathname, numeric offset.

Returns an errno.

Called to truncate a file, at the given offset.

=head3 utime

Arguments:  Pathname, numeric actime, numeric modtime.

Returns an errno.

Called to change access/modification times for a file/directory/device/symlink.

=head3 open

Arguments:  Pathname, numeric flags (which is an OR-ing of stuff like O_RDONLY
and O_SYNC, constants you can import from POSIX), fileinfo hash reference.

Returns an errno, a file handle (optional).

No creation, or truncation flags (O_CREAT, O_EXCL, O_TRUNC) will be passed to open().
The fileinfo hash reference contains flags from the Fuse open call which may be modified by the module. The only fields presently supported are:
 direct_io (version 2.4 onwards)
 keep_cache (version 2.4 onwards)
 nonseekable (version 2.8 onwards)
Your open() method needs only check if the operation is permitted for the given flags, and return 0 for success.
Optionally a file handle may be returned, which will be passed to subsequent read, write, flush, fsync and release calls.

=head3 read

Arguments:  Pathname, numeric requested size, numeric offset, file handle

Returns a numeric errno, or a string scalar with up to $requestedsize bytes of data.

Called in an attempt to fetch a portion of the file.

=head3 write

Arguments:  Pathname, scalar buffer, numeric offset, file handle.  You can use length($buffer) to
find the buffersize.
Returns length($buffer) if successful (number of bytes written).

Called in an attempt to write (or overwrite) a portion of the file.  Be prepared because $buffer could contain random binary data with NULs and all sorts of other wonderful stuff.

=head3 statfs

Arguments:  none

Returns any of the following:



( run in 0.965 second using v1.01-cache-2.11-cpan-71847e10f99 )