예제 #1
0
def unmount(target, mnt_flags=()):
    """Umount ``target``.
    """
    target = target.encode()

    mnt_flags = utils.get_iterable(mnt_flags)
    mnt_flags = six.moves.reduce(operator.or_, mnt_flags, 0)

    _LOGGER.debug('umount(%r, %r)', target,
                  utils.parse_mask(mnt_flags, MNTFlags))

    if not mnt_flags:
        return _umount(target)

    else:
        return _umount2(target, mnt_flags)
예제 #2
0
def mount(source,
          target,
          fs_type,
          *mnt_opts_args,
          mnt_flags=(),
          **mnt_opts_kwargs):
    """Mount ``source`` on ``target`` using filesystem type ``fs_type`` and
    mount flags ``mnt_flags``.

    NOTE: Mount data argument is not supported.

    :params `str` source:
        What to mount
    :params `str` target:
        Where to mount it
    """
    if source is not None:
        source = source.encode()
    if target is not None:
        target = target.encode()
    else:
        target = source
    if fs_type is not None:
        fs_type = fs_type.encode()

    # Fix up mount flags
    mnt_flags = utils.get_iterable(mnt_flags)
    flags = int(six.moves.reduce(operator.or_, mnt_flags, MS_MGC_VAL))
    # Fix up mount options
    options = ','.join(
        itertools.chain(mnt_opts_args,
                        ('%s=%s' % (key, value)
                         for (key, value) in six.iteritems(mnt_opts_kwargs))))
    if options:
        options = options.encode()
    else:
        options = None

    _LOGGER.debug('mount(%r, %r, %r, %r, %r)', source, target, fs_type,
                  utils.parse_mask(flags, MSFlags), options)

    return _mount(source, target, fs_type, flags, options)