Class: Mountfd::DetachedMount

Inherits:
Object
  • Object
show all
Defined in:
lib/mountfd/core.rb,
sig/mountfd.rbs

Instance Method Summary collapse

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

Parameters:

  • path (String)
  • beneath: (Boolean) (defaults to: false)

Returns:



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.message}", cause: error
  end
  close
  AttachedMount.new(target)
end

#closenil

Returns:

  • (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

Returns:

  • (Boolean)


124
# File 'lib/mountfd/core.rb', line 124

def closed? = @handle.closed?

#discardnil

Returns:

  • (nil)


125
# File 'lib/mountfd/core.rb', line 125

def discard = close

#filenoInteger

Returns:

  • (Integer)


123
# File 'lib/mountfd/core.rb', line 123

def fileno = @handle.fileno

#idmap!(userns) ⇒ DetachedMount

Parameters:

Returns:



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

Parameters:

  • set: (Integer, Array[Symbol]) (defaults to: [])
  • clr: (Integer, Array[Symbol]) (defaults to: [])
  • propagation: (Symbol, nil) (defaults to: nil)
  • idmap: (_Fileno, nil) (defaults to: nil)
  • recursive: (Boolean) (defaults to: false)

Returns:



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.message}", cause: error
end