Class: RFuse::Fuse

Inherits:
Object
  • Object
show all
Defined in:
lib/rfuse.rb

Direct Known Subclasses

FuseDelegator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mountpoint, *argv) ⇒ Fuse

Returns a new instance of Fuse.



258
259
260
261
# File 'lib/rfuse.rb', line 258

def initialize(mountpoint, *argv)
  @mountpoint = mountpoint
  @fuse = FFI::Libfuse::Main.fuse_create(mountpoint, *argv, operations: self, private_data: self)
end

Instance Attribute Details

#mountpointObject (readonly) Also known as: mountname

Returns the value of attribute mountpoint.



255
256
257
# File 'lib/rfuse.rb', line 255

def mountpoint
  @mountpoint
end

Instance Method Details

#exitObject Also known as: unmount

Stop processing



289
290
291
# File 'lib/rfuse.rb', line 289

def exit
  @fuse&.exit&.join
end

#loopObject



284
285
286
# File 'lib/rfuse.rb', line 284

def loop
  run([] ,single_thread: true, foreground: true)
end

#mounted?Boolean

Is the filesystem successfully mounted

@return [Boolean] true if mounted, false otherwise

Returns:

  • (Boolean)


266
267
268
# File 'lib/rfuse.rb', line 266

def mounted?
  @fuse && @fuse.mounted?
end

#run(signals = Signal.list.keys, **run_args) ⇒ void

This method returns an undefined value.

Convenience method to run a mounted filesystem to completion.

Parameters:

  • signals (Array<String|Integer>) (defaults to: Signal.list.keys)

    list of signals to handle. Default is all available signals. See #trap_signals

Raises:

See Also:

Since:

  • 1.1.0



278
279
280
281
282
# File 'lib/rfuse.rb', line 278

def run(signals = Signal.list.keys, **run_args)
  raise Error, 'not mounted' unless @fuse
  trap_signals(*signals)
  @fuse.run(traps: @traps, **run_args)
end

#trap_signals(*signames) ⇒ Array<String>

Set traps

The filesystem supports a signal by providing a sig<name> method. eg #sigint

The fuse #loop is notified of the signal via the self-pipe trick, and calls the corresponding sig<name> method, after any current filesystem operation completes.

This method will not override traps that have previously been set to something other than "DEFAULT"

Note: RFuse::Fuse itself provides #sigterm and #sigint.

Examples:

class MyFS < Fuse
   def sighup()
       # do something on HUP signal
   end
end

fuse = MyFS.new(*args)

if fuse.mounted?
    # Below will result in (effectively) Signal.trap("HUP") { fuse.sighup() }
    fuse.trap_signals("HUP","USR1") # ==> ["HUP"]
    fuse.loop()
end

Parameters:

  • signames (Array<String>)

    List of signal names to set traps for, if the filesystem has methods to handle them. Use Signal.list.keys to try all available signals.

Returns:

  • (Array<String>)

    List of signal names that traps have been set for.

Since:

  • 1.1.0



328
329
330
331
332
333
334
335
# File 'lib/rfuse.rb', line 328

def trap_signals(*signames)
  signames = signames.map { |n| n.to_s.upcase }.map { |n| n.start_with?('SIG') ? n[3..-1] : n }
  signames.keep_if { |n| Signal.list[n] && respond_sigmethod?(sigmethod(n)) }

  @traps ||= {}
  @traps.merge!(signames.map { |n| [ n, ->() { call_sigmethod(sigmethod(n)) }]}.to_h)
  @traps.keys
end