summaryrefslogtreecommitdiffstats
path: root/libmount
Commit message (Collapse)AuthorAgeFilesLines
* Revert "build-sys: Order pylibmount after usrlib on install"Filipe Brandenburger2016-02-051-12/+2Star
| | | | This reverts commit e61f406913fb9356aed013da7ece34e73929cff6.
* docs: fix typos found by codespellRuediger Meier2016-02-031-1/+1
| | | | | | Using "codespell" from https://github.com/lucasdemarchi/codespell Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* libmount: move btrfs subvol code refactoringKarel Zak2016-02-011-99/+115
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix target resolving for btrfs stuffKarel Zak2016-02-011-9/+14
| | | | | | and make the code more verbose. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: code re-indentationStanislav Brabec2016-02-011-43/+44
| | | | | | | | | | 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>
* libmount: run btrfs subvol checks for "subvolid" optionStanislav Brabec2016-02-011-1/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* libmount: run btrfs subvol checks for "auto" fs typeStanislav Brabec2016-02-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* libmount: add 'force-mountinfo' to features list, improve debugKarel Zak2016-02-012-7/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: Order pylibmount after usrlib on installFilipe Brandenburger2016-01-261-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* libmount: cleanup btrfs.c headerKarel Zak2016-01-261-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: consolidate btrfs stuff, make it more portableKarel Zak2016-01-265-133/+92Star
| | | | | | | | | - 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>
* libmount: handle btrfs default subvolume mountStanislav Brabec2016-01-269-4/+331
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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,libmount: Do not use void* in calculations [cppcheck]Boris Egorov2016-01-191-2/+2
| | | | | | | | [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.
* login, mount: fix __SC_GETPW_R_SIZE_MAX usageKarel Zak2015-12-151-19/+6Star
| | | | | | | | | | 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>
* libmount: add comment, remove TODO itemKarel Zak2015-12-101-0/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: use fstatat(AT_NO_AUTOMOUNT) for mountpointsKarel Zak2015-12-094-6/+16
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add cgroup2 pseudo FSKarel Zak2015-12-081-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix is-mounted check for btrfsKarel Zak2015-12-021-12/+26
| | | | | | | | | | | 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>
* libmount: follow docs with parse-error callback return codeKarel Zak2015-10-151-1/+1
| | | | | | The docs says that recoverable errors have rc > 0. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix uid= and gid= translationKarel Zak2015-10-121-11/+14
| | | | | | | | | | | | | | | | | | | | | | | 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>
* libmount: (monitor) remove unnecessary epoll EPOLLPRIKarel Zak2015-09-111-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: (monitor) don't check for regular mtabKarel Zak2015-09-111-5/+1Star
| | | | | | | | | | | | 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>
* libmount: typo fixesKir Kolyshkin2015-09-032-2/+2
| | | | | | I was reading the code and found these mountinfo typos. Signed-off-by: Kir Kolyshkin <kir@openvz.org>
* libmount: fix compiler warning [-Wdiscarded-qualifiers]Karel Zak2015-08-311-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: handle arbitrary line length for mountsKarel Zak2015-08-271-32/+49
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* misc: fix shadow declarationsSami Kerola2015-08-241-3/+3
| | | | | | | | | | | | | | | | | | | | | | 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>
* libmount: (monitor) fix docsKarel Zak2015-08-191-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add support for "bind,ro"Karel Zak2015-08-171-1/+47
| | | | | | | | | | | | | | 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>
* libmount: fix typo in mnt_optstr_prepend_option()Karel Zak2015-08-051-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: variable dereferenced before check [smatch scan]Karel Zak2015-08-051-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: add --disable-assertKarel Zak2015-08-042-11/+2Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: cleanup assert() usageKarel Zak2015-08-046-54/+6Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: make mnt_get_filesystems() more robust [clang analyze]Karel Zak2015-07-301-2/+2
| | | | | | | | | 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>
* libmount: sort pseudo filesystems by LC_COLLATE=CKarel Zak2015-07-291-1/+1
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/212 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: improve monitor to be usable for non-root usersKarel Zak2015-06-191-82/+142
| | | | | | | | | | | | | | 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>
* libmount: (docs) fix wordingRonny Chevalier2015-06-031-1/+1
| | | | Signed-off-by: Ronny Chevalier <chevalier.ronny@gmail.com>
* libmount: (docs) fix typoRonny Chevalier2015-06-031-1/+1
| | | | Signed-off-by: Ronny Chevalier <chevalier.ronny@gmail.com>
* libmount: do not call umount helper on --fakeKarel Zak2015-06-032-3/+9
| | | | | | | | | 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>
* libmount: fix mnt_monitor_event_cleanup()Karel Zak2015-06-011-13/+26
| | | | | | | 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>
* docs: fix gtk-docs related warningsKarel Zak2015-05-282-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add note about flock() to docsKarel Zak2015-04-021-0/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add support for MS_LAZYTIMEKarel Zak2015-03-302-0/+8
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: mark overlay as pseudo-FSKarel Zak2015-03-111-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add mnt_table_get_fs_root() to header fileKarel Zak2015-03-111-0/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: cleanup fs root detection codeKarel Zak2015-03-103-45/+26Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* findmnt: don't rely on st_dev for --targetKarel Zak2015-03-101-0/+4
| | | | | | | | | | | | 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>
* build-sys: cleanup realtime lib usageKarel Zak2015-03-061-2/+2
| | | | | | | | * 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>
* libmount: remove assert(arg) from public functionsKarel Zak2015-02-1610-238/+28Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: improve remount logicKarel Zak2015-02-162-3/+5
| | | | | | | * fix fs type detection for remount * parse mtab only for remount and umount Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add --enable-libmount-force-mountinfoKarel Zak2015-02-162-1/+8
| | | | | | | | | | | | | | | | | | 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>