Module: FFI::Libfuse::Filesystem::Ruby::VirtualNode

Included in:
VirtualFile, VirtualLink, VirtualNode
Defined in:
lib/ffi/libfuse/filesystem/virtual_node.rb

Overview

Common FUSE Callbacks for a virtual inode representing a single filesystem object at '/'

Note this module is used by both VirtualFile which is under Adapter::Ruby::Prepend and VirtualDir which passes on native FFI::Libfuse::FuseOperations calls

Instance Attribute Summary collapse

FUSE Callbacks collapse

Instance Method Summary collapse

Instance Attribute Details

#accountingAccounting|nil (readonly)

Returns file system statistcs accumulator.

Returns:

  • (Accounting|nil)

    file system statistcs accumulator



22
23
24
# File 'lib/ffi/libfuse/filesystem/virtual_node.rb', line 22

def accounting
  @accounting
end

#virtual_statHash<Symbol,Integer> (readonly)

Returns base file or directory stat information used for :getattr of this node.

Returns:

  • (Hash<Symbol,Integer>)

    base file or directory stat information used for :getattr of this node



16
17
18
# File 'lib/ffi/libfuse/filesystem/virtual_node.rb', line 16

def virtual_stat
  @virtual_stat
end

#virtual_xattrHash<String,String> (readonly)

Returns virtual extended attributes.

Returns:

  • (Hash<String,String>)

    virtual extended attributes



19
20
21
# File 'lib/ffi/libfuse/filesystem/virtual_node.rb', line 19

def virtual_xattr
  @virtual_xattr
end

Instance Method Details

#chmod(path, mode, *args) ⇒ Object



48
49
50
51
52
53
# File 'lib/ffi/libfuse/filesystem/virtual_node.rb', line 48

def chmod(path, mode, *args)
  return path_method(__method__, path, mode, *args) unless root?(path)

  virtual_stat[:mode] = mode
  virtual_stat[:ctime] = Time.now
end

#chown(path, uid, gid, *args) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/ffi/libfuse/filesystem/virtual_node.rb', line 55

def chown(path, uid, gid, *args)
  return path_method(__method__, path, uid, gid, *args) unless root?(path)

  virtual_stat[:uid] = uid
  virtual_stat[:gid] = gid
  virtual_stat[:ctime] = Time.now
end

#getxattr(path, name, buf = nil, size = nil) ⇒ Object



70
71
72
73
74
75
# File 'lib/ffi/libfuse/filesystem/virtual_node.rb', line 70

def getxattr(path, name, buf = nil, size = nil)
  return path_method(__method__, path, name, buf, size) unless root?(path)
  return virtual_xattr[name] unless buf

  Adapter::Ruby.getxattr(buf, size) { virtual_xattr[name] }
end

#init_node(mode, ctx: FuseContext.get, now: Time.now) ⇒ Object

Initialise the stat information for the node - should only be called once (eg from create or mkdir)



87
88
89
90
91
92
93
94
95
96
# File 'lib/ffi/libfuse/filesystem/virtual_node.rb', line 87

def init_node(mode, ctx: FuseContext.get, now: Time.now)
  @virtual_stat =
    {
      mode: mode & ~ctx.umask, uid: ctx.uid, gid: ctx.gid,
      ctime: now, mtime: now, atime: now,
      ino: object_id
    }
  accounting&.adjust(0, +1)
  self
end

#initialize(accounting: Accounting.new) ⇒ Object

Parameters:

  • accounting (Accounting) (defaults to: Accounting.new)

    accumulator of filesystem statistics



25
26
27
28
29
# File 'lib/ffi/libfuse/filesystem/virtual_node.rb', line 25

def initialize(accounting: Accounting.new)
  @accounting = accounting

  @virtual_xattr = {}
end

#listxattr(path, buf = nil, size = nil) ⇒ Object



77
78
79
80
81
82
# File 'lib/ffi/libfuse/filesystem/virtual_node.rb', line 77

def listxattr(path, buf = nil, size = nil)
  return path_method(__method__, path) unless root?(path)
  return virtual_xattr.keys unless buf

  Adapter::Ruby.listxattr(buf, size) { virtual_xattr.keys }
end

#statfs(path, statfs_buf) ⇒ Object

Raises:

  • (Errno::ENOTSUP)


63
64
65
66
67
68
# File 'lib/ffi/libfuse/filesystem/virtual_node.rb', line 63

def statfs(path, statfs_buf)
  return path_method(__method__, path, statfs_buf) unless root?(path)
  raise Errno::ENOTSUP unless accounting

  accounting.to_statvfs(statfs_buf)
end

#utimens(path, *args) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/ffi/libfuse/filesystem/virtual_node.rb', line 37

def utimens(path, *args)
  return path_method(__method__, path, *args) unless root?(path)

  atime, mtime, *_fuse3 = args
  # if native fuse call atime will be Array<Stat::TimeSpec>
  atime, mtime = Stat::TimeSpec.fill_times(atime[0, 2], 2).map(&:time) if atime.is_a?(Array)
  virtual_stat[:atime] = atime if atime
  virtual_stat[:mtime] = mtime if mtime
  virtual_stat[:ctime] = mtime if mtime
end