Class: Mountfd::FsContext
- Inherits:
-
Object
- Object
- Mountfd::FsContext
- Defined in:
- lib/mountfd/core.rb,
sig/mountfd.rbs
Instance Attribute Summary collapse
-
#diagnostics ⇒ Array[Diagnostic]
readonly
Returns the value of attribute diagnostics.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ nil
- #closed? ⇒ Boolean
- #create!(exclusive: false) ⇒ FsContext
- #fileno ⇒ Integer
-
#initialize(filesystem, flags: 0, handle: nil) ⇒ FsContext
constructor
A new instance of FsContext.
- #mount(attrs: {}) ⇒ DetachedMount
- #reconfigure! ⇒ FsContext
- #set(key, value = nil) ⇒ FsContext
- #set_binary(key, bytes) ⇒ FsContext
- #set_fd(key, io) ⇒ FsContext
- #set_flag(key) ⇒ FsContext
- #set_path(key, path, dfd: AT_FDCWD) ⇒ FsContext
- #warnings ⇒ Array[Diagnostic]
Constructor Details
#initialize(filesystem, flags: 0, handle: nil) ⇒ FsContext
Returns a new instance of FsContext.
40 41 42 43 |
# File 'lib/mountfd/core.rb', line 40 def initialize(filesystem, flags: 0, handle: nil) @handle = handle || Native.fsopen(filesystem.to_s, flags | Native::FSOPEN_CLOEXEC) @diagnostics = [] end |
Instance Attribute Details
#diagnostics ⇒ Array[Diagnostic] (readonly)
Returns the value of attribute diagnostics.
23 24 25 |
# File 'lib/mountfd/core.rb', line 23 def diagnostics @diagnostics end |
Class Method Details
.open ⇒ void .open(filesystem, flags:) ⇒ FsContext
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mountfd/core.rb', line 25 def self.open(filesystem, flags: 0) context = new(filesystem, flags: flags) return context unless block_given? begin yield context ensure context.close unless context.closed? end end |
Instance Method Details
#close ⇒ nil
85 |
# File 'lib/mountfd/core.rb', line 85 def close = @handle.close |
#closed? ⇒ Boolean
46 |
# File 'lib/mountfd/core.rb', line 46 def closed? = @handle.closed? |
#create!(exclusive: false) ⇒ FsContext
63 64 65 66 67 68 69 70 |
# File 'lib/mountfd/core.rb', line 63 def create!(exclusive: false) if exclusive && !Mountfd.features.include?(:create_excl) raise UnsupportedError, "exclusive fsconfig creation requires Linux 6.6 or newer" end command = exclusive ? Native::FSCONFIG_CMD_CREATE_EXCL : Native::FSCONFIG_CMD_CREATE configure(command, nil, nil, 0) end |
#fileno ⇒ Integer
45 |
# File 'lib/mountfd/core.rb', line 45 def fileno = @handle.fileno |
#mount(attrs: {}) ⇒ DetachedMount
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/mountfd/core.rb', line 74 def mount(attrs: {}) attr_set, attr_clr = Attributes.build(attrs) raise ArgumentError, "idmap must be applied to a detached mount with a user namespace" if ((attr_set | attr_clr) & Native::MOUNT_ATTR_IDMAP).positive? handle = with_diagnostics("fsmount", MountError) do Native.fsmount(@handle, Native::FSMOUNT_CLOEXEC, attr_set) end DetachedMount.new(handle) end |
#reconfigure! ⇒ FsContext
72 |
# File 'lib/mountfd/core.rb', line 72 def reconfigure! = configure(Native::FSCONFIG_CMD_RECONFIGURE, nil, nil, 0) |
#set(key, value = nil) ⇒ FsContext
49 50 51 52 53 |
# File 'lib/mountfd/core.rb', line 49 def set(key, value = nil) return set_flag(key) if value.nil? || value == true configure(Native::FSCONFIG_SET_STRING, key, value.to_s, 0) end |
#set_binary(key, bytes) ⇒ FsContext
58 59 60 61 |
# File 'lib/mountfd/core.rb', line 58 def set_binary(key, bytes) value = String(bytes) configure(Native::FSCONFIG_SET_BINARY, key, value, value.bytesize) end |
#set_fd(key, io) ⇒ FsContext
57 |
# File 'lib/mountfd/core.rb', line 57 def set_fd(key, io) = configure(Native::FSCONFIG_SET_FD, key, nil, Mountfd.fileno(io)) |
#set_flag(key) ⇒ FsContext
55 |
# File 'lib/mountfd/core.rb', line 55 def set_flag(key) = configure(Native::FSCONFIG_SET_FLAG, key, nil, 0) |
#set_path(key, path, dfd: AT_FDCWD) ⇒ FsContext
56 |
# File 'lib/mountfd/core.rb', line 56 def set_path(key, path, dfd: AT_FDCWD) = configure(Native::FSCONFIG_SET_PATH, key, File.path(path), dfd) |
#warnings ⇒ Array[Diagnostic]
47 |
# File 'lib/mountfd/core.rb', line 47 def warnings = diagnostics.select { _1.level == :warning } |