Commit Graph

763 Commits

Author SHA1 Message Date
Sami Kerola 1b5042636f misc: fix reassigned values before old ones has been used [cppcheck]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 12:19:20 +02:00
Ruediger Meier b68d953e62 libmount: btrfs, remove unused setter functions
We have never used them since introduced in 2cd28fc8.
clang compiler warned about it.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-14 11:48:22 +02:00
Karel Zak 26cd36a636 Merge branch 'pylibmount-NULL-terminate-kwlist-in-Context_init' of https://github.com/zmedico/util-linux
* 'pylibmount-NULL-terminate-kwlist-in-Context_init' of https://github.com/zmedico/util-linux:
  pylibmount: NULL terminate kwlist in Context_init
2017-06-12 15:39:59 +02:00
Zac Medico 29b721bc9d pylibmount: NULL terminate kwlist in Context_init
Fixes a segfault observed with python3.6.
2017-06-07 17:25:12 -07:00
Karel Zak 11573ac0c8 libmount: (umount) use mount table filter on -c only
The path canonicalization is the worst use-case, it's better to read
all mount table than try canonicalize.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-07 12:40:17 +02:00
Karel Zak f8416301c1 libmount: use mount table filter on --no-canonicalize
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>
2017-06-07 11:35:26 +02:00
NeilBrown ce6e269447 umount: never 'stat' the path when "-c" is given.
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>
2017-06-06 11:41:05 +02:00
Ruediger Meier c0d7b11a3f build-sys: fix library order when linking
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>
2017-06-01 03:16:48 +02:00
Karel Zak a81b1946a1 libmount: (docs) add missing 'since' tags
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-23 13:32:45 +02:00
Karel Zak 7a5dbd2258 libmount: don't pass -1 to close() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:45:30 +02:00
Karel Zak fdaba3eb62 libmount: fix memory leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:38:16 +02:00
Karel Zak 799d9e845f tests: (libmount) parse version from command line
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 11:28:19 +02:00
Karel Zak 8503c0ed30 libmount: (docs) remove unwanted tag
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-28 12:39:21 +02:00
Karel Zak 0361cb6f9b libmount: add read-only warning
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-28 11:03:24 +02:00
Karel Zak 7b53418bf0 libmount: (docs) add unused declarations
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-27 14:17:50 +02:00
Karel Zak ea848180dd libmount: add mnt_context_get_excode()
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>
2017-04-27 14:10:23 +02:00
Karel Zak 6dede2f2f7 libmount: support MS_RDONLY on write-protected devices
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>
2017-04-26 17:27:02 +02:00
Stanislav Brabec ecfeae90a2 libmount: Ensure utab.lock mode 644
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>
2017-04-18 11:13:32 +02:00
Sami Kerola a0a32456c8 libmount: fix file descriptor leak
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-04-10 15:40:40 +02:00
Sami Kerola 41427f97d9
tests: add static keyword where needed [smatch scan]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-17 21:22:26 +00:00
Sami Kerola 08cce2e1cc libmount: fix use of preprocessor identifier
libmount/src/context_mount.c:990:5: warning: undefined preprocessor
identifier 'USE_LIBMOUNT_SUPPORT_MTAB'

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-13 14:48:07 +01:00
Karel Zak 7bb9ee99da libmount: cosmetic change to mnt_table_find_srcpath()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-28 14:47:02 +01:00
Petr Vorel 443be11396 libmount: return tab entry for default node
This is useful for lsblk.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
2017-02-28 14:41:42 +01:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
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>
2017-02-20 12:58:49 +01:00
Yuri Chornoivan a7349ee315 docs: Fix word repetitions 2017-02-13 14:10:12 +01:00
Karel Zak 1a3397906d libmount: make rootfs lookup by parent-id more robust
The root FS id really does not have to be the smallest one.

Reported-by: Michal Soltys <soltys@ziu.info>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-01 16:20:12 +01:00
Stanislav Brabec 7b46647df4 libmount: Fix incorrect detach of reused loop device
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>
2017-01-16 12:25:45 +01:00
Stanislav Brabec 3789806db2 libmount: fix mount -oloop=/dev/loopX regression
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>
2017-01-16 12:25:45 +01:00
Stanislav Brabec 89958178f6 If mtab support is disabled, disable ro/rw mtab checks
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>
2017-01-10 17:32:32 +01:00
Karel Zak 7d395c75d1 libmount: support name=value for mnt_match_options()
$ findmnt --options mode=755
TARGET         SOURCE FSTYPE   OPTIONS
/sys/fs/cgroup tmpfs  tmpfs    rw,nosuid,nodev,noexec,relatime,mode=755
/dev           udev   devtmpfs rw,relatime,size=1983516k,nr_inodes=495879,mode=755

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-20 16:01:22 +01:00
Karel Zak db17f201b8 libmount: reimplement mnt_match_options()
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>
2016-12-20 15:35:50 +01:00
Sébastien Helleu d673b74e9d docs: replace FTP by HTTPS in kernel.org URLs
The links to ftp://ftp.kernel.org/ are replaced by
https://www.kernel.org/.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 11:22:26 +01:00
Karel Zak 80c31a0b59 findmnt: error on --target /non-exist
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>
2016-12-16 13:00:45 +01:00
Karel Zak 8048a826cc Merge branch 'build-fixes' of https://github.com/rudimeier/util-linux
* 'build-fixes' of https://github.com/rudimeier/util-linux:
  build-sys: don't clean *.img files
