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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
- 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>
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>
[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.
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
* 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>
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>
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>
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
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>
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>
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>
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>
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>
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>
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>
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>
==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>
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>
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>
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>
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>
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>
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>
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>
# 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>
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>
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>
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>
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>
- 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>
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>
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>
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>
* '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
"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>
* 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>
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>
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>
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>
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>
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>
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>
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>
[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>
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>
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>