def mount(self, options=None): ctx = mnt.Context() ctx.source = self.dev ctx.target = self.mntpoint if options is not None: ctx.options = options ctx.mount()
def get_repo_name_from_squash(repo_squash_path): """ Get the name of the repo at the given repo_squash_path. To obtain the name, the squash file is mounted to a temporary directory. """ repo_name = None # Mount squash file to temp directory in separate mount namespace with TemporaryDirectory() as temp, namespace(mount=True): try: source = str(repo_squash_path) target = str(temp) fstype = 'squashfs' options = 'ro,loop' cxt = libmount.Context(source=source, target=target, fstype=fstype, options=options) cxt.mount() repo_name = get_repo_name_from_dir(target) except Exception as e: raise CatalystError(f"Couldn't mount: {source}, {e}") from e return repo_name
def test_umount(ts, argv): idx = 1 rc = 0 if len(argv) < 2: return -errno.EINVAL cxt = mnt.Context() if argv[idx] == "-t": cxt.options = argv[idx + 1] idx += 2 if argv[idx] == "-f": cxt.enable_force(True) if argv[idx] == "-l": cxt.enable_lazy(True) idx += 1 elif argv[idx] == "-r": cxt.enable_rdonly_umount(True) idx += 1 if len(argv) == idx + 1: cxt.target = argv[idx] idx += 1 else: return -errno.EINVAL try: cxt.umount() except Exception: print("failed to umount") return 1 print("successfully umounted") return rc
def test_mount(ts, argv): idx = 1 rc = 0 if len(argv) < 2: return -errno.EINVAL cxt = mnt.Context() if argv[idx] == "-o": cxt.options = argv[idx + 1] idx += 2 if argv[idx] == "-t": cxt.fstype = argv[idx + 1] idx += 2 if len(argv) == idx + 1: cxt.target = argv[idx] idx += 1 elif (len(argv) == idx + 2): cxt.source = argv[idx] idx += 1 cxt.target = argv[idx] idx += 1 try: cxt.mount() except Exception: print("failed to mount") return -1 print("successfully mounted") return rc
def test_mountall(ts, argv): mntrc = 1 ignored = 1 idx = 1 cxt = mnt.Context() if len(argv) > 2: if argv[idx] == "-O": cxt.options_pattern = argv[idx + 1] idx += 2 if argv[idx] == "-t": cxt.fstype_pattern = argv[idx + 1] idx += 2 i = () while (cxt.next_mount()): tgt = i.target if (ignored == 1): print("{:s}: ignored: not match".format(tgt)) elif (ignored == 2): print("{:s}: ignored: already mounted".format(tgt)) elif (not cxt.status): if (mntrc > 0): # ?? errno = mntrc print("{:s}: mount failed".format(tgt)) else: print("{:s}: mount failed".format(tgt)) else: print("{:s}: successfully mounted".format(tgt)) return 0
def test_flags(ts, argv): idx = 1 rc = 0 opt = "" flags = 0 cxt = mnt.Context() if argv[idx] == "-o": cxt.options = argv[idx + 1] idx += 2 if len(argv) == idx + 1: cxt.target = argv[idx] idx += 1 try: cxt.prepare_mount() # catch ioerror here except IOError as e: print("failed to prepare mount {:s}".format(e.strerror)) opt = cxt.fs.options if (opt): print("options: {:s}", opt) print("flags: {08:lx}".format(cxt.mflags())) return rc
def ismount(path): """Like os.path.ismount, but also support bind mounts""" path = Path(path) if path.is_mount(): return True cxt = libmount.Context() while (fs := cxt.mtab.next_fs()) is not None: if path == Path(fs.target): return True
def _unmount(self, dir): ctx = mnt.Context() ctx.target = dir try: ctx.umount() except Exception as err: writemsg_level("Failed to unmount %s: %r\n" % (dir, err), level=logging.ERROR, noiselevel=-1) return return True
def mount_disk(dobj,target): if dobj["mounted"]: return False ctx = mnt.Context() ctx.target = target ctx.source = dobj["device"] try: ctx.mount() except Exception as e: print(e) return False return True
def _mount(self, source, target): ctx = mnt.Context() ctx.source = source ctx.target = target ctx.options = self.mount_options ctx.fstype = "squashfs" try: ctx.mount() except Exception as err: writemsg_level("Failed to mount %s: %r\n" % (source, err), level=logging.ERROR, noiselevel=-1) return return True
def umount(self): ctx = mnt.Context() ctx.target = self.mntpoint ctx.umount()
def umount(target: Path): '''Unmount target''' ctx = libmount.Context(target=str(target)) ctx.umount() if ctx.status < 0: raise MountError(f'umount failed with status {ctx.status}')
def mount(source: Path, target: Path): '''Mount source to target''' ctx = libmount.Context(source=str(source), target=str(target)) ctx.mount() if ctx.status < 0: raise MountError(f'mount failed with status {ctx.status}')