2016-12-09 15:37:09 +01:00
Karel Zak 0a14cc8bcc libmount: revert X-* and x-* meaning
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>
2016-12-09 15:36:14 +01:00
Ruediger Meier 38f75ebe1e build-sys: don't clean *.img files
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>
2016-12-09 14:27:48 +01:00
Karel Zak 5c493bd92f libmount: use x-systemd options as X-*
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>
2016-12-08 15:27:24 +01:00
Karel Zak 83601b1af9 libmount: introduce X-* comments
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>
2016-12-08 14:55:02 +01:00
Karel Zak 3c4a3de0fc mount: append inverting options for mount.<type> on "users"
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>
2016-10-27 15:30:20 +02:00
Karel Zak 9e13b1c1c7 libmount: fix null-checking [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-04 16:33:14 +02:00
Karel Zak 3e44e75dae libmount: paranoid change in mnt_table_is_fs_mounted()
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-09-29 11:55:07 +02:00
Aurelien Aptel 76d4fba2e4 libmount: fix mount -a for cifs
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>
2016-09-29 11:51:38 +02:00
Karel Zak 81b176c4da docs: some random fixes
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-09-27 12:52:47 +02:00
Filipe Brandenburger 727c689908 libmount: Preserve empty string value in optstr parsing
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>
2016-08-10 13:59:52 -07:00
Karel Zak d4e89dea4e libmount: ignore redundant slashes
///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>
2016-08-08 17:23:54 +02:00
Karel Zak dff7e16046 libmount: one iteration to detect overlap and reuse loopdev
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>
2016-08-04 11:48:26 +02:00
Karel Zak c444a71b1b lib/loopdev: cleanup sizelimit check
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-04 10:49:46 +02:00
Stanislav Brabec 8efad715b9 libmout: Reuse loop device safely
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>
2016-08-03 11:53:28 +02:00
Stanislav Brabec 74a4705a99 Add sizelimit to internal API
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>
2016-08-03 11:53:28 +02:00
Stanislav Brabec 7e6b7035e7 libmount: Introduce new error: MNT_ERR_LOOPOVERLAP
This error code is intended for situations where overlapping loop device exists
and cannot be reused.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-08-03 11:53:28 +02:00
Stanislav Brabec 441cdba95b libmount: Fix possible crash in mnt_context_setup_loopdev()
If loopcxt_init() fails, Iloopcxt_deinit() should not be called.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-08-03 11:53:28 +02:00
Sami Kerola 445e9ca2d4
libmount, look: remove dead code [oclint]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Sami Kerola 74ce680a3e
misc: simplify if clauses [oclint]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Karel Zak 372d410d9e libmount: don't check nonnull attributes for NULL [-Wnonnull-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-06-14 13:55:27 +02:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Karel Zak deb1c90327 libmount: remove duplicate code
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>
2016-04-22 13:59:06 +02:00
Stanislav Brabec bdf46c4df9 libmount: reuse existing loop device
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>
2016-04-22 12:50:14 +02:00
Stanislav Brabec 6e25802675 libmount: Re-organize is_mounted_same_loopfile()
First parse options, then initialize context.
No change in function.
The change is needed for loop device reuse.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-04-22 12:50:14 +02:00
Sami Kerola ac943a662d
libmount: fix memory leak
Found with scan-build.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-04-19 21:27:54 +01:00
Karel Zak 7997468484 pylibmount: include c.h
... for sys/sysmacros.h and major() and minor() macros.

Reported-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-18 13:19:12 +02:00
Karel Zak a772281dff libmount: make kernel_fs_postparse() more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-15 14:48:29 +02:00
Karel Zak 4b85aef355 libmount: fix mnt_table_parse_stream() logic
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-15 14:30:43 +02:00
Karel Zak edeb6223fe tests: make tests more portable due to mtab
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-15 14:10:23 +02:00
Karel Zak b529694f61 libmount: fix mnt_table_parse_mtab() logic
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-15 12:05:55 +02:00
Karel Zak 3904d87636 tests: remove USE_LIBMOUNT_FORCE_MOUNTINFO
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-15 11:29:22 +02:00
Karel Zak e778642a9e libmount: don't support /etc/mtab by default
The file mtab is evil and already unused by mainstream distributions.

Now libmount is able to detect mtab->/proc/mounts and use
/proc/self/mountinfo if necessary. This heuristic seems overkill in
many cases. It's also dangerous on systems where mountinfo is strongly
required (systemd based distros).

This patch #ifdefs mtab code and forces libmount to always use
/proc/self/mountinfo.

The new configure option --enable-libmount-support-mtab is necessary
to enable old behavior to support mtab.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-14 14:26:54 +02:00
Karel Zak 2238214ddc libmount: try absolute target before canonicalize
The path canonicalization is expensive and in many cases unwanted due
to problems with readlink() on unreachable NFS and automounters.

This patch add a possibility to search also by $(CWD)/<path> if the
<path> is relative to reduce number of situation when we convert the
path to the canonical absolute path.

The common use-case:

	# cd /some/long/path
	# umount ./mountpoint

old version:

15543: libmount:      TAB: [0x560a99a54230]: lookup TARGET: './test'
15543: libmount:    CACHE: [0x560a99a54290]: canonicalize path ./test
15543: libmount:    CACHE: [0x560a99a54290]: add entry [ 1] (path): /mnt/test: ./test
15543: libmount:      TAB: [0x560a99a54230]: lookup canonical TARGET: '/mnt/test'
15543: libmount:      CXT: [0x560a99a54050]: umount fs: /mnt/test

new version:

15597: libmount:      TAB: [0xabf230]: lookup TARGET: './test'
15597: libmount:      TAB: [0xabf230]: lookup absolute TARGET: '/mnt/test'
15597: libmount:      CXT: [0xabf050]: umount fs: /mnt/test

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-13 12:29:16 +02:00
Karel Zak e9cd2e2bd9 libmount: Fix possible NULL dereference in get_btrfs_fs_root()
The function mnt_table_get_fs_root() should be robust enough to accept
NULL as mountinfo -- the right behaviour is to default to '/'.

The set_fs_root() (tab_update.c) has to understand when mountinfo is
necessary (for bind mounts and btrfs).

Reported-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-31 11:45:55 +02:00
Karel Zak 935f9d5b35 libmount: result of operation is garbage or undefined [clang analyze]
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-29 15:44:48 +02:00
Ruediger Meier a5b3be92c6 build-sys: pylibmount, mount context is Linux only
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-21 21:03:41 +01:00
Ruediger Meier 2eb6a7486e build-sys: some libmount test progs are Linux only
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-21 21:03:40 +01:00
Karel Zak 40f00b4f8e libmount: improve conversion from root= to the devname
Currently the code supports /dev/name or PARTUUID= only. We also
need to support 'maj:min' and 'hexhex' notations.

Reported-by: George Spelvin <linux@horizon.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-15 14:07:34 +01:00
Ruediger Meier 18336d16d9 build-sys: use AC_PROG_MKDIR_P and remove a few gnuisms
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-13 21:48:09 +01:00
Ruediger Meier 58c87bd045 misc: fix icc/clang compiler warnings
clang warning:
libmount/src/tab.c:1833:6: warning: variable 'rc' is used uninitialized whenever
      'if' condition is true [-Wsometimes-uninitialized]
        if (!mpc)
            ^~~~

icc printf warnings:
    libmount/src/monitor.c(348): warning #2279: printf/scanf format not a string literal and no format arguments
            DBG(MONITOR, ul_debugobj(mn, status == 1 ? " success" : " nothing"));
            ^
    login-utils/vipw.c(348): warning #2279: printf/scanf format not a string literal and no format arguments
                           : _("You are using shadow passwords on this system.\n"));
                                                                                  ^

icc enum warnings:
    disk-utils/fdisk-menu.c(150): warning #188: enumerated type mixed with another type
            .exclude = FDISK_DISKLABEL_GPT | FDISK_DISKLABEL_BSD,
                       ^
    libsmartcols/src/table_print.c(750): warning #188: enumerated type mixed with another type
                            &width, align,
                                    ^

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-13 21:47:27 +01:00
Karel Zak 5bb1d22e8a build-sys: fix if..endif for *_la_LDFLAGS
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-10 13:54:15 +01:00
Stanislav Brabec c59409b945 libmount: Typo fix 2016-03-10 11:03:00 +01:00
Karel Zak 3fe3f560b7 Revert "include sysmacros.h where used"
This reverts commit 46a40c0184.
2016-03-08 14:26:33 +01:00
Mike Frysinger 46a40c0184 include sysmacros.h where used
BSD/Linux systems stick major/minor/makedev in sysmacros.h.  Newer Linux
libraries have been moving away from including sysmacros.h implicitly via
sys/types.h, so include it directly.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-03-08 14:21:55 +01:00
Ruediger Meier 9d76c6fb9f libmount: don't include libio.h
This include was added just one month ago in 5a971329 but I don't see
what it was good for. It's missing in musl libc.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 23:29:55 +01:00
Ruediger Meier 1a048dc5e2 lib: move fopen_at() to fileutils.h, remove at.h
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 15:36:00 +01:00
Ruediger Meier 2208b3ccb2 lib: remove openat fallback functions (include/at.h)
I have validated that we are still compatible at least back to
  - openSUSE 11.4
  - SLE 11
  - RHEL/CentOS 6
  - OSX 10.10.x, (Xcode 6.3)
  - FreeBSD 10.2

Confirmed incompatibility:
  - OSX 10.9.x, (Xcode 6.2)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 15:33:56 +01:00
Ruediger Meier 2013b33f40 build-sys: disable unused parameter warnings for some test progs
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 03:20:22 +01:00
Ruediger Meier 5fde1d9f06 tests: fix compiler warnings [-Wmissing-prototypes]
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 03:18:09 +01:00
Ruediger Meier 48df5980b4 libmount: add mnt_fs_set_priority()
Looks like it got lost in ce4dd666.

Compiler warning discoverd this issue:
libmount/src/fs.c:1171:5: warning: no previous prototype for 'mnt_fs_set_priority' [-Wmissing-prototypes]
 int mnt_fs_set_priority(struct libmnt_fs *fs, int prio)
     ^

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 01:19:49 +01:00
Ruediger Meier b0b54cc582 build-sys: always add AM_CFLAGS
We were missing our nice compliler warnings for many programs
and libs. See next commits how many trivial and non-trival
warnings have to be fixed.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 01:17:29 +01:00
Ruediger Meier b201f1d86c build-sys: always use global LDADD
This was a major showstopper when building on a system where
LTLIBINTL libs are needed (e.g. OSX). Maybe there are a few test
programs which wouldn't need LDADD ... never mind.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 01:16:58 +01:00
Ruediger Meier 3719bf8de9 build-sys: check linker support for version scripts
The macro AX_CHECK_VSCRIPT was taken from gnu autoconf archive.
http://www.gnu.org/software/autoconf-archive/

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 12:53:48 +01:00
Karel Zak dc7c3d6587 libmount: fix mnt_table_is_fs_mounted() loopdev use
The function does not detect already mounted loop devices on systems
with regular /etc/mtab file.

