Class: FFI::Libfuse::Filesystem::MappedDir

Inherits:
Object
  • Object
show all
Includes:
MappedFiles, Utils
Defined in:
lib/ffi/libfuse/filesystem/mapped_dir.rb

Overview

A read-only directory of MappedFiles

Subclasses must implement #entries and #map_path

Constant Summary

Constants included from MappedFiles

FFI::Libfuse::Filesystem::MappedFiles::HAS_XATTR

Instance Attribute Summary collapse

Attributes included from MappedFiles

#accounting

Fuse Callbacks collapse

Instance Method Summary collapse

Methods included from Utils

#directory?, #empty_dir?, #empty_file?, #exists?, #file?, #mkdir_p

Methods included from MappedFiles

#create, #getxattr, #listxattr, #open, #read, #read_buf, #stat_mask, #statfs, #truncate, #unlink, #utimens, #write, #write_buf

Constructor Details

#initialize(accounting: nil) ⇒ MappedDir

Returns a new instance of MappedDir.



20
21
22
23
# File 'lib/ffi/libfuse/filesystem/mapped_dir.rb', line 20

def initialize(accounting: nil)
  @accounting = accounting
  @root = VirtualNode.new(accounting: accounting)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, path = nil, *args, &block) ⇒ Object

Passes FUSE Callbacks on to the Top Level Namespace filesystem

Raises:

  • (Errno::ENOTSUP)


53
54
55
56
57
58
59
# File 'lib/ffi/libfuse/filesystem/mapped_dir.rb', line 53

def method_missing(method, path = nil, *args, &block)
  return @root.public_send(method, path, *args, &block) if @root.respond_to?(method) && root?(path)

  raise Errno::ENOTSUP if FuseOperations.path_callbacks.include?(method)

  super
end

Instance Attribute Details

#statObject

Returns the value of attribute stat.



14
15
16
# File 'lib/ffi/libfuse/filesystem/mapped_dir.rb', line 14

def stat
  @stat
end

Instance Method Details

#entriesEnumerable

This method is abstract.

Returns set of entries in this directory (excluding '.' and '..').

Returns:

  • (Enumerable)

    set of entries in this directory (excluding '.' and '..')



20
21
22
23
# File 'lib/ffi/libfuse/filesystem/mapped_dir.rb', line 20

def initialize(accounting: nil)
  @accounting = accounting
  @root = VirtualNode.new(accounting: accounting)
end

#getattr(path, stat = nil, _ffi = nil) ⇒ Object

For the root path provides this directory's stat information, otherwise passes on to the next filesystem



28
29
30
31
32
33
34
# File 'lib/ffi/libfuse/filesystem/mapped_dir.rb', line 28

def getattr(path, stat = nil, _ffi = nil)
  return super unless root?(path)

  stat&.directory(@root.virtual_stat.merge({ nlink: entries.size + 2 }))

  self
end

#map_path(path) ⇒ Object

subclass only call super for root path

Raises:

  • (ArgumentError)


66
67
68
69
70
# File 'lib/ffi/libfuse/filesystem/mapped_dir.rb', line 66

def map_path(path)
  raise ArgumentError, "map_path received non root path #{path}" unless root?(path)

  [path, @root]
end

#mkdir(path, mode, *_args) ⇒ Object

Raises:

  • (Errno::EROFS)


44
45
46
47
48
# File 'lib/ffi/libfuse/filesystem/mapped_dir.rb', line 44

def mkdir(path, mode, *_args)
  raise Errno::EROFS unless root?(path)

  @root.init_node(mode)
end

#readdir(path, *_args, &block) ⇒ Object

For root path enumerates #entries

Raises:

  • (Errno::ENOTDIR)

    unless root path



38
39
40
41
42
# File 'lib/ffi/libfuse/filesystem/mapped_dir.rb', line 38

def readdir(path, *_args, &block)
  raise Errno::ENOTDIR unless root?(path)

  %w[. ..].concat(entries).each(&block)
end

#respond_to_missing?(method, private = false) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/ffi/libfuse/filesystem/mapped_dir.rb', line 61

def respond_to_missing?(method, private = false)
  (FuseOperations.fuse_callbacks.include?(method) && @root.respond_to?(method, false)) || super
end