def get_mounted_disks(): tb = mnt.Table("/proc/self/mountinfo") out = [] for fs in iter(ft.partial(tb.next_fs),None): if "/dev/s" in fs.source: out.append(fs) return out
def helper_mount(options, tmpfs=True): conf = base_config() conf['process']['args'] = ['/init', 'cat', '/proc/self/mountinfo'] add_all_namespaces(conf) if tmpfs: mount_opt = { "destination": "/var/dir", "type": "tmpfs", "source": "tmpfs", "options": [options] } else: mount_opt = { "destination": "/var/dir", "type": "bind", "source": get_tests_root(), "options": ["bind", "rprivate"] + [options] } conf['mounts'].append(mount_opt) out, _ = run_and_get_output(conf, hide_stderr=True) with tempfile.NamedTemporaryFile(mode='w', delete=True) as f: f.write(out) f.flush() t = libmount.Table(f.name) m = t.find_target('/var/dir') return [m.vfs_options, m.fs_options] return -1
def _cache_check(self): """ Computes the MD5 hash on /proc/self/mountinfo and updates the cache on change """ md5hash = util.md5_file(MOUNT_FILE) if md5hash != self.mounts_hash: self.mounts_hash = md5hash self.mountpoints = libmount.Table(MOUNT_FILE)
def test_find_mountpoint(ts, argv): rc = -1 tb = mnt.Table("/proc/self/mountinfo") if not tb: return rc fs = tb.find_mountpoint(argv[1], mnt.MNT_ITER_BACKWARD) if not fs: return rc fs.print_debug(sys.stdout) return 0
def prep_mounts(self): # What filesystems hold the packages we're gonna use? mountinfo = libmount.Table('/proc/self/mountinfo') pkg_dirs = set(dirname(p) for p in self.cli.state.read_packagelist()) pkg_mounts = set(mountinfo.find_mountpoint(path) for path in pkg_dirs) # Write mount units for everything the upgrade will need. # (it's OK if they're redundant - systemd will sort it out.) ensure_dir(MOUNT_UNIT_DIR) for mnt in pkg_mounts: write_mount_unit(mnt)
def create_table(f, comments): if not f: return None tb = mnt.Table() tb.enable_comments(comments) tb.errcb = parser_errcb try: tb.parse_file(f) except Exception: print "{:s}: parsing failed".format(f) return None return tb
def test_replace(ts, argv): fs = mnt.Fs() tb = mnt.Table() if (len(argv) < 3): return -1 tb.enable_comments(True) tb.parse_fstab() fs.source = argv[1] fs.target = argv[2] #TODO: resolve None + string fs.comment = "# this is new filesystem\n" tb.add_fs(fs) tb.replace_file(os.environ["LIBMOUNT_FSTAB"]) return 0
def valid_datadir(datadir): '''Check the location of --datadir to make sure it's usable for upgrades.''' def err(msg): raise argparse.ArgumentTypeError(" ".join((datadir, msg))) fs = libmount.Table('/proc/self/mountinfo').find_mountpoint(datadir) if fs.is_netfs(): err(_("is on a network filesystem")) if fs.is_pseudofs(): err(_("is on a temporary filesystem")) if datadir == DEFAULT_DATADIR: return datadir if not os.path.exists(datadir): err(_("does not exist")) if not os.path.isdir(datadir): err(_("is not a directory")) if os.listdir(datadir): err(_("is not empty")) # looks good! return datadir
def test_getMountpoint(self): mtab = libmount.Table().parse_mtab() rootfs = mtab.find_target('/') self.assertEqual(str(mounts.getMountpoint(rootfs.source)), '/')