The patch also improves test_is_mounted() to be useful with mtab.

Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-16 15:44:31 +01:00
Karel Zak 7bbde59c8c libmount: add loop to debug output
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-16 15:03:22 +01:00
Karel Zak af86564357 libmount: fix memleak in mnt_pretty_path()
References: https://github.com/karelzak/util-linux/issues/275
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-12 13:09:28 +01:00
Karel Zak d58b9706ed libmount: fix mnt_table_is_fs_mounted() for loopdev
Reported-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-12 11:03:32 +01:00
Filipe Brandenburger d54eb46646 Revert "build-sys: Order pylibmount after usrlib on install"
This reverts commit e61f406913.
2016-02-05 10:08:50 -08:00
Ruediger Meier 3fd1f7711e docs: fix typos found by codespell
Using "codespell" from https://github.com/lucasdemarchi/codespell

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-03 15:10:08 +01:00
Karel Zak 9aa3173bab libmount: move btrfs subvol code refactoring
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-01 13:10:33 +01:00
Karel Zak 7dca35b2be libmount: fix target resolving for btrfs stuff
and make the code more verbose.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-01 12:36:07 +01:00
Stanislav Brabec c6f9f229c5 libmount: code re-indentation
For easier review, the fix of libmount comes in two patches:
PATCH 1/2: libmount: run btrfs subvol checks for "subvolid" option
PATCH 2/2: code re-indentation

No code change is present in this patch.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-02-01 12:23:18 +01:00
Stanislav Brabec 618a88140e libmount: run btrfs subvol checks for "subvolid" option
It is possible to identify btrfs subvolume with "subvolid" instead of "subvol".
In such case, btrfs specific check mistakenly assumes that the default subvolume
is going to be mounted, even if subvolid specifies id of non-default subvolume.

Implement a code for "subvolid" option.

For easier review, this fix comes in two patches:
PATCH 1/2: libmount: run btrfs subvol checks for "subvolid" option
PATCH 2/2: code re-indentation

How to reproduce:
	truncate -s1G btrfs_test.img
	mkdir -p btrfs_mnt
	/sbin/mkfs.btrfs -f -d single -m single ./btrfs_test.img
	mount -o loop btrfs_test.img btrfs_mnt
	pushd .
	cd btrfs_mnt
	mkdir -p d0/dd0/ddd0
	cd d0/dd0/ddd0
	touch file{1..5}
	btrfs subvol create s1
	cd s1
	touch file{1..5}
	mkdir -p d1/dd1/ddd1
	cd d1/dd1/ddd1
	btrfs subvol create s2
	rid=$(btrfs inspect rootid s2)
	echo new default $rid
	btrfs subvol get-default .
	btrfs subvol set-default $rid .
	popd
	DEFAULT_SUBVOLID=`btrfs subvolume get-default btrfs_mnt | while read dummy id rest ; do echo $id ; done`
	NON_DEFAULT_SUBVOLID=`btrfs subvolume list btrfs_mnt | while read dummy id rest ; do if test $id = $DEFAULT_SUBVOLID ; then continue ; fi ; echo $id ; done`
	umount btrfs_mnt
	losetup /dev/loop0 $PWD/btrfs_test.img
	echo "/dev/loop0 $PWD/btrfs_mnt btrfs subvolid=$NON_DEFAULT_SUBVOLID 0 0" >>/etc/fstab
	./mount -a
	./mount -a
	umount btrfs_mnt
	sed -i "/\/dev\/loop0/d" /etc/fstab
	losetup -d /dev/loop0
	rm btrfs_test.img
	rmdir btrfs_mnt

Current behavior of second "mount -a":
    mount: /dev/loop0 is already mounted or /root/btrfs_mnt busy
           /dev/loop0 is already mounted on /root/btrfs_mnt

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-02-01 12:23:18 +01:00
Stanislav Brabec d2f8267847 libmount: run btrfs subvol checks for "auto" fs type
It is possible to mount btrfs using "auto" keyword in fstab. In such
case, btrfs specific checks are skipped. Run them for "auto" as well.

Looking at the code, it is a safe approach. In case of btrfs, it will do
what is needed, in case of no btrfs, btrfs_get_default_subvol_id() will
fail, and the rest of the code is skipped.

How to reproduce:
See reproducer in 2cd28fc and replace fstab line by
	echo "/dev/loop0 $PWD/btrfs_mnt btrfs auto 0 0" >>/etc/fstab

Current behavior of second "mount -a":
	mount: /dev/loop0 is already mounted or /root/btrfs_mnt busy
	       /dev/loop0 is already mounted on /root/btrfs_mnt

Testcases for btrfs and ext4:
	truncate -s1G btrfs_test.img
	truncate -s1G ext4_test.img
	mkdir -p btrfs_mnt
	mkdir -p ext4_mnt
	/sbin/mkfs.btrfs -f -d single -m single ./btrfs_test.img
	/sbin/mkfs.ext4 ./ext4_test.img
	losetup /dev/loop0 $PWD/btrfs_test.img
	losetup /dev/loop1 $PWD/ext4_test.img
	echo "/dev/loop0 $PWD/btrfs_mnt auto defaults 0 0" >>/etc/fstab
	echo "/dev/loop1 $PWD/ext4_mnt auto defaults 0 0" >>/etc/fstab
	./mount -a
	./mount -a
	umount btrfs_mnt
	umount ext4_mnt
	sed -i "/\/dev\/loop[01]/d" /etc/fstab
	losetup -d /dev/loop0
	losetup -d /dev/loop1
	rm btrfs_test.img
	rm ext4_test.img
	rmdir btrfs_mnt
	rmdir ext4_mnt

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-02-01 11:59:31 +01:00
Karel Zak 314c3358d5 libmount: add 'force-mountinfo' to features list, improve debug
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-01 11:01:44 +01:00
Filipe Brandenburger e61f406913 build-sys: Order pylibmount after usrlib on install
This fixes a failure of `make install DESTDIR=...` when trying to relink
pylibmount against libmount.la.

libtool will look for libmount.so under ${DESTDIR}/${libdir}, but if it
is not yet present, it will assume it is a system installed library and
use -lmount instead.

This makes the install order significant.

Automake lists the install entries in alphabetical order, and as
install-pylibmountexecLTLIBRARIES < install-usrlib_execLTLIBRARIES,
make will try to install pylibmount.so before libmount.so is present
in the DESTDIR, which will then cause libtool to fallback to -lmount
when relinking. This causes the error below:

  libtool: install: warning: relinking `pylibmount.la'
  libtool: install: (... libtool --mode=relink gcc -o pylibmount.la \
        -rpath /usr/lib/python2.7/dist-packages/libmount \
        libmount/python/*.lo libmount.la ... -lpython2.7 \
        -inst-prefix-dir /path/to/destdir)
  /usr/bin/ld: cannot find -lmount
  collect2: error: ld returned 1 exit status
  libtool: install: error: relink `pylibmount.la' ...
  make[3]: *** [install-pylibmountexecLTLIBRARIES] Error 1

Work around this issue by using a zz_ prefix for the pylibmount exec
dir, in order to install it last.

This does not work if parallel make is used for the install step, but
that should be a minor issue (parallel install is probably not that
useful for util-linux, which is not that large a package to actually
benefit from it.) The proper fix should be to introduce a make
dependency of target install-pylibmountexecLTLIBRARIES on target
install-usrlib_execLTLIBRARIES, but unfortunately there is no good way
to accomplish that in automake without overriding it completely.

This issue seems to be previously encountered in automake context, since
automake includes a hack to insert such a dependency rule to install all
libLTLIBRARIES before attempting to install binPROGRAMS, initially
introduced in the commit below:
http://git.savannah.gnu.org/cgit/automake.git/commit/?id=bd4a1d5ad1a72fa780a8b7fd6c365a5dad2e6220

Also, a related bug from Ubuntu tracker:
https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/1442076

Tested that `make install` starts working again after this commit, even
when libmount-dev is not installed on the system. Also confirmed that
`make distcheck` is now functional.

Confirmed that both __init__.py and the .so library are still installed
in the Python directory.

Tested that it still works without python-devel installed, also
inspected Makefile.in which looks correct.

