This is false positive warning, but lets silence it so that if and when
warnings crop up they are easy to notice and take seriously.
libmount/src/optstr.c:354:29: warning: potential null pointer dereference
[-Wnull-dereference]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* Added member 'struct libmnt_table *tab' to libmnt_fs structure.
* Added 'mnt_fs_get_table()'.
* Removed overhead from 'mnt_table_{insert,move,remove}_fs().
* Added check to 'mnt_table_set_iter()' that entry is member of table.
[kzak@redhat.com: - add to libmount.sys
- add to docs
- cleanup commit message
- set fs->tab = NULL before mnt_unref_fs() in mnt_table_remove_fs()]
Signed-off-by: Tim Hildering <hilderingt@posteo.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
Add some fuse filesystems to the list of pseudofs and netfs.
There are still tens of filesystems that should be evaluated and added.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Add functions to insert FS into table to specified position and to
move FS between two tables.
Co-Author: Tim Hildering <hilderingt@posteo.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
Added validation to function 'mnt_table_add_fs()' to check that added @fs
is not already a member of another table.
Signed-off-by: Karel Zak <kzak@redhat.com>
This patch add to support for remount-all operation to
libmount and mount(8).
For example:
mount --all -o remount,ro -t vfat
to remount read-only all VFAT filesystems.
Addresses: https://github.com/karelzak/util-linux/issues/589
Signed-off-by: Karel Zak <kzak@redhat.com>
The option user= is already handled by evaluate_permissions() and by
classic mount and umount usermount support. It seems we do not need
to duplicate support for user= in is_fuse_usermount().
The option user_id= is fuse specific and it's maintained by
libfuse/kernel in /proc/self/mountinfo. This is feature we need to
support in umount(8).
Addresses: https://github.com/karelzak/util-linux/pull/705
Signed-off-by: Karel Zak <kzak@redhat.com>
FUSE mounts don't need an fstab entry to be unmounted.
This checks if a mount is a FUSE mount before checking for
the fstab entry, and if so returns success.
[kzak@redhat.com: - use libmount tools for mount options
- use namespace switches
- cleanup code
The requirement is user=<username> or user_id=<uid> in /proc/self/mountinfo
for fuse filesystem. The logic is the same as for user= mount options, but in
this case it is not maintained by libmount in userspace, but by fuse FS in kernel.]
Co-Author: Karel Zak <kzak@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
* add SPDX-License-Identifier (see https://spdx.org/licenses/)
* add "This file part of libmount from util-linux project."
* use proper text for LGPL-2.1-or-later
* use the same texts everywhere
Signed-off-by: Karel Zak <kzak@redhat.com>
Let's use standardized names for licenses. The names used by SPDX
makes things more obvious at first glance. For complete list see:
https://spdx.org/licenses/
Note, this commit does not change any license or so...
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/python/pylibmount.c:158:19: warning: cast between incompatible function types
from ‘PyObject * (*)(PyObject *)’ {aka ‘struct _object * (*)(struct _object *)’}
to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *)’}
[-Wcast-function-type]
This is generic problem in all Python C code and gcc v8. The another
possible (and probably more correct) way is to add unused argument to
all API functions. Unfortunately, this solution is pretty invasive. The
question is if gcc is not too paranoid in this case.
For more details see https://bugs.python.org/issue33012. It seems
Python guys also prefer CFLAGS modification for now.
Signed-off-by: Karel Zak <kzak@redhat.com>
The source of a mount in /proc/self/mountinfo can unfortunately be an
empty string. Before this patch, 'mount' and 'mountpoint' fail as
following:
$ sudo mount -t tmpfs "" /tmp/bb
$ mount
mount: /proc/self/mountinfo: parse error at line 64 -- ignored
$ mountpoint /tmp/bb
/tmp/bb is not a mountpoint
This patch fixes the parsing. It is unfortunately more complex because
sscanf() does not handle fields with empty strings easily.
Other projects have their own parser for mountinfo and have similar
issues. I know of runc and runtime-tools (I'll send a patch for those
two) but there are probably others.
Signed-off-by: Alban Crequy <alban@kinvolk.io>
The previous commit 4ebea84bb1 replaced
all operations by strings, but it does not work for MS_MOVE as this
operation is not supported in fstab by libmount.
Signed-off-by: Karel Zak <kzak@redhat.com>
Specifying MS_MGC_VAL was required in kernel versions prior to 2.4,
but since Linux 2.4 is no longer required and is ignored if specified
The minimal kernel requirement for util-linux is Linux v2.6.
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount allows to split one library (mount(8)) call to multiple mount(2)
syscalls, for example
--rbind --make-rslave
in this case we have to be careful with MS_REC because the flag is
applied to multiple operations.
# strace -e mount mount --rbind --make-rslave /mnt/A /mnt/B
Old version:
mount("/mnt/A", "/mnt/B", 0x13ecac0, MS_MGC_VAL|MS_BIND, NULL) = 0
mount("none", "/mnt/B", NULL, MS_REC|MS_SLAVE, NULL) = 0
Fixed version:
mount("/mnt/A", "/mnt/B", 0x1f22ac0, MS_MGC_VAL|MS_BIND|MS_REC, NULL) = 0
mount("none", "/mnt/B", NULL, MS_REC|MS_SLAVE, NULL) = 0
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1584443
Signed-off-by: Karel Zak <kzak@redhat.com>
The current libmount MS_REMOUNT|MS_BIND support is restricted to
MS_RDONLY (read-only bind mount). This is too restrictive as Linux
kernel supports bind-remount for arbitrary VFS flags.
After this update you can use
# mount /dev/sdc1 /mnt/A
# mount --bind -onosuid,noexec /mnt/A /mnt/B
# findmnt /dev/sdc1 -oTARGET,SOURCE,FS-OPTIONS,VFS-OPTIONS
TARGET SOURCE FS-OPTIONS VFS-OPTIONS
/mnt/A /dev/sdc1 rw,stripe=512,data=ordered rw,relatime
/mnt/B /dev/sdc1 rw,stripe=512,data=ordered rw,nosuid,noexec,relatime
The "mount --bind" is composed from two syscalls of course (1st is
bind, 2nd is bind,remount,nosuid,noexec).
Addresses: https://github.com/karelzak/util-linux/issues/637
Signed-off-by: Karel Zak <kzak@redhat.com>
When you bind-mount a subdirectory of a local filesystem, the
path to that subdirectory appears as the fourth field in mountinfo.
For nfs mounts, the fourth field is always "/", and the subdirectory
part is appended to the "special" (aka "device") field. This is
consistent with historical NFS usage which always includes a path in
the fs_spec field.
libmount needs to know about this when "mount -a" checks to see if
a filesystem is already mounted.
Without this fix, fstab lines like:
server::/path /dir nfs defaults 0 0
/dir/subdir /mnt/test none bind 0 0
result in a new mount at /mnt/test every time "mount -a" is run.
[kzak@redhat.com: - use strappend() rather than asprintf()]
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
mnt_context_get_mtab() doesn't set its return **tb argument on error,
and so in mnt_context_next_umount() mtab will remain uninitialized on
error, later resulting in cxt->mtab containing garbage, possibly
resulting in segfault on exit.
Let's include sys/mount.h to be sure that our local libmount fallbacks
are not used by default to avoid possible conflicts with later included
sys/mount.h.
Addresses: https://github.com/systemd/systemd/pull/8452
Reported-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
The command "mount -a -t <pattern>" uses the -t as pattern to filter
fstab entries. And "mount -t <type>" is used to specify FS type.
Unfortunately libmount does not care about this difference when it
calls standard mount functionality. The original pattern is still in
the library control struct and mnt_do_mount() tries to use it as FS
type.
This patch is just bugfix. Maybe the long term solution would be to
differentiate between the pattern and type in the library API. Now the
library follows mount(8) command line and it's little bit messy.
Reported-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
We have already automakes's automatic dependencies like
bla.h.in -> bla.h -> foo.o -> bar.la
An explicit direct dependency bla.h.in -> bar.la
is redundant and useless anyways.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Headers should only be listed in either *_HEADERS or
*_SOURCES, especially when we want nodist_*_HEADERS.
Since all the generated headers are made by configure we
don't even need to use BUILT_SOURCES or other tricks.
Also see automake docs 9.4.1 Built Sources Example:
case "Build bindir.h from configure"
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Let's make it possible to use debug.h without environment variables.
Suggested-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
* introduce new flag __UL_DEBUG_FL_NOADDR to suppress pointer address printing
* use __UL_DEBUG_FL_NOADDR when SUID
* move ul_debugobj() to debugobj.h, and require UL_DEBUG_CURRENT_MASK
to provide access to the current mask from ul_debugobj(). It's better
than modify all ul_debugobj() calls and use the global mask as
argument.
* remove never used UL_DEBUG_DEFINE_FLAG
Reported-by: halfdog <me@halfdog.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
There is no difference between "bind" and "rbind" if we want to FS
root to search for the FS in mountinfo file.
fstab:
/dev/sdc1 /mnt/foo xfs defaults 0 0
/mnt/foo /mnt/test none rw,rbind 0 0
use -a more than once:
mount -a
mount -a
/proc/mounts (the current result):
/dev/sdc1 /mnt/foo xfs rw,relatime,attr2,inode64,noquota 0 0
/dev/sdc1 /mnt/test xfs rw,relatime,attr2,inode64,noquota 0 0
/dev/sdc1 /mnt/test xfs rw,relatime,attr2,inode64,noquota 0 0
/dev/sdc1 /mnt/foo xfs rw,relatime,attr2,inode64,noquota 0 0
expected (fixed version) result:
/dev/sdc1 /mnt/foo xfs rw,relatime,attr2,inode64,noquota 0 0
/dev/sdc1 /mnt/test xfs rw,relatime,attr2,inode64,noquota 0 0
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1528959
Signed-off-by: Karel Zak <kzak@redhat.com>
utimensat() is pretty expensive when mounting parallel filesystems from
the same source. It's possible to ignore all this if mtab is not
writable.
Note that this change is irrelevant for default util-linux builds
where all around mtab is already disabled since v2.30 (commit
89958178f6).
This change is relevant only for users who still use --enable-libmount-support-mtab.
Reported-by: Douglas Jacobsen <dmjacobsen@lbl.gov>
Signed-off-by: Karel Zak <kzak@redhat.com>
The commit c08396c769 replaces
open(O_CREATE) with ecaccess(). Unfortunately, another code depends on
the original behavior.
* let's make utab when really necessary rather than in the try_write() test
* __mnt_new_table_from_file() returns NULL if tab-file does not
exists. This is incorrect for tab_update.c stuff. We need empty table
in this case.
* we can check /run/mount/ directory for write access if
eaccess(filename) return ENOENT (because file does not exist)
Signed-off-by: Karel Zak <kzak@redhat.com>
MNT_FORCE and MNT_DETACH are orthogonal in the Linux kernel, so both may
be specified without any problems. Even if there were a problem with
this combination, it should be up to the kernel to take the correct
action or report an error.
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Using wait() in a library may be problematic as it may reap some
totally unrelated child process instead of the just forked
one. That can result in the library call doing weird things and
returning bad return values, but also in a breakage of an
arbitrary other thing in the program using the library.
[[kzak@redhat.com: - use waitpid() for umount too
- keep the current codding style]
Signed-off-by: Karel Zak <kzak@redhat.com>
The open() syscall is probably the most strong way how to check write
accessibility in all situations, but it's overkill and on some
paranoid systems with enabled audit/selinux. It fills logs with
"Permission denied" entries. Let's use eaccess() if available.
Signed-off-by: Karel Zak <kzak@redhat.com>
mount: /media/sdb5: mount(2) system call failed: Bad message.
is really ugly for end users. It seems XFS, extN (etc) use EBADMSG for
bad checksums. For network or pseudo filesystems continue to use "Bad
message" error...
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1496764
Signed-off-by: Karel Zak <kzak@redhat.com>
The current implementation would return always 0, as it is the return
code of mnt_fs_get_propagation. Change the implementation to raise an
exception on an error and return the propagation flags otherwise.
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
The mount man page assumes locking errors mapped to MNT_EX_FILEIO (16)
return code. Unfortunately, this is internally not exported as a
special error code, so it's returned as a generic (errno based)
stuff. This patch fixes this issue.
Note that we still use locking for example for utab or when enabled
/etc/mtab (disabled by default).
Signed-off-by: Karel Zak <kzak@redhat.com>
Assume that /proc is not mounted instead of returning an error when we
are unable to open the mounts and mountinfo files in /proc. Also set
cxt->mtab back to NULL so that it gets properly parsed when we check if
the next filesystem is mounted.
The goal is to have mount -a work when /proc is not mounted, typically
with /proc on the first line of fstab.
Signed-off-by: Ivan Delalande <colona@arista.com>
The originally used exit() is bad idea for the shared library.
Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
The current code always apply all flags from /etc/fstab on remount.
Unfortunately remount+bind has special semantic and it's impossible
from command line to avoid interaction with the "bind" from fstab.
Example, fstab:
/dev/sda1 /bar ext4 defaults 0 1
/bar /foo none bind 0 0
Command line:
# mount /foo -o remount,rw
produces:
mount(... MS_REMOUNT|MS_BIND ) syscall
This changes the per-mountpoint (VFS) ro flag to rw, but doesn't
change the filesystem itself.
This patch forces libmount to ignore "bind" from fstab when "-o
remount" specified on command line. If you need remount+bind semantic
you have to specify the "bind" flag on command line. This allow to
differentiate between
# mount /foo -o remount,bind,rw --> mount(MS_REMOUNT|MS_BIND)
and
# mount /foo -o remount,rw --> mount(MS_REMOUNT)
Suggested-by: NeilBrown <neilb@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
The umount command option --no-canonicalize means that the path is
already canonical. So, we can use mount table filter in this case too.
Signed-off-by: Karel Zak <kzak@redhat.com>
It is currently not possible to reliably and automatically
unmount an NFS filesystem. If the server is not available, the
umount command will hang.
The hang can be avoided by using "-l" or "-f", but neither
of these are appropriate for automatic use such as by an
automounter (e.g automountd or systemd).
"-l" will unmount even if the filesystem is in use, which
an automounter generally doesn't want. If the filesystem
is in use, then the umount should fail.
"-f" can cause the filesystem to abort pending transactions
which might break filesystem semantics. This can be useful
in the hands of a sysadmin, but not when used by an
automatic tool.
umount has another option, "-c" aka "--no-canonicalize"
which avoids some "stat" calls.
Currently this doesn't avoid all calls to
canonicalize_path()
as
mnt_context_prepare_umount() ->
lookup_umount_fs() ->
mnt_context_find_umount_fs() ->
mnt_context_get_mtab_for_target() ->
mnt_resolve_path() ->
canonicalize_path_and_cache() ->
canonicalize_path()
leads to that function being called.
The "-c" option could be taken to mean "I know what I'm
doing, this really is the path to a mount point, I just want
you to unmount it". Given that, it seems suitable to
extend this to avoid all 'stat' calls on the mountpoint.
It is already appropriate for any automount program to pass
"-c" to "umount", so they can be changed to do so at any
time.
With the patch below, "-c" will result in the mountpoint
never being "stat"ed, so umount won't hang on an
inaccessible server.
This isn't quite sufficient, for NFS at least, as the usage
of libmount in umount.nfs still calls 'stat' on the mount
point.
"-c" isn't passed to the umount helper, but it is reasonable
for such helpers to assume "-c" because "umount" will have
canonicalized the path when that is appropriate.
So, this patch treats "-c" much like "-l" and "-f" when
deciding whether it is safe to 'stat' the path.
Signed-off-by: NeilBrown <neilb@suse.com>
We got some errors on Alpine Linux where $LTLIBINTL is non-empty:
./.libs/libcommon.a(libcommon_la-blkdev.o): In function `open_blkdev_or_file':
lib/blkdev.c:282: undefined reference to `libintl_gettext
collect2: error: ld returned 1 exit status
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
It's pretty complex task to make mount(8) and umount(8) return code
and generate error message. It seems better to do that in the libmount
rather than force all library users to duplicate mount(8) mk_exit_code()
functions. It also means that all the messages will be translated only
once. Changes:
* all error messages are printed by warn()
* no more multi-line messages
* all messages prefixed by mount target (mountpoint)
* library provides mount(8) compatible MNT_EX_* codes
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1429531
Signed-off-by: Karel Zak <kzak@redhat.com>
This feature is supported by mount(8) only. It seems better move
this code to libmount. The results is more simple mount(8) and the
feature is accessible for all libmount users.
Signed-off-by: Karel Zak <kzak@redhat.com>
If utab.lock is created by a process with a restricted umask, utab.lock is
created with restricted permissions. It breaks userspace monitor.
Ensure that the mode is always 644.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer
Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.
Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
If -oloop is used and the loop device is reused, the loop device is detached
after umount. It is incorrect as it could break the another task using the loop
device.
This is caused by mnt_context_enable_loopdel(,TRUE) that is called from
mnt_context_prepare_umount() whenever "loop" option is used, independently on
AUTOCLEAR flag.
Remove the "loop" option for reused devices to prevent detaching of reused loop
device.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
If mount option "loop" is used with an argument, it should be respected. Commit
8efad715 introduced a regression. Even with an argument, overlaying loop device
is searched and argument is ignored. It could have unexpected side effects.
If argument is set, never allocate a new loop device.
How to reproduce:
mkdir -p cdrom
mkisofs -o cdrom.iso cdrom/ 2>/dev/null
losetup /dev/loop0 cdrom.iso
strace mount -t auto -o ro,loop=/dev/loop1 cdrom.iso /mnt 2>&1 | grep ^mount
cat /proc/self/mountinfo | grep /mnt
umount /mnt
losetup -d /dev/loop0
mount("/dev/loop0", "/mnt", "iso9660", MS_MGC_VAL|MS_RDONLY, NULL) = 0
327 60 7:0 / /mnt ro,relatime shared:241 - iso9660 /dev/loop0 ro
losetup: /dev/loop0: detach failed: No such device or address
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Commit f9906424 introduced a check that should prevent different information in
mtab and /proc/mounts. The check can require significant amount of time, and for
systems without mtab support it has no sense.
Execute this code only on systems with mtab.
When a systems with large number of nodes (thousands) mount the filesystems
simultaneously, the time required for serialization causes the utimensat() to
take a large amount of time (tens of minutes) when a large number of nodes are
simultaneously updating the timestamp.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Let's use optstr.c functions to parse pattern and options strings.
It's more robust that the old original mount(8) code and it supports
quotes in the options strings.
Signed-off-by: Karel Zak <kzak@redhat.com>
The original --target implementation (< v2.27) has been based on
stat(), so it was usable for valid paths only.
The new implementation is based on search in the mountinfo file, so it
works for arbitrary crazy path. This is not backwardly compatible and
if the path does not exist then it still returns at least root
directory mount entry.
This patch forces mnt_table_find_mountpoint() to check if the path is
valid before we search in the mountinfo file.
Signed-off-by: Karel Zak <kzak@redhat.com>
Let's hope this is last change necessary to cleanup x-* usage:
x-* persistent option, stored in utab, available for umount, etc.
X-* fstab comment only
mount(8) supports x-mount.mkdir= as well as newly recommended X-mount.mkdir=
Advantages:
* less invasive
* does not require exception for x-systemd
* does not require rename x-initrd to X-initrd
The systemd and dracut users will get the new (=fixed) functionality without a
change in fstab configuration. This is the primary goal.
Disadvantages:
* not 100% compatible libmount behavior, x-* options have not been
previously stored in utab. The API is the same, options will be still
available, but on x-* libmount will write to /run/mount/utab. For now
it seems only systemd uses x-*, and they like this behavior, so...
Addresses: https://github.com/systemd/systemd/pull/4515
Signed-off-by: Karel Zak <kzak@redhat.com>
Don't know why this was added in d78df0ac but it can't be right that
libmount/python removes these files in the toplevel builddir. Moreover
I've never seen such *.img files appearing during build at all.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
The previous patch introduces X-* options namespace for options
that have to be maintained in user space.
Unfortunately, systemd users already use mount options that are
necessary by umount or another operations. The conclusion from
discussion with systemd guys is to store all the systemd options
in userspace.
It seems better to add one line exception to libmount than force all
fstab users to rename x-systemd to X-systemd.
Addresses: https://github.com/systemd/systemd/pull/3904
Signed-off-by: Karel Zak <kzak@redhat.com>
x-* are fstab only and not stored in userspace (utab). In some cases
it's not optional solution because the option is also necessary for
umount or another operations. The X-* is exactly the same as x-*, but
stored to utab (or mtab on old systems).
It's usually bad idea to store mount options in userspace, but it's
better to provide any solution that force users to bypass mount(8)
(and friends) and implement 3rd-party incompatible solutions.
Signed-off-by: Karel Zak <kzak@redhat.com>
If you call mount(8) as root, then we need to append inverting options
(if specified by fstab) for "user" and "users" to /sbin/mount.<type>
command line, because for UID=0 mount.nfs follows command line rather
than the fstab setting.
This has been originally implemented by commit
a4c0cc75ff for the old mount(8). The
same feature is supported by libmount, unfortunately for "user" only.
We need the same also for "users" to be backwardly compatible.
Addresses: https://github.com/karelzak/util-linux/issues/368
Signed-off-by: Karel Zak <kzak@redhat.com>
when mounting a cifs share, the src is actually an UNC path which can in
in several forms:
simple: //host/share, //host/share/
including subpath: //host/share/sub/path
to check if the cifs fs is mounted we have to extract the subpath and
compare *that* to the root.
Signed-off-by: Aurelien Aptel <aaptel@suse.com>
Recent mount (since the switch to libmount in v2.22) drops the '=' in
mount options that are set to an empty value. For example, the command
line below will be affected:
# mount -o rw,myopt='' -t tmpfs tmpfs /mnt/tmp
Fix that by preserving an empty string in the options passed to the
mount(2) syscall when they are present on the command line.
Add test cases to ensure empty string handling is working as expected
and in order to prevent regressions in the future.
Also tested manually by stracing mount commands (on a kernel which
accepts a special extra option, for testing purposes.)
Before this commit:
# strace -e mount ./mount -t tmpfs -o rw,myopt='' tmpfs /mnt/tmp
mount("tmpfs", "/mnt/tmp", "tmpfs", MS_MGC_VAL, "myarg") = -1 EINVAL (Invalid argument)
After this commit:
# strace -e mount ./mount -t tmpfs -o rw,myopt='' tmpfs /mnt/tmp
mount("tmpfs", "/mnt/tmp", "tmpfs", MS_MGC_VAL, "myopt=") = 0
All test cases pass, including newly added test cases. Also checked
them with valgrind using:
$ tests/run.sh --memcheck libmount/optstr
Fixes#332.
Signed-off-by: Filipe Brandenburger <filbranden@google.com>
///aaa/bbb and /aaa/bbb/ are the same paths. This is important
especially with NFS where number of slashes are not the same in
the /proc/self/mountinfo and fstab or utab. The regular URI is
euler://tmp
but /proc contains
euler:/tmp
Reported-by: Ales Novak <alnovak@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
The current code scans loopdevs to detect already used loop device and
another scan to detect overlap.
Let's use one scan only, for this purpose loopcxt_find_overlap() has
been modified to return info (rc==2) about full size and offset match.
Signed-off-by: Karel Zak <kzak@redhat.com>
Add a safety check to mnt_context_setup_loopdev(). Only a loop device with equal
offset and sizelimit will be reused. If any overlapping loop device exists,
MNT_ERR_LOOPOVERLAP is returned.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Fully safe checks of loop device need to check sizelimit. To prevent need of two
nearly equal functions, introduce sizelimit parameter to several internal
functions:
loopdev_is_used()
loopdev_find_by_backing_file()
loopcxt_is_used()
loopcxt_find_by_backing_file()
If sizelimit is zero, fall back to the old behavior (ignoring of sizelimit).
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
This error code is intended for situations where overlapping loop device exists
and cannot be reused.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.
Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
For petty long time we have strdup_to_struct_member() macro to avoid
duplicate code when strdup() strings in setter functions. Let's use it
for libmount.
Signed-off-by: Karel Zak <kzak@redhat.com>
According to the Al Viro[1], kernel has no way to detect that a single file is
used by multiple loop devices, and multiple mounts of the same file using
different loop devices will result in a data corruption. Exactly this now
happens, if multiple btrfs sub-volumes in one file are mounted with "-oloop".
Make use of multiple -oloop mounting the same file safe: Do a loop devices
lookup, and if a loop device is already initialized, use it.
Hopefully it is possible, as "losetup -d" will return OK, even if the device
itself is in use, and is not released.
Problems:
There is a risk of race condition between the lookup and real mount.
Once loop device is initialized read-only, kernel offers no way to turn it to
read-write. It has to fail.
References:
https://lkml.org/lkml/2016/2/26/897
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>