Class: FFI::Libfuse::FuseOperations

Inherits:
Struct
  • Object
show all
Includes:
FuseCallbacks
Defined in:
lib/ffi/libfuse/fuse_operations.rb

Overview

The file system operations as specified in libfuse.

All Callback methods are optional, but some are essential for a useful filesystem e.g. #getattr,#readdir

Almost all callback operations take a path which can be of any length and will return 0 for success or a negative Errno value on failure.

Constant Summary collapse

VOID_RETURN =

Callbacks that have no return value

i[init destroy].freeze
MEANINGFUL_RETURN =

Callbacks that are expected to return meaningful positive integers

i[read write write_buf lseek copy_file_range getxattr listxattr].freeze

FUSE Callbacks collapse

Class Method Summary collapse

Methods included from FuseCallbacks

#fuse_respond_to?, #fuse_wrappers

Methods included from Callbacks

#register

Constructor Details

#initialize(fuse_wrappers: [], fuse_flags: [], delegate: self) ⇒ FuseOperations

Returns a new instance of FuseOperations.

Build a FuseOperations struct and register callback methods

The methods to register are identified by delegate.FFI::Libfuse::FuseCallbacks#fuse_respond_to? if available otherwise delegate.respond_to? is used.



938
939
940
941
942
943
944
945
946
947
948
# File 'lib/ffi/libfuse/fuse_operations.rb', line 938

def initialize(*args, fuse_wrappers: [], fuse_flags: [], delegate: self)
  super(*args) # FFI::Struct constructor
  return if args.any? # only configure if this is a new allocation

  initialize_callbacks(wrappers: fuse_wrappers, delegate: delegate)

  return unless FUSE_MAJOR_VERSION < 3

  fuse_flags.concat(delegate.fuse_flags) if delegate.respond_to?(:fuse_flags)
  send(:[]=, :flags, fuse_flags.uniq)
end

Class Method Details

.fuse_callbacksSet<Symbol>



107
108
109
# File 'lib/ffi/libfuse/fuse_operations.rb', line 107

def fuse_callbacks
  @fuse_callbacks ||= Set.new(members - [:flags])
end

.meaningful_return?(fuse_callback) ⇒ Boolean



77
78
79
# File 'lib/ffi/libfuse/fuse_operations.rb', line 77

def meaningful_return?(fuse_callback)
  MEANINGFUL_RETURN.include?(fuse_callback)
end

.path_arg_methods(fuse_callback) ⇒ Symbol

Helper to determine how to handle the path argument for a path callback

Examples:

def wrap_callback(fuse_method, *args)
    read, remove, add = FFI::Libfuse::FuseOperations.path_arg_methods(fuse_method)
    path = args.send(read)
    # ... do something with path

    path = args.send(remove)
    # ... do something to make an alternate path
    args.send(add, adjusted_path)
    delegate.send(fuse_methoed, *args)
end


102
103
104
# File 'lib/ffi/libfuse/fuse_operations.rb', line 102

def path_arg_methods(fuse_callback)
  CALLBACK_PATH_ARG_METHODS[fuse_callback]
end

.path_callbacksSet<Symbol>



112
113
114
# File 'lib/ffi/libfuse/fuse_operations.rb', line 112

def path_callbacks
  @path_callbacks ||= fuse_callbacks - VOID_RETURN
end

.void_return?(fuse_callback) ⇒ Boolean



82
83
84
# File 'lib/ffi/libfuse/fuse_operations.rb', line 82

def void_return?(fuse_callback)
  VOID_RETURN.include?(fuse_callback)
end

Instance Method Details

#access(path, mode) ⇒ Integer

This method is abstract.

Check file access permissions

This will be called for the access() system call. If the 'default_permissions' mount option is given, this method is not called.

This method is not called under Linux kernel versions 2.4.x

See Also:

  • access(2)


# File 'lib/ffi/libfuse/fuse_operations.rb', line 565


#bmap(path, blocksize, index) ⇒ Integer

This method is abstract.
Note:

This makes sense only for block device backed filesystem mounted with the 'blkdev' option

Map block index within file to block index within device



# File 'lib/ffi/libfuse/fuse_operations.rb', line 683


#chmod(path, mode, fuse_file_info = nil) ⇒ Integer

This method is abstract.

Change the permission bits of a file



# File 'lib/ffi/libfuse/fuse_operations.rb', line 247


#chown(path, uid, gid, fuse_file_info = nil) ⇒ Integer

This method is abstract.

Change the owner and group of a file



# File 'lib/ffi/libfuse/fuse_operations.rb', line 260


#copy_file_range(path_in, fi_in, offset_in, path_out, fi_out, offset_out, size, flags) ⇒ Integer

This method is abstract.

Copy a range of data from one file to another

Performs an optimized copy between two file descriptors without the additional cost of transferring data through the FUSE kernel module to user space (glibc) and then back into the FUSE filesystem again.

In case this method is not implemented, glibc falls back to reading data from the source and writing to the destination. Effectively doing an inefficient copy of the data.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 862


#create(path, mode, fuse_file_info) ⇒ Integer

This method is abstract.

Create and open a file

If the file does not exist, first create it with the specified mode, and then open it.

If this method is not implemented or under Linux kernel versions earlier than 2.6.15, the mknod() and open() methods will be called instead.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 582


#destroy(obj) ⇒ Object

This method is abstract.

Clean up filesystem. Called on filesystem exit.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 554


#fallocate(path, mode, offset, len, fuse_file_info) ⇒ Object

This method is abstract.

Allocates space for an open file

This function ensures that required space is allocated for specified file. If this function returns success then any subsequent write request to specified range is guaranteed not to fail because of lack of space on the file system media.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 835


#fgetattr(path, stat, fuse_file_info) ⇒ Integer

Deprecated.

in Fuse3 implement #getattr instead

Get attributes from an open file

This method is called instead of the getattr() method if the file information is available.

Currently this is only called after the create() method if that is implemented (see above). Later it may be called for invocations of fstat() too.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 618


#flock(path, fuse_file_info, op) ⇒ Object

This method is abstract.

Perform BSD file locking operation

@note: if this method is not implemented, the kernel will still allow file locking to work locally. Hence it is only interesting for network filesystem and similar.

See Also:

  • flock(2)


# File 'lib/ffi/libfuse/fuse_operations.rb', line 815


#flush(path, fuse_file_info) ⇒ Integer

Possibly flush cached data

BIG NOTE: This is not equivalent to fsync(). It's not a request to sync dirty data.

Flush is called on each close() of a file descriptor. So if a filesystem wants to return write errors in close() and the file has cached dirty data, this is a good place to write back data and return any errors. Since many applications ignore close() errors this is not always useful.

NOTE: The flush() method may be called more than once for each open(). This happens if more than one file descriptor refers to an opened file due to dup(), dup2() or fork() calls. It is not possible to determine if a flush is final, so each flush should be treated equally. Multiple write-flush sequences are relatively rare, so this shouldn't be a problem.

Filesystems shouldn't assume that flush will always be called after some writes, or that if will be called at all.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 361


#fsync(path, datasync, fuse_file_info) ⇒ Integer

Synchronize file contents



# File 'lib/ffi/libfuse/fuse_operations.rb', line 404


#fsyncdir(path, datasync, fuse_file_info) ⇒ Integer

Synchronize directory contents



# File 'lib/ffi/libfuse/fuse_operations.rb', line 522


#ftruncate(path, offset, fuse_file_info) ⇒ Integer

Deprecated.

in Fuse3 implement #truncate instead

This method is abstract.

Change the size of an open file

This method is called instead of the truncate() method if the truncation was invoked from an ftruncate() system call.

If this method is not implemented or under Linux kernel versions earlier than 2.6.15, the truncate() method will be called instead.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 599


#fuse_flagsArray<Symbol>

Deprecated.

in Fuse3 use fuse_config object in #init

This method is abstract.
Note:

Not available in Fuse3

Configuration method to set fuse flags

  • :nullpath_ok

Flag indicating that the filesystem can accept a NULL path as the first argument for the following operations: read, write, flush, release, fsync, readdir, releasedir, fsyncdir, ftruncate, fgetattr, lock, ioctl and poll

If this flag is set these operations continue to work on unlinked files even if "-ohard_remove" option was specified.

  • :nopath

Flag indicating that the path need not be calculated for the following operations: read, write, flush, release, fsync, readdir, releasedir, fsyncdir, ftruncate, fgetattr, lock, ioctl and poll

Closely related to flag_nullpath_ok, but if this flag is set then the path will not be calculaged even if the file wasn't unlinked. However the path can still be non-NULL if it needs to be calculated for some other reason.

  • :utime_omit_ok

Flag indicating that the filesystem accepts special UTIME_NOW and UTIME_OMIT values in its utimens operation.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 698


#getattr(path, stat, fuse_file_info = nil) ⇒ Integer

This method is abstract.

Get file attributes.

Similar to stat(). The 'st_dev' and 'st_blksize' fields are ignored. The 'st_ino' field is ignored except if the 'use_ino' mount option is given.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 127


#getdirObject

Deprecated.

use #readdir instead



# File 'lib/ffi/libfuse/fuse_operations.rb', line 161


#getxattr(path, name, buf, size) ⇒ Integer

This method is abstract.

Get extended attributes

See Also:

  • getxattr(2)


# File 'lib/ffi/libfuse/fuse_operations.rb', line 430


#init(fuse_conn_info, fuse_config = nil) ⇒ Object

This method is abstract.

Initialize filesystem



# File 'lib/ffi/libfuse/fuse_operations.rb', line 533


#ioctl(path, cmd, arg, fuse_file_info, flags, data) ⇒ Object

This method is abstract.

Ioctl The size and direction of data is determined by IOC*() decoding of cmd. For _IOC_NONE, data will be NULL, for _IOC_WRITE data is out area, for _IOC_READ in area and if both are set in/out area. In all non-NULL cases, the area is of _IOC_SIZE(cmd) bytes.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 734


This method is abstract.

Create a hard link to a file

See Also:

  • rename(2)


# File 'lib/ffi/libfuse/fuse_operations.rb', line 236


#listxattr(path, buf, size) ⇒ Integer

This method is abstract.

List extended attributes

See Also:

  • listxattr(2)


# File 'lib/ffi/libfuse/fuse_operations.rb', line 443


#lock(path, fuse_file_info, cmd, flock) ⇒ Integer

This method is abstract.
Note:

if this method is not implemented, the kernel will still allow file locking to work locally. Hence it

Perform POSIX file locking operation For :f_getlk operation, the library will first check currently held locks, and if a conflicting lock is found it will return information without calling this method. This ensures, that for local locks the pid field is correctly filled in. The results may not be accurate in case of race conditions and in the presence of hard links, but its unlikely that an application would rely on accurate GETLK results in these cases. If a conflicting lock is not found, this method will be called, and the filesystem may fill out l_pid by a meaningful value, or it may leave this field zero.

For :f_setlk and :f_setlkw the pid field will be set to the pid of the process performing the locking operation.

is only interesting for network filesystem and similar.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 635


#lseek(path, offset, whence, fuse_file_info) ⇒ Integer

This method is abstract.

Find next data or hole after the specified offset

See Also:

  • lseek(2)


# File 'lib/ffi/libfuse/fuse_operations.rb', line 893


#mkdir(path, mode) ⇒ Integer

This method is abstract.

Create a directory

Note that the mode argument may not have the type specification bits set, i.e. S_ISDIR(mode) can be false. To obtain the correct directory type bits use mode | Stat::S_IFDIR



# File 'lib/ffi/libfuse/fuse_operations.rb', line 181


#mknod(path, mode, dev) ⇒ Integer

Create a file node

This is called for creation of all non-directory, non-symlink nodes. If the filesystem defines a create() method, then for regular files that will be called instead.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 167


#open(path, fuse_file_info) ⇒ Integer

This method is abstract.

File open operation

No creation (O_CREAT, O_EXCL) and by default also no truncation (O_TRUNC) flags will be passed to open(). If an application specifies O_TRUNC, fuse first calls truncate() and then open(). Only if 'atomic_o_trunc' has been specified and kernel version is 2.6.24 or later, O_TRUNC is passed on to open.

Unless the 'default_permissions' mount option is given, open should check if the operation is permitted for the given flags.

Optionally open may also return an arbitrary filehandle in the fuse_file_info structure, which will be passed to all file operations.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 291


#opendir(path, fuse_file_info) ⇒ Object

This method is abstract.

Open directory

Unless the 'default_permissions' mount option is given, this method should check if opendir is permitted for this directory. Optionally opendir may also return an arbitrary filehandle in the fuse_file_info structure, which will be passed to readdir, releasedir and fsyncdir.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 468