Tested that `make install pylibmountexecdir=...` still works to override
destination directory at `make install` time.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
2016-01-26 13:24:25 -08:00
Karel Zak 7ccc2989dd libmount: cleanup btrfs.c header
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-26 15:57:24 +01:00
Karel Zak 5a9713293d libmount: consolidate btrfs stuff, make it more portable
- add --with-btrfs (enabled by default)
- check for linux/btrfs.h
- add "btrfs" to libmount features list (see mount -V)
- #ifdef HAVE_BTRFS_SUPPORT for all btrfs stuff in libmount

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-26 14:39:13 +01:00
Stanislav Brabec 2cd28fc82d libmount: handle btrfs default subvolume mount
When mounting btrfs volume without subvol= and subvolid=, and the
btrfs volume has default subvolume defined, mount() mounts the default
subvolume and not the volume root as other filesystems do.

To handle this situation correctly (for example for "mount -a"),
libmount has to be capable to detect default subvolume.

Add btrfs.c and btrfs.h that implement needed functions.

This patch adds mnt_table_find_target_with_option() to the library API.

Known problems not covered by this patch:

- Use of subvolid= in fstab is not yet handled.

- Use of type auto in combination with subvol= in fstab is not yet
  handled.

- Use of btrfs in loop devices, where image file is specified in fstab is
  not yet handled (use of /dev/loop0 in fstab works).

- If fstab uses subvol=, and subvol path changes since last "mount -a",
  subsequent "mount -a" will not recognize that it is already mounted,
  and it will attempt to mount it second time. To fix it, libmount should
  remember subvolid in time of mount (subvolid is unique for the
  subvolume, subvol is not).

- mountinfo contains subvol and subvolid since kernel 4.2. Before kernel
  4.2, there is no reasonable way to solve this situation. (One would
  create temporary mount point, mount the default, call needed ioctl() to
  determine what was mounted, deduce the default subvolume, compare it
  with subvolume of mounted volume, unmount and return result.)

How to reproduce:
	truncate -s1G btrfs_test.img
	mkdir -p btrfs_mnt
	/sbin/mkfs.btrfs -f -d single -m single ./btrfs_test.img
	mount -o loop btrfs_test.img btrfs_mnt
	pushd .
	cd btrfs_mnt
	mkdir -p d0/dd0/ddd0
	cd d0/dd0/ddd0
	touch file{1..5}
	btrfs subvol create s1
	cd s1
	touch file{1..5}
	mkdir -p d1/dd1/ddd1
	cd d1/dd1/ddd1
	btrfs subvol create s2
	rid=$(btrfs inspect rootid s2)
	echo new default $rid
	btrfs subvol get-default .
	btrfs subvol set-default $rid .
	popd
	umount btrfs_mnt
	losetup /dev/loop0 $PWD/btrfs_test.img
	echo "/dev/loop0 $PWD/btrfs_mnt btrfs defaults 0 0" >>/etc/fstab
	mount -a
	mount -a
	umount btrfs_mnt
	sed -i "/\/dev\/loop0/d" /etc/fstab
	losetup -d /dev/loop0
	rm btrfs_test.img
	rmdir btrfs_mnt

Current behavior:
	mount: /dev/loop0 is already mounted or /root/btrfs_mnt busy
	       /dev/loop0 is already mounted on /root/btrfs_mnt

Expected behavior is to ignore already mounted FS.

[kzak@redhat.com: - make 'var' optional for mnt_table_find_target_with_option(),
                  - add mnt_table_find_target_with_option() to symbols table and docs
                  - add "btrfs" string between supported debug modes
                  - minor coding style changes]

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Cc: David Štěrba <dsterba@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-26 11:14:25 +01:00
Boris Egorov fef0063119 libblkid,libmount: Do not use void* in calculations [cppcheck]
[libblkid/src/superblocks/zfs.c:179]: (portability) 'label' is of type 'const void *'. When using void pointers in calculations, the behaviour is undefined.
[libblkid/src/superblocks/zfs.c:237]: (portability) 'label' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[libblkid/src/topology/topology.c:221]: (portability) 'chn.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[libmount/src/fs.c:153]: (portability) 'old' is of type 'const void *'. When using void pointers in calculations, the behaviour is undefined.
[libmount/src/fs.c:154]: (portability) 'new' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
2016-01-19 12:59:12 +06:00
Karel Zak f7ac9e71b1 login, mount: fix __SC_GETPW_R_SIZE_MAX usage
sysconf(_SC_GETPW_R_SIZE_MAX) returns initial suggested size for pwd
buffer (see getpwnam_r man page or POSIX). This is not large enough in
some cases.

Yes, this sysconf option is misnamed (should be _SC_GETPW_R_SIZE_MIN).

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-15 12:33:34 +01:00
Karel Zak 0f1cbe9430 libmount: add comment, remove TODO item
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-10 11:45:31 +01:00
Karel Zak 6589a1632b libmount: use fstatat(AT_NO_AUTOMOUNT) for mountpoints
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-09 10:26:16 +01:00
Karel Zak 624996a950 libmount: add cgroup2 pseudo FS
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-08 12:16:27 +01:00
Karel Zak 352740e88e libmount: fix is-mounted check for btrfs
fstab:
  /dev/sdc        /mnt/test       btrfs   subvol=/anydir
  /mnt/test       /mnt/test2      auto    bind

and "mount -a" does not detect that /mnt/test2 is already mounted.

Reported-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-02 13:38:51 +01:00
Karel Zak 1bb02a2da9 libmount: follow docs with parse-error callback return code
The docs says that recoverable errors have rc > 0.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-10-15 12:12:11 +02:00
Karel Zak 440a355a3d libmount: fix uid= and gid= translation
The current libmount version returns error when no able to convert
username/groupname to uid/git.

 # mount mount /dev/sda1 /mnt/test -o uid=ignore
 # mount: failed to parse mount options

This is regression, the original mount(8) has ignored possible unknown
user/group names and the option has been used unconverted (with the
original value). For example UDF kernel driver depends on this behavior
and "uid=ignore" (or "forgot") is a valid mount option.

Fixed version (unit test):

./test_mount_optstr  --fix uid=kzak,gid=forgot,aaa,bbb
optstr: uid=kzak,gid=forgot,aaa,bbb
fixed:  uid=1000,gid=forgot,aaa,bbb

Reported-By: Anthony DeRobertis <anthony@derobert.net>
Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=801527
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-10-12 11:42:13 +02:00
Karel Zak 1d15c4b273 libmount: (monitor) remove unnecessary epoll EPOLLPRI
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-11 11:37:49 +02:00
Karel Zak 0250174654 libmount: (monitor) don't check for regular mtab
The monitor supports utab only (as documented). It's application
responsibility to use libmount in the right way. It's overkill to
check for valid environment during monitor initialization.

For example systemd checks for regular mtab during boot, it's better
than try to be smart later in libmount monitor when system is already
running.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-11 11:19:30 +02:00
Kir Kolyshkin 58dda170fb libmount: typo fixes
I was reading the code and found these mountinfo typos.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
2015-09-02 18:45:06 -07:00
Karel Zak 928f209cea libmount: fix compiler warning [-Wdiscarded-qualifiers]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-31 11:38:58 +02:00
Karel Zak d92b8c3ba1 libmount: handle arbitrary line length for mounts
Based on patch from Kees Cook, he wrote:
> The kernel's maximum path length is PATH_MAX (4096). The use of BUFSIZ
> (8192) would seem sufficient for reading mountinfo files, but it's
> not. Paths may contain escaped characters (requiring 4x as many bytes
> to read), and filesystem options are of unknown length. To avoid
> mounts being either intentionally or unintentionally hidden from
> libmount and its users, we must accept arbitrary length lines when
> parsing.
>
> Long valid entries are currently ignored, with warnings like this:
> mount: /proc/self/mountinfo: parse error: ignore entry at line 11.
> mount: /proc/self/mountinfo: parse error: ignore entry at line 12.
>
> Instead of using a malloc on every line parsed from mount files, do it
> once per mount file context, growing it as needed. The general case
> will never grow it.

I have moved the parser stuff to the new struct libmnt_parser, maybe
we can move more things (e.g. libmnt_table->fmt) to this struct later.

Reported-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-27 10:49:39 +02:00
Sami Kerola 624e147ba2 misc: fix shadow declarations
sys-utils/zramctl.c: In function 'get_mm_stat':
sys-utils/zramctl.c:276:58: warning: declaration of 'inbytes' shadows a global declaration [-Wshadow]
 static char *get_mm_stat(struct zram *z, size_t idx, int inbytes)
sys-utils/zramctl.c:119:39: note: shadowed declaration is here
 static unsigned int raw, no_headings, inbytes;

