Module: HrrRbMount
- Includes:
- Constants
- Defined in:
- lib/hrr_rb_mount.rb,
lib/hrr_rb_mount/version.rb,
ext/hrr_rb_mount/hrr_rb_mount.c
Overview
A wrapper around mount and umount. See mount(2) and umount(2) for details.
Defined Under Namespace
Modules: Constants
Constant Summary collapse
- PROC_MOUNTINFO_PATH =
The path to /proc/self/mountinfo.
"/proc/self/mountinfo"- VERSION =
"0.3.0"
Constants included from Constants
Constants::BIND, Constants::DETACH, Constants::DIRSYNC, Constants::EXPIRE, Constants::FORCE, Constants::LAZYTIME, Constants::MANDLOCK, Constants::MOVE, Constants::NOATIME, Constants::NODEV, Constants::NODIRATIME, Constants::NOEXEC, Constants::NOFOLLOW, Constants::NOSUID, Constants::PRIVATE, Constants::RDONLY, Constants::REC, Constants::RELATIME, Constants::REMOUNT, Constants::SHARED, Constants::SILENT, Constants::SLAVE, Constants::STRICTATIME, Constants::SYNCHRONOUS, Constants::UNBINDABLE
Class Method Summary collapse
-
.bind(source, target, mountflags = 0, data = "") ⇒ Integer
A wrapper around mount –bind source target command.
-
.make_private(mountpoint) ⇒ Integer
A wrapper around mount –make-private mountpoint command.
-
.make_rprivate(mountpoint) ⇒ Integer
A wrapper around mount –make-rprivate mountpoint command.
-
.make_rshared(mountpoint) ⇒ Integer
A wrapper around mount –make-rshared mountpoint command.
-
.make_rslave(mountpoint) ⇒ Integer
A wrapper around mount –make-rslave mountpoint command.
-
.make_runbindable(mountpoint) ⇒ Integer
A wrapper around mount –make-runbindable mountpoint command.
-
.make_shared(mountpoint) ⇒ Integer
A wrapper around mount –make-shared mountpoint command.
-
.make_slave(mountpoint) ⇒ Integer
A wrapper around mount –make-slave mountpoint command.
-
.make_unbindable(mountpoint) ⇒ Integer
A wrapper around mount –make-unbindable mountpoint command.
-
.mount(source, target, filesystemtype, mountflags = 0, data = "") ⇒ Integer
A wrapper around mount system call.
-
.mountpoint?(target, follow_symlinks: true) ⇒ Boolean
Returns true if the target directory or file is a mountpoint.
-
.move(source, target, mountflags = 0, data = "") ⇒ Integer
A wrapper around mount –move source target command.
-
.rbind(source, target, mountflags = 0, data = "") ⇒ Integer
A wrapper around mount –rbind source target command.
-
.remount(mountpoint, mountflags = 0, data = "") ⇒ Integer
A wrapper around mount –remount mountpoint command.
-
.umount(target, flags = 0) ⇒ Integer
A wrapper around umount system call.
Class Method Details
.bind(source, target, mountflags = 0, data = "") ⇒ Integer
A wrapper around mount –bind source target command.
63 64 65 |
# File 'lib/hrr_rb_mount.rb', line 63 def self.bind source, target, mountflags=0, data="" mount source, target, nil, BIND | mountflags, data end |
.make_private(mountpoint) ⇒ Integer
A wrapper around mount –make-private mountpoint command.
114 115 116 |
# File 'lib/hrr_rb_mount.rb', line 114 def self.make_private mountpoint mount "none", mountpoint, nil, PRIVATE end |
.make_rprivate(mountpoint) ⇒ Integer
A wrapper around mount –make-rprivate mountpoint command.
162 163 164 |
# File 'lib/hrr_rb_mount.rb', line 162 def self.make_rprivate mountpoint mount "none", mountpoint, nil, REC | PRIVATE end |
.make_rshared(mountpoint) ⇒ Integer
A wrapper around mount –make-rshared mountpoint command.
138 139 140 |
# File 'lib/hrr_rb_mount.rb', line 138 def self.make_rshared mountpoint mount "none", mountpoint, nil, REC | SHARED end |
.make_rslave(mountpoint) ⇒ Integer
A wrapper around mount –make-rslave mountpoint command.
150 151 152 |
# File 'lib/hrr_rb_mount.rb', line 150 def self.make_rslave mountpoint mount "none", mountpoint, nil, REC | SLAVE end |
.make_runbindable(mountpoint) ⇒ Integer
A wrapper around mount –make-runbindable mountpoint command.
174 175 176 |
# File 'lib/hrr_rb_mount.rb', line 174 def self.make_runbindable mountpoint mount "none", mountpoint, nil, REC | UNBINDABLE end |
.make_shared(mountpoint) ⇒ Integer
A wrapper around mount –make-shared mountpoint command.
90 91 92 |
# File 'lib/hrr_rb_mount.rb', line 90 def self.make_shared mountpoint mount "none", mountpoint, nil, SHARED end |
.make_slave(mountpoint) ⇒ Integer
A wrapper around mount –make-slave mountpoint command.
102 103 104 |
# File 'lib/hrr_rb_mount.rb', line 102 def self.make_slave mountpoint mount "none", mountpoint, nil, SLAVE end |
.make_unbindable(mountpoint) ⇒ Integer
A wrapper around mount –make-unbindable mountpoint command.
126 127 128 |
# File 'lib/hrr_rb_mount.rb', line 126 def self.make_unbindable mountpoint mount "none", mountpoint, nil, UNBINDABLE end |
.mount(source, target, filesystemtype, mountflags = 0, data = "") ⇒ Integer
A wrapper around mount system call.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'ext/hrr_rb_mount/hrr_rb_mount.c', line 22
VALUE
hrr_rb_mount_mount(int argc, VALUE *argv, VALUE self)
{
const char *source, *target, *filesystemtype, *data;
unsigned long mountflags;
rb_check_arity(argc, 3, 5);
source = StringValueCStr(argv[0]);
target = StringValueCStr(argv[1]);
filesystemtype = NIL_P(argv[2]) ? NULL : StringValueCStr(argv[2]);
mountflags = argc < 4 ? 0 : NUM2ULONG(argv[3]);
data = argc < 5 ? NULL : StringValueCStr(argv[4]);
if (mount(source, target, filesystemtype, mountflags, data) < 0)
rb_sys_fail("mount");
return INT2FIX(0);
}
|
.mountpoint?(target, follow_symlinks: true) ⇒ Boolean
Returns true if the target directory or file is a mountpoint. Otherwise, returns false.
Internally, uses /proc/self/mountinfo file to detect if the target is a mountpoint.
When the file is not available, then uses stat(2). In this case, bind mount is not able to be detected.
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/hrr_rb_mount.rb', line 193 def self.mountpoint? target, follow_symlinks: true return false if (! follow_symlinks) && File.symlink?(target) begin if File.exist? PROC_MOUNTINFO_PATH tgt_abs_path = File.realpath(target) File.foreach(PROC_MOUNTINFO_PATH){ |line| break true if line.split(" ")[4] == tgt_abs_path } or false else parent = File.join(target, "..") st, pst = File.stat(target), File.stat(parent) st.dev != pst.dev || st.ino == pst.ino end rescue Errno::ENOENT, Errno::ENOTDIR false end end |
.move(source, target, mountflags = 0, data = "") ⇒ Integer
A wrapper around mount –move source target command.
48 49 50 |
# File 'lib/hrr_rb_mount.rb', line 48 def self.move source, target, mountflags=0, data="" mount source, target, nil, MOVE | mountflags, data end |
.rbind(source, target, mountflags = 0, data = "") ⇒ Integer
A wrapper around mount –rbind source target command.
78 79 80 |
# File 'lib/hrr_rb_mount.rb', line 78 def self.rbind source, target, mountflags=0, data="" mount source, target, nil, BIND | REC | mountflags, data end |
.remount(mountpoint, mountflags = 0, data = "") ⇒ Integer
A wrapper around mount –remount mountpoint command.
33 34 35 |
# File 'lib/hrr_rb_mount.rb', line 33 def self.remount mountpoint, mountflags=0, data="" mount "none", mountpoint, nil, REMOUNT | mountflags, data end |
.umount(target, flags = 0) ⇒ Integer
A wrapper around umount system call.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'ext/hrr_rb_mount/hrr_rb_mount.c', line 54
VALUE
hrr_rb_mount_umount(int argc, VALUE *argv, VALUE self)
{
const char *target;
int flags;
rb_check_arity(argc, 1, 2);
target = StringValueCStr(argv[0]);
flags = argc < 2 ? 0 : NUM2INT(argv[1]);
if (umount2(target, flags) < 0)
rb_sys_fail("umount");
return INT2FIX(0);
}
|