Class: Mountfd::DetachedMount
- Inherits:
-
Object
- Object
- Mountfd::DetachedMount
- Defined in:
- lib/mountfd/core.rb,
sig/mountfd.rbs
Instance Method Summary collapse
- #attach(path, beneath: false) ⇒ AttachedMount
- #close ⇒ nil
- #closed? ⇒ Boolean
- #discard ⇒ nil
- #fileno ⇒ Integer
- #idmap!(userns) ⇒ DetachedMount
-
#initialize(handle) ⇒ DetachedMount
constructor
A new instance of DetachedMount.
- #set_attributes(set: [], clr: [], propagation: nil, idmap: nil, recursive: false) ⇒ DetachedMount
Constructor Details
#initialize(handle) ⇒ DetachedMount
Returns a new instance of DetachedMount.
118 119 120 121 |
# File 'lib/mountfd/core.rb', line 118 def initialize(handle) @handle = handle Mountfd.__send__(:track, self) end |
Instance Method Details
#attach(path, beneath: false) ⇒ AttachedMount
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/mountfd/core.rb', line 150 def attach(path, beneath: false) target = File.path(path) flags = Native::MOVE_MOUNT_F_EMPTY_PATH flags |= Native::MOVE_MOUNT_BENEATH if beneath begin Native.move_mount(@handle, "", AT_FDCWD, target, flags) rescue SystemCallError => error raise MountError, "move_mount: #{error.}", cause: error end close AttachedMount.new(target) end |
#close ⇒ nil
163 164 165 166 167 168 |
# File 'lib/mountfd/core.rb', line 163 def close @handle.close nil ensure Mountfd.__send__(:untrack, self) if @handle.closed? end |
#closed? ⇒ Boolean
124 |
# File 'lib/mountfd/core.rb', line 124 def closed? = @handle.closed? |
#discard ⇒ nil
125 |
# File 'lib/mountfd/core.rb', line 125 def discard = close |
#fileno ⇒ Integer
123 |
# File 'lib/mountfd/core.rb', line 123 def fileno = @handle.fileno |
#idmap!(userns) ⇒ DetachedMount
148 |
# File 'lib/mountfd/core.rb', line 148 def idmap!(userns) = set_attributes(set: [:idmap], idmap: userns) |
#set_attributes(set: [], clr: [], propagation: nil, idmap: nil, recursive: false) ⇒ DetachedMount
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/mountfd/core.rb', line 127 def set_attributes(set: [], clr: [], propagation: nil, idmap: nil, recursive: false) flags = Native::AT_EMPTY_PATH flags |= Native::AT_RECURSIVE if recursive set_flags = Attributes.flags(set) clear_flags = Attributes.flags(clr) has_idmap = (set_flags & Native::MOUNT_ATTR_IDMAP).positive? raise ArgumentError, "an idmapped mount cannot be cleared" if (clear_flags & Native::MOUNT_ATTR_IDMAP).positive? raise ArgumentError, "MOUNT_ATTR_IDMAP and a user namespace must be provided together" if has_idmap == idmap.nil? Native.mount_setattr( @handle, "", flags, set_flags, clear_flags, Attributes.propagation(propagation), idmap && Mountfd.fileno(idmap) ) self rescue SystemCallError => error exception = idmap ? IdmapError : MountError raise exception, "mount_setattr: #{error.}", cause: error end |