libmount/src/tab.c: In function 'mnt_table_get_fs_root':
libmount/src/tab.c:1221:22: warning: declaration of 'fs' shadows a parameter [-Wshadow]
    struct libmnt_fs *fs = mnt_table_find_mountpoint(tb,
libmount/src/tab.c:1197:24: note: shadowed declaration is here
      struct libmnt_fs *fs,

disk-utils/fsck.minix.c: In function 'main':
disk-utils/fsck.minix.c:1364:17: warning: declaration of 'i' shadows a previous local [-Wshadow]
   unsigned long i, free;
disk-utils/fsck.minix.c:1250:6: note: shadowed declaration is here
  int i;

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-08-24 10:55:37 +02:00
Karel Zak d9579859c2 libmount: (monitor) fix docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-19 15:27:20 +02:00
Karel Zak 9ac77b8a78 libmount: add support for "bind,ro"
Now it's necessary t use two mount(8) calls to create a read-only
mount:

  mount /foo /bar -o bind
  mount /bar -o remount,ro,bind

This patch allows to specify "bind,ro" and the remount is done
automatically by libmount by additional mount(2) syscall. It's not
atomic of course.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-17 11:54:26 +02:00
Karel Zak 41e554e303 libmount: fix typo in mnt_optstr_prepend_option()
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-05 13:39:06 +02:00
Karel Zak 941c734c56 libmount: variable dereferenced before check [smatch scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-05 12:46:56 +02:00
Karel Zak 2c6567799d build-sys: add --disable-assert
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-04 13:40:44 +02:00
Karel Zak cba392b661 libmount: cleanup assert() usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-04 13:21:42 +02:00
Karel Zak 6b9784b442 libmount: make mnt_get_filesystems() more robust [clang analyze]
The mnt_free_filesystems() relies on NULL as the last item in the
filesystems array. It's necessary to keep NULL there after failed
strdup() too, because we call mnt_free_filesystems() to deallocate
after error.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-30 09:28:19 +02:00
Karel Zak 462a570340 libmount: sort pseudo filesystems by LC_COLLATE=C
Addresses: https://github.com/karelzak/util-linux/issues/212
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-29 12:43:45 +02:00
Karel Zak 7dc0f5c90e libmount: improve monitor to be usable for non-root users
The current implementation calls mkdir and open(O_CREATE) to
initialize /run/mount/utab.lock before it starts to monitor the file.
Unfortunately it makes the monitor useless for non-root processes
(e.g. systemd --user).

The new implementation adds inotify watch for the last existing
component in the path (/run/mount/utab.lock) and re-initialize
after a change. It makes the monitor robust enough for mkdir/rmdir
when monitor is already active.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-19 12:30:40 +02:00
Ronny Chevalier 1280109fdc libmount: (docs) fix wording
Signed-off-by: Ronny Chevalier <chevalier.ronny@gmail.com>
2015-06-03 13:21:52 +02:00
Ronny Chevalier 8b1333423a libmount: (docs) fix typo
Signed-off-by: Ronny Chevalier <chevalier.ronny@gmail.com>
2015-06-03 13:06:59 +02:00
Karel Zak 28cdf9c612 libmount: do not call umount helper on --fake
The umount.<type> helpers does not support --fake option and it does
not make sense to call the helpers at all. All we need is to remove
mtab/utab entries.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1172297
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-03 11:02:25 +02:00
Karel Zak 08e193e1e4 libmount: fix mnt_monitor_event_cleanup()
We have to call epoll to drain mountinfo events too. The problem is
visible if the monitor epoll FD is within another (top-level) epoll.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-01 13:17:41 +02:00
Karel Zak d5dbd57b22 docs: fix gtk-docs related warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-28 12:28:23 +02:00
Karel Zak 398f7f9d99 libmount: add note about flock() to docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-02 17:32:47 +02:00
Karel Zak 8c7f073aae libmount: add support for MS_LAZYTIME
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-30 12:43:45 +02:00
Karel Zak 209fd7a748 libmount: mark overlay as pseudo-FS
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-11 11:38:07 +01:00
Karel Zak c8b9ecebe9 libmount: add mnt_table_get_fs_root() to header file
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-11 11:11:19 +01:00
Karel Zak cc06a01ec5 libmount: cleanup fs root detection code
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-10 13:49:57 +01:00
Karel Zak cd41b385a0 findmnt: don't rely on st_dev for --target
The overlay filesystem does not provide usable st_dev (in traditional
UNIX way). It's necessary to search in /proc/self/mountinfo to detect
which path element is mountpoint.

$ findmnt --target /mnt/merged/dir-a/foo
TARGET      SOURCE  FSTYPE  OPTIONS
/mnt/merged overlay overlay rw,relatime,lowerdir=/mnt/low,upperdir=/mnt/high/data,workdir=/mnt/high/work

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-10 12:51:44 +01:00
Karel Zak 254743e4a6 build-sys: cleanup realtime lib usage
* check for timer_create()
* define dependence on timer_create() for flock
* rename CLOCKGETTIME_LIBS to REALTIME_LIBS

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-06 14:20:19 +01:00
Karel Zak 37290a5396 libmount: remove assert(arg) from public functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-16 14:17:54 +01:00
Karel Zak ff5ace78d6 libmount: improve remount logic
* fix fs type detection for remount
 * parse mtab only for remount and umount

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-16 13:39:33 +01:00
Karel Zak e3f72275ca libmount: add --enable-libmount-force-mountinfo
The default libmount mtab management depends on mtan symlink. If the
symlink exists than libmount parses /proc/self/mountinfo, otherwise it
parses regular classic /etc/mtab. This is backwardly compatible and
transparent solution.

Unfortunately, this is not robust enough because some broken init
scripts or 3-party mount helpers may remove the symlink and create
regular mtab file. This is pretty bad if initd (systemd) depends on
libmount.

Fortunately we known that mtab is absolutely unwanted on some distros,
so it's fine too ignore mtab at all and don't care about the symlink.

Reported-by: Martin Pitt <martin.pitt@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-16 12:49:49 +01:00
Karel Zak 60d29f827b libmount: read utab always when read mtab from /proc
Now libmount reads utab only when mtab filename is no explicitly
specified, but for example:

 mnt_table_parse_mtab(tb, "/proc/self/mountinfo");

ignores utab because filename points to regular file. This is mistake,
we wnat to read utab always when we read mount table from kernel.

Reported-by: Martin Pitt <martin.pitt@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-12 13:21:08 +01:00
Karel Zak 0c6d9b6300 Revert "libmount: MNT_OMODE_FORCE usage"
This reverts commit 6f41c5de40.
2015-02-10 11:40:56 +01:00
Fridolin Pokorny 6f41c5de40 libmount: MNT_OMODE_FORCE usage
Hi,

I have found out that libmount does not respect MNT_OMODE_FORCE mode.
I don't see any usage in sources and libmount does not respect this mode
when calling library functions. I'm proposing a patch to fix this.

Have a nice day!
Fridolin Pokorny
2015-02-10 11:18:51 +01:00
Karel Zak 0c8cd4ba7a libmount: fix type pointer usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-03 14:05:05 +01:00
Karel Zak 7396bdd468 libmount: fix possible mem leak in has_utab_entry() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-29 11:03:49 +01:00
Karel Zak 7bc2fd3d23 libmount: fix mem leak in do_mount_by_types() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-29 10:58:55 +01:00
Karel Zak 3df1a79ad5 libmount: add options map to docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-26 12:25:40 +01:00
Karel Zak 2498303575 libmount: revert "read mtab on remount" idea
It's backwardly incompatible nonsense to prefer mtab on remount.

 mount -o remount /foo

has to read mount options from fstab otherwise the remount has no
effect. (The ideal solution would be to read both mtab, then modify
the options according to fstab -- but for now more important is to be
backwardly compatible.)

References: https://bugzilla.redhat.com/show_bug.cgi?id=1182778
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-16 12:24:57 +01:00
Karel Zak 05cdd0bf45 libmount: (docs) add monitor example
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-13 12:13:09 +01:00
Karel Zak 2b6c532e17 docs: update API docs years
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-13 12:03:17 +01:00
Karel Zak 0cf8312703 libmount: cleanup gtk-docs warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-13 11:57:15 +01:00
Sami Kerola 7ee26cbf02 maint: fix shadow declaration
This change fixes all shadow declarations.  The worth while to mention
fix is with libfdisk sun geometry.  It comes from bitops.h cpu_to_be16
macro that further expands from include/bits/byteswap.h that has the
shadowing.

libfdisk/src/sun.c:961:173: warning: declaration of '__v' shadows a previous local [-Wshadow]
libfdisk/src/sun.c:961:69: warning: shadowed declaration is here [-Wshadow]
libfdisk/src/sun.c:961:178: warning: declaration of '__x' shadows a previous local [-Wshadow]
libfdisk/src/sun.c:961:74: warning: shadowed declaration is here [-Wshadow]

That could have caused earlier some unexpected results.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-01-07 10:08:21 +01:00
Karel Zak f43fb23a2f libmount: (monitor) make mnt_monitor_next_changed() usable for epoll version too
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak 8f52496d8e linmount: (monitor) refresh docs, headers and symbols table
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak 3b2c2ba688 libmount: (monitor) use inotify for utab lock file
It's better than monitor utab directly. The utab is updated by
rename(2) and it's really tricky for inotify, because it's necessary
to monitor all /run/mount directory and then it's necessary to verify
that the renamed file is really "utab".

The new concept is without possible false positives and it also
triggers the change when utab update is really done.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak 3c5ed29a93 libmount: (monitor) add kernel mountninfo monitoring
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak 9b4fc141d4 libmount: (monitor) cleanup wait/verify stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak f7ca1a6433 libmount: make public top-level monitor FD only
We need full control on changes evaluation, so it's better to
hide all in our private epoll. This change also significantly
simplify the API.

 mn = mnt_new_monitor();
 mnt_monitor_enable_userapce(mn, TRUE, NULL);
 mnt_monitor_enable_kenrel(mn, TRUE);

 fd = mnt_monitor_get_fd(mn);
 ...
   <use 'fd' in epoll controlled by your application>
 ...
 while (mnt_monitor_next_changed(mn, &filename, NULL) == 0)
 	printf("%s: change detected\n", filename);

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak 36813a2128 libmount: monitor unref function refactoring
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak c6b1e56d26 libmount: cleanup monitor test
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak fc79d3ab44 libmount: split monitor initialization
The patch introduces mnt_monitor_enable_*() functions (now for
userspace only) to make the API easy to use for high-level purpose.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak 01966ce852 libmount: allow unspecified source on remount
kernel does not require mount source (e.g. device name) on remount, it
means that fstab/mtab/mountinfo should be optional in this case.
For example:

 mount -o rw,remount /

has to work on system without mounted /proc.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-12-18 10:47:39 +01:00
Karel Zak 372112e908 libmount: add new libmnt_monitor API
It's usually enough to us [e]poll() to monitor kernel mount table, but
there is no way how to monitor changes in userspace mount options
(e.g. _netdev). The management of these mount options is completely
hidden in libmount and /rub/mount/utab is private libmount file.

This patch introduces new libmnt_mount API to monitor also userspace
mount table.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-12-05 15:30:04 +01:00
Karel Zak e857e9940a build-sys: cleanup in libmount Makemodule
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-26 12:14:18 +01:00
Karel Zak adc9f78cfc build-sys: cleanup library symbol files
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-20 14:01:03 +01:00
Karel Zak bbf0ff70f0 libmount: fix lock test to use real time to sync
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-19 16:50:08 +01:00
Karel Zak cd2876d252 build-sys: move all around clock_gettime() to monotonic.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-19 11:54:47 +01:00
Karel Zak a4830f617e build-sys: use CLOCKGETTIME_LIBS
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-19 11:23:05 +01:00
Karel Zak edda9f8a15 libmount: fix utab entry on remount
mount(8) command does not set ROOT= field to utab entry on remount,
for example:

	mount -oremount,_netdev /mnt

Reported-by: Chris Leech <cleech@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-19 11:10:55 +01:00
Karel Zak 7deae03fb4 libmount: add private mnt_context_get_mtab_for_target()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-19 11:07:40 +01:00
Karel Zak e713e11d4c libmount: reuse allocated fs in parser
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-19 11:07:11 +01:00
Karel Zak a504eaed65 libmount: improve mnt_reset_fs()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-19 11:06:24 +01:00
Karel Zak 700031ade7 misc: use monotonic time rater than gettimeofday
Based on patch Alexander Samilovskih <alexsamilovskih@gmail.com>

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-18 14:35:21 +01:00
Sami Kerola e3c27186e8 libmount: fix memory overflow [AddressSanitizer]
==10918==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffd795b680 at pc 0x0000004447c6 bp 0x7fffd795b3e0 sp 0x7fffd795ab78
WRITE of size 129 at 0x7fffd795b680 thread T0
    #0 0x4447c5 in scanf_common(void*, int, bool, char const*, __va_list_tag*) (/home/src/util-linux/.libs/lt-mount+0x4447c5)
    #1 0x445892 in sscanf (/home/src/util-linux/.libs/lt-mount+0x445892)
    #2 0x7fe78709a3d3 in get_filesystems /home/src/util-linux/libmount/src/utils.c:581:7
    #3 0x7fe78709a1ba in mnt_get_filesystems /home/src/util-linux/libmount/src/utils.c:622:7
    #4 0x7fe7870aa78f in do_mount_by_pattern /home/src/util-linux/libmount/src/context_mount.c:833:7
    #5 0x7fe7870a9534 in mnt_context_do_mount /home/src/util-linux/libmount/src/context_mount.c:951:9
    #6 0x7fe7870aab2b in mnt_context_mount /home/src/util-linux/libmount/src/context_mount.c:1051:8
    #7 0x4ba9f5 in main /home/src/util-linux/sys-utils/mount.c:1107:7
    #8 0x7fe785caa03f in __libc_start_main (/usr/lib/libc.so.6+0x2003f)
    #9 0x4b9f9c in _start (/home/src/util-linux/.libs/lt-mount+0x4b9f9c)

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-18 12:56:05 +01:00
Karel Zak 0bf037402a lib/loopdev: replace custom DBG() with include/debug.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-04 14:08:45 +01:00
Karel Zak 74d70957b4 tests: cleanup libmount debug test
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-03 13:54:40 +01:00
Karel Zak 3533341614 libmount: clean up debug, add help debug mask
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-03 13:13:12 +01:00
Mike Frysinger 72a2a3f5d7 libmount: improve kernel command line parsing
The current command line parser will stop at the first occurrence of an
option, however the kernel does the opposite.  So if you have:
	root=/dev/sda1 root=/dev/sda2
When you look for "root", the kernel will use /dev/sda2, but util-linux
uses /dev/sda1.

Further, if args are passed to custom init programs, the parser will
pick those up as kernel options.  So if you have:
	root=/dev/sda1 -- /foo bar=yes
The kernel will stop at the "--" and pass the rest to userland.  But if
you look for "bar", util-linux will incorrectly return "yes".

Ultimately, there's no way for util-linux to exactly parse the command
line the same way as the kernel -- we don't know exactly which ones the
kernel picks up and which it passes on to userland (either as env vars
or as command line args).  The kernel passes all unrecognized options.
These updates are simple best effort.

URL: https://bugs.gentoo.org/526754
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2014-10-31 10:39:15 +01:00
Karel Zak 819d9a2975 include/debug: fix typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-24 11:19:23 +02:00
Søren Holm 10e1d2e5f7 libmount: provide version as int for better compiletime test
Signed-off-by: Søren Holm <sgh@sgh.dk>
2014-10-14 12:03:54 +02:00
Karel Zak 473c5fb86c libmount: fix mnt_is_readonly() #ifdef
This issue affects util-linux portability to GNU/HURD

Reported-by: Pino Toscano (from Red Hat)
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 13:41:40 +02:00
Søren Holm 41510d26dd libmount: don't return root if path contains // or ending /
If the path fx. is /foo/bar/ the initial stripoff will replace the last slash
with \0 and return a pointer to that exact \0 character. The same thing will
happen if the path contains // somewhere.

Signed-off-by: Søren Holm <sgh@sgh.dk>
2014-10-01 10:01:35 +02:00
Andreas Henriksson 200cdfa8b1 libmount: only include context on linux
This is part of an attempt to make libmount buildable on non-linux.

The parts that need architecture specific porting is under
the context*.c files and the rest of libmount is useful/used
by for example fsck.

Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2014-09-22 12:54:09 +02:00
Andreas Henriksson e624bc558b libmount: only invoke loopcxt on linux
This is part of an attempt to make libmount buildable on non-linux.

The support for /dev/loop* is Linux-specific so just disable
it on non-linux for now.

Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2014-09-22 12:54:07 +02:00
Robert Schiele 4fcb0f3fb8 umount: read mountinfo if --detach-loop given
Don't use the optimization not to read mountinfo from commit
6a52473ecd if --detach-loop was given
since we need the name of the loop device in that case and with the
optimization this is not present and thus the detach operation
obviously fails.

Signed-off-by: Robert Schiele <rschiele@gmail.com>
2014-09-22 12:53:57 +02:00
Karel Zak a3b92242ad libmount: hide details about failed search in fstab/mtab
The current code returns -errno when not found "mount /foo" in fstab
and mtab does not exist (or /etc/mtab points to non-mounted /proc).

This is problem because the return value is too low-level and maybe
misinterpreted by top level code. It's better to always return
MNT_ERR_NOFSTAB when not found in fstab/mtab.

Reported-by: Dylan Cali <calid1984@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-09-16 15:30:03 +02:00
Karel Zak e4ea53de0b libmount: use -t for type.subtype in helpers API
References: https://github.com/karelzak/util-linux/issues/116
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-21 14:58:40 +02:00
Karel Zak 03e4220d29 include/debug: cleanup masks
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-13 14:13:32 +02:00
Ondrej Oprala 14ad2353cc libs/debug: accept human readable names for _DEBUG=
For example
	$ LIBMOUNT_DEBUG=tab,cache findmnt

to debug only TAB and CACHE subsystem.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-13 12:33:47 +02:00
Karel Zak 64a7e20980 libmount: don't use /{proc,ext}/filesystems when more fs types specified
# mkfs.ext4 /dev/sda1
 # mount -t foo,bar /dev/sda1 /mnt

successfully mount the device, this is unexpected as extN is no
between wanted (by -t specified) filesystems.

Summary about -t:

 * "mount -t foo"        mount(2) with "foo" type

 * "mount -t foo,bar"    try mount(2) with "foo" or "bar"

 * "mount -t foo,auto"   try mount(2) with "foo" or ask libblkid for
                         the type

 * "mount -t nofoo,bar"  try types from /{etc,proc}/filesystems, but
                         exclude "foo" and "bar"

Note that more filesystems may be specified in fstab (as comma
delimited list). The stuff from fstab is always interpreted as list
and never as a pattern ("no" prefix makes no sense in fstab).

Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-25 12:28:34 +02:00
Karel Zak 98d391c0b6 libmount: add missing assert()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-17 14:31:05 +02:00
Benno Schulenberg 0dc5e9ba03 libmount: adjust the ordering of a #define and tweak some comments
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-07-14 16:21:36 +02:00
Sami Kerola 0e65dcde88 textual: fix some typos
Found with misspell-check version 2.0d.

Reference: https://github.com/lyda/misspell-check
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-13 17:21:02 +01:00
Karel Zak 8642cd7b0f libmount: always use mnt_resolve_target() in mnt_fs_match_target()
The requested path is also target mountpoint, so let's optimize
realpath() usage as well.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-01 10:34:09 +02:00
Eric Rannaud 0382ba32ed libmount: mnt_resolve_target: tiptoe around active mount points
Current code in mnt_fs_match_target() and mnt_table_find_target()
already does not canonicalize active mount points (when read from
mountinfo), because they are already canonicalized by the kernel.
Calling realpath(fs->target) on a mount point can hang -- e.g. if the
NFS server is unreachable.

This patch optionally extends this strategy to the general case, that is
when @fs does not directly come from the kernel through mountinfo (for
instance, it may have been parsed from /etc/fstab).

Given @mtab parsed from mountinfo, and if mnt_cache_set_targets(cache,
mtab) is used, then mnt_fs_match_target() and mnt_table_find_target()
check whether @fs->target is a known mount point in the cached
mountinfo, before attempting to canonicalize @fs->target, no matter
where @fs itself comes from. If found in the cached mountinfo,
@fs->target is not canonicalized.

[kzak@redhat.com: - don't allocate libmnt_iter,
                  - add docs for mnt_cache_set_targets(),
                  - fallback to mnt_resolve_path() if no cache->mtab specified,
                  - use streq_except_trailing_slash() to compare paths]

Signed-off-by: Eric Rannaud <e@nanocritical.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-01 10:03:40 +02:00
Eric Rannaud 45e8cdba91 libmount: mnt_resolve_path: don't canonicalize fs->target for swap
This is how mnt_table_find_target() does it. It makes sense because
@fs->target is "none" for swap and is never a sensible match for a
user-specified target.

Signed-off-by: Eric Rannaud <e@nanocritical.com>
2014-07-01 09:32:12 +02:00
Eric Rannaud ab131f00a2 libmount: mnt_resolve_path: use strcmp() only if both are canonical
Signed-off-by: Eric Rannaud <e@nanocritical.com>
2014-07-01 09:32:09 +02:00
Karel Zak b1f03df798 libmount: special treatment for auto in fstype pattern
Let's support

  mount -t ext2,auto /dev/sde /media/stick

Reported-by: Andreas Henriksson <andreas@fatal.se>
Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=506695
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-23 12:42:33 +02:00
Karel Zak 150e696dac libmount: don't touch mtab when mount -n specified
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1109367
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-17 15:38:14 +02:00
Thomas Petazzoni 6e90f2b479 Only move shared libraries to /lib if they exists
In several Makemodule.am, there is a install-exec-hook-<library>
target whose role is to move the shared library from /usr/lib to /lib,
while keeping a symbolic link /usr/lib/libuuid.so ->
../../lib/<library>.so.<version>.

However, when util-linux is built with --enable-static
--disable-shared (as is needed on noMMU platforms that don't support
shared libraries), no <library>.so is built, but the
install-exec-hook-libuuid creates an invalid /usr/lib/<library>.so
symbolic link, pointing to ../../lib (yes, the directory). This causes
troubles later one when other libraries/programs are compiled with
-l<library>, as gcc thinks a shared library is available because
there's a file named /usr/lib/<library>.so.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2014-06-16 14:53:09 +02:00
Karel Zak d4eaabc86a lib/fileutils: add stripoff_last_component() from libmount
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-09 11:54:32 +02:00
Karel Zak 934530c7e8 lib/fileutils: add mkdir_p() from libmount 2014-06-09 10:59:18 +02:00
Karel Zak ee312c654b docs: fix "behaviour" vs. "behavior"
Sometimes we use "behaviour" and "behavior" in the same text, let's
use "behavior" only everywhere.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1011068
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-06 09:49:35 +02:00
Ruediger Meier 15b2606c4f tests: fix python tests for dist and out-of-tree builds
- add python helper scripts to the dist
- helper scripts are always in srcdir
- python libs are in builddir
- abort tests if helpers are missing

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-06-04 10:14:24 +02:00
Ruediger Meier 15cb27895d build-sys: use automake's PYTHON primary for __init__.py
Actually the initial reason for this commit was to remove execute
permission from installed __init__.py.

Now after discovering automake's _PYTHON suffix we slightly cleanup
Makemodule.am and we will install byte compiled .pyc and .pyo files.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-06-03 13:12:43 +02:00
Karel Zak 7a1c36ab38 docs: rename libs xml/version.xml to xml/version-utils.xml
It seems that gtk-docs stuff is confused when we use version.xml
(package version) and xml/version.xml (library version functions).

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-03 12:37:33 +02:00
Karel Zak 1024dd6acb build-sys: fix .h.in usage in libblkid and libmount
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-07 13:26:56 +02:00
Karel Zak b6bdccc710 mount: apply "nofail" to MNT_ERR_NOSOURCE libmount error
fstab:
     UUID=nonexist /mnt/nonexist1 ext4 nofail 0 1

 # mount -av
 mount: can't find UUID=nonexist

.. this is bug of course.

Reported-by: Patrick McLean <chutzpah@gentoo.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-07 12:09:11 +02:00
Ondrej Oprala cbe9202781 libmount: silence some docs warnings
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2014-03-28 11:25:40 +01:00
Karel Zak b5ce1c5642 Merge branch 'master' of https://github.com/rudimeier/util-linux
* 'master' of https://github.com/rudimeier/util-linux:
  tests: try hard to create swaplabel's test image
  build-sys: libmount/python/__init__.py is always a dist file
  tests: return error if failures file not usable
  tests: write tests/failures to build- instead of srcdir
2014-03-21 15:02:29 +01:00
Karel Zak 83a783320b libmount: use new debug functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-21 12:34:39 +01:00
Ruediger Meier a400c2ad0e build-sys: libmount/python/__init__.py is always a dist file
"make dist" and "make distcheck" should work after a bare
./configure to give us a full featured tar ball.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-03-13 17:48:09 +01:00
Ondrej Oprala 274228fecc clean up redundant macros and defines
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2014-03-13 11:53:31 +01:00
Ondrej Oprala d736582199 libmount: further debug.h integration
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2014-03-13 11:03:23 +01:00
Ondrej Oprala cedd8e5f62 libmount: use macros from include/debug.h
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2014-03-12 14:37:58 +01:00
Sami Kerola cc93d115de build-sys: sort gitignore files
Use 'LC_ALL=C sort -fu' order for all lists.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-03-12 12:06:37 +01:00
Karel Zak df019e9be7 libmount: add statfs_magic.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-06 13:09:16 +01:00
Bernhard Voelker 260412b19f libmount: define BTRFS_TEST_MAGIC if missing
* libmount/src/utils.c (BTRFS_TEST_MAGIC): Conditionally add define
which is used since commit v2.24-243-g6a52473.

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
2014-03-05 12:14:54 +01:00
Karel Zak dbf7043ea1 build-sys: don't connect _DEPENDENCIES and _LIBADD
The _DEPENDENCIES has to be used for dependencies on another in-tree
files, but _LIBADD is to specify additional libs (including external
libs).

Reported-by: oleid <notifications@github.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-05 10:20:10 +01:00
Karel Zak 870c616d60 libmount: cgroup magic already defined
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-03 12:10:08 +01:00
Karel Zak 6a52473ecd umount: don't use mountinfo if possible
The umount(8) always parses /proc/self/mountinfo to get fstype and to
merge kernel mount options with userspace mount options from
/run/mount/utab. This behavior is overkill in many cases and it's
pretty expensive as kernel has to always compose *whole* mountinfo.
This performance disadvantage is visible for crazy use-cases with huge
number of mountpoints and frequently called umount(8).

It seems that we can bypass /proc/self/mountinfo by statfs() to get
filesystem type (statfs.f_type magic) and analyze /run/mount/utab
before we parse mountinfo.

This optimization is not used when:

 * umount(8) executed by non-root (as user= in utab is expected)
 * umount --lazy / --force (target is probably unreachable NFS, then
   use statfs() is pretty bad idea)
 * target is not a directory (e.g. umount /dev/sda1)
 * there is (deprecated) writeable mtab

Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-03 10:36:15 +01:00
Karel Zak 6c373810f5 libmount: FS id and parent ID could be zero
It seems that linux 3.14 is able to produce things like:

  19 0 8:3 / / rw,relatime - ext4 /dev/sda3 rw,data=ordered
     ^

Reported-by: Mantas Mikulėnas <grawity@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-02-20 16:59:11 +01:00
Thomas Bächler 2e358a901f libmount: initialize *root to NULL in mnt_table_get_root_fs
mnt_table_get_root_fs only works when *root is set to NULL. This
is not only undocumented, but also unintuitive. Fix it by initializing
*root inside mnt_table_get_root_fs.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-02-17 13:36:47 +01:00
Karel Zak 5980048edd libmount: make the mountinfo parser more robust
... sorry, the previous change to the parser was too stupid.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-02-17 13:17:47 +01:00
Karel Zak c6f462ffac libmount: accept (deleted) path suffix in mountinfo file
Addresses: debian bug #711183
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-02-17 13:12:23 +01:00
Karel Zak a5bd793996 include/c.h: prefer nanosleep() over usleep()
Let's use nanosleep() although if usleep() exists. The nanosleep
function does no interact with signals and other timers.

The patch introduces xusleep() as replacement to libc (or our fallback)
usleep(). Yes, we don't want to use struct timespec + nanosleep()
everywhere in code as nano-time resolution is useless for us.

The patch also enlarges delays in some busy wait loops. It seems
enough to try read/write 4x per second.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-24 13:04:14 +01:00
Karel Zak ea97feab8d libmount: fix scanf format string [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-14 18:00:14 +01:00
Karel Zak ecdec6d866 pylibmount: import directly from pylibmount in tests
This change does not have any impact to in a standard way installed
libmount impact. It's simplification for in-tree tests.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-14 17:40:47 +01:00
Karel Zak 34330d2bea pylibmount: remove unncessary subdirectory
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-14 17:40:47 +01:00
Karel Zak 51fffa7be0 libmount: add mnt_table_uniq_fs()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-12-11 16:59:57 +01:00
Karel Zak 84ceaf7a19 libmount: add efivarfs to the list of pseudo filesystems
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-12-10 14:05:22 +01:00
Dave Reisner c8e5e6e732 pylibmount: correctly import from pylibmount.so
Without this, python is unable to find the module:

$ python -c 'import libmount'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.3/site-packages/libmount/__init__.py", line 1, in <module>
    from pylibmount import *
ImportError: No module named 'pylibmount'

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2013-12-02 10:59:31 +01:00
Karel Zak a53cc4e0cb libmount: add mnt_tag_is_valid()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-19 17:41:28 +01:00
Karel Zak 50bdacb823 libmount: cleanup fix_optstr() regards to selinux and smack
It's better (more robust) to make the code based on datetypes
rather than on if(strcmp(...)).

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-12 15:49:33 +01:00
Karel Zak 74aad572e0 libmount: fix typo in smack path
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-12 15:17:28 +01:00
Karel Zak b8095d25ba libmount: remove smackfs* option when SMACK not enabled
If there is no /sys/fs/smackfs then libmount removes smackfs*= mount
options when compiled --with-smack.

Note that we do the same for SELinux.

References: http://www.mail-archive.com/systemd-devel@lists.freedesktop.org/msg13740.html
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-12 15:07:12 +01:00
Ondrej Oprala 675de3f5c1 strutils: add skip_space() function
[kzak@redhat.com: - add also skip_blank(),
                  - remove duplicate implementation from libmount]

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-08 14:14:34 +01:00
Karel Zak 7e0c06194f libmount: update utab after successful extern helper mount
This patch allows to maintain private utab libmount file also for
external mount/umount helpers that are not linked with libmount.

The libmount check if utab has been updated after successful extern
helper execution (status=0). If not then the file is updated.

This patch affects only 'user' fstab mount option. So, for example
with suid mount.cifs you can use:

 //server/foo    /mnt  cifs   username=foo,noauto,user

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-04 14:24:41 +01:00
Karel Zak 889fc9fe3a libmount: allow to use -s (sloppy) for all external helpers
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-04 10:50:48 +01:00
Karel Zak d4f0f1ccad libmount: fix mnt_context_is_child() comment
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-11 10:51:59 +02:00
Namhyung Kim 94c7fa6ee7 libmount: Fix typo in comment
s/MNT_OMASK_/MNT_OMODE_/

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
2013-10-11 10:45:43 +02:00
Sami Kerola 5d324c6b94 various: fix mixing declarations and code compiler warnings [smatch]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-10-08 15:47:59 +02:00
Benno Schulenberg e9c58f6d55 COPYING: fix grammar of referring phrase, and indicate location better
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-10-08 15:38:39 +02:00
Karel Zak c7616e4c6c libmount: remove dead code [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-01 17:23:26 +02:00
Karel Zak 1d4d4b42e6 pylibmount: check for mnt_fs_get_tag() return value [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-01 17:18:54 +02:00
Karel Zak 21ca031559 pylibmount: make tab parsers more robust [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-01 17:15:08 +02:00
Karel Zak a84ec176ec libmount: make mnt_table_replace_file() more robust [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-01 16:56:26 +02:00
Namhyung Kim 1dbaf5cc72 libmount: Save errno if mkostemp() failed
After mkostemp() failed, umask() and free() might alter the errno
to another value.  Not sure those calls really changes the errno
or not.  But let's be more conservative.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
2013-09-30 13:41:12 +02:00
Karel Zak 6073251ca8 build-sys: one install dir for all pylibmount stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-27 14:23:38 +02:00