#poll(path, fuse_file_info, ph, reventsp) ⇒ Integer

This method is abstract.

Poll for IO readiness events

See Also:

  • poll(2)


# File 'lib/ffi/libfuse/fuse_operations.rb', line 757


#read(path, buf, size, offset, fuse_file_info) ⇒ Integer

This method is abstract.

Read data from an open file



# File 'lib/ffi/libfuse/fuse_operations.rb', line 313


#read_buf(path, bufp, size, offset, fuse_file_info) ⇒ Object

This method is abstract.

Similar to the #read method, but data is stored and returned in a generic buffer.

No actual copying of data has to take place, the source file descriptor may simply be stored in the buffer for later data transfer.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 795


#readdir(path, buffer, filler, offset, fuse_file_info, fuse_readdir_flag = 0) ⇒ Integer

This method is abstract.

Read directory

The filesystem may choose between two modes of operation:

1) The readdir implementation ignores the offset parameter, and passes zero to the filler function's offset. The filler function will not return '1' (unless an error happens), so the whole directory is read in a single readdir operation.

2) The readdir implementation keeps track of the offsets of the directory entries. It uses the offset parameter and always passes non-zero offset to the filler function. When the buffer is full (or an error happens) the filler function will return '1'.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 483


This method is abstract.

Resolve the target of a symbolic link



# File 'lib/ffi/libfuse/fuse_operations.rb', line 144


#release(path, fuse_file_info) ⇒ Integer

Release an open file

Release is called when there are no more references to an open file: all file descriptors are closed and all memory mappings are unmapped.

For every open() call there will be exactly one release() call with the same flags and file descriptor. It is possible to have a file opened more than once, in which case only the last release will mean, that no more reads \/ writes will happen on the file.



# File 'lib/ffi/libfuse/fuse_operations.rb', line 386


#releasedir(path, fuse_file_info) ⇒ Integer

Release directory



# File 'lib/ffi/libfuse/fuse_operations.rb', line 513


#removexattr(path, name) ⇒ Integer

This method is abstract.

Remove extended attributes

See Also:

  • removexattr(2)


# File 'lib/ffi/libfuse/fuse_operations.rb', line 455


#rename(from_path, to_path) ⇒ Integer

This method is abstract.

Rename a file



# File 'lib/ffi/libfuse/fuse_operations.rb', line 225


#rmdir(path) ⇒ Integer

This method is abstract.

Remove a directory



# File 'lib/ffi/libfuse/fuse_operations.rb', line 205


#setxattr(path, name, data, size, flags) ⇒ Integer

This method is abstract.

Set extended attributes

See Also:

  • setxattr(2)


# File 'lib/ffi/libfuse/fuse_operations.rb', line 416


#statfs(path, statvfs) ⇒ Integer

This method is abstract.

Get file system statistics



# File 'lib/ffi/libfuse/fuse_operations.rb', line 348


This method is abstract.

Create a symbolic link



# File 'lib/ffi/libfuse/fuse_operations.rb', line 215


#truncate(path, offset, fuse_file_info = nil) ⇒ Integer

This method is abstract.

Change the size of a file



# File 'lib/ffi/libfuse/fuse_operations.rb', line 274


This method is abstract.

Remove a file



# File 'lib/ffi/libfuse/fuse_operations.rb', line 195


#utimens(path, time_specs, fuse_file_info = nil) ⇒ Integer

This method is abstract.

Change the access and modification times of a file with nanosecond resolution

This supersedes the old utime() interface. New applications should use this.

See Also:

  • utimensat(2)


# File 'lib/ffi/libfuse/fuse_operations.rb', line 665


#write(path, data, size, offset, fuse_file_info) ⇒ Integer

This method is abstract.

Write data to an open file



# File 'lib/ffi/libfuse/fuse_operations.rb', line 331


#write_buf(path, buf, offset, fuse_file_info) ⇒ Integer

This method is abstract.

Write contents of buffer to an open file

Similar to the #write method, but data is supplied in a generic buffer. Use FFI::Libfuse::FuseBufVec#copy_to_fd to copy data to an open file descriptor, or FFI::Libfuse::FuseBufVec#copy_to_str to extract string data from the buffer



# File 'lib/ffi/libfuse/fuse_operations.rb', line 777