Module: FFI::Libfuse::Adapter::Safe

Included in:
Debug
Defined in:
lib/ffi/libfuse/adapter/safe.rb

Overview

Safe callbacks convert return values into integer responses, and rescues errors

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.safe_callback(fuse_method, *args, default_errno: Errno::ENOTRECOVERABLE::Errno) ⇒ nil, Integer

Process the result of yielding to the fuse callback to provide a safe return value to libfuse

For callbacks in FuseOperations::VOID_RETURN

  • the return value and any unexpected errors raised are ignored

For callbacks in FuseOperations::MEANINGFUL_RETURN

  • should raise appropriate Errno error for expected errors (eg Errno::ENOENT)
  • must return a value convertable to an integer (via :to_i) - either a positive meaningful value or a negative errno value which will be returned directly
  • otherwise default_errno is returned

For remaining path callbacks

  • should raise appropriate Errno error for expected errors (eg Errno::ENOENT)
  • may return a negative Integer (equivalent to raising the corresponding SystemCallError)
  • any other value returned is considered success and 0 is returned
  • unexpected errors raised are rescued and default_errno is returned

Parameters:

  • default_errno (Integer) (defaults to: Errno::ENOTRECOVERABLE::Errno)

    value to return for any unexpected errors

Returns:

  • (nil)

    For void callbacks

  • (Integer)

    For path callbacks, either 0 for success or a negative errno value



63
64
65
66
67
68
69
70
71
# File 'lib/ffi/libfuse/adapter/safe.rb', line 63

def safe_callback(fuse_method, *args, default_errno: Errno::ENOTRECOVERABLE::Errno)
  if FuseOperations::MEANINGFUL_RETURN.include?(fuse_method)
    safe_meaningful_integer_callback(fuse_method, *args, default_errno: default_errno)
  elsif FuseOperations::VOID_RETURN.include?(fuse_method)
    safe_void_callback(fuse_method, *args)
  else
    safe_integer_callback(fuse_method, *args, default_errno: default_errno)
  end
end

Instance Method Details

#default_errnoInteger

Returns the default errno to return for rescued errors. ENOTRECOVERABLE unless overridden.

Returns:

  • (Integer)

    the default errno to return for rescued errors. ENOTRECOVERABLE unless overridden



30
31
32
# File 'lib/ffi/libfuse/adapter/safe.rb', line 30

def default_errno
  defined?(super) ? super : Errno::ENOTRECOVERABLE::Errno
end