summaryrefslogtreecommitdiffstats
path: root/libmount/src
Commit message (Collapse)AuthorAgeFilesLines
...
* libmount: accept another flags on MS_REMOUNT|MS_BINDKarel Zak2018-05-282-14/+11Star
| | | | | | | | | | | | | | | | | | | | | | The current libmount MS_REMOUNT|MS_BIND support is restricted to MS_RDONLY (read-only bind mount). This is too restrictive as Linux kernel supports bind-remount for arbitrary VFS flags. After this update you can use # mount /dev/sdc1 /mnt/A # mount --bind -onosuid,noexec /mnt/A /mnt/B # findmnt /dev/sdc1 -oTARGET,SOURCE,FS-OPTIONS,VFS-OPTIONS TARGET SOURCE FS-OPTIONS VFS-OPTIONS /mnt/A /dev/sdc1 rw,stripe=512,data=ordered rw,relatime /mnt/B /dev/sdc1 rw,stripe=512,data=ordered rw,nosuid,noexec,relatime The "mount --bind" is composed from two syscalls of course (1st is bind, 2nd is bind,remount,nosuid,noexec). Addresses: https://github.com/karelzak/util-linux/issues/637 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix compiler warning [-Wunused-parameter]Karel Zak2018-05-031-4/+2Star
| | | | | Reported-by: L A Walsh <lkml@tlinx.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: improve docs about mnt_context_mount() return codesKarel Zak2018-04-261-3/+31
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix mnt_table_is_fs_mounted() for NFS bind mounts.NeilBrown2018-04-181-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | When you bind-mount a subdirectory of a local filesystem, the path to that subdirectory appears as the fourth field in mountinfo. For nfs mounts, the fourth field is always "/", and the subdirectory part is appended to the "special" (aka "device") field. This is consistent with historical NFS usage which always includes a path in the fs_spec field. libmount needs to know about this when "mount -a" checks to see if a filesystem is already mounted. Without this fix, fstab lines like: server::/path /dir nfs defaults 0 0 /dir/subdir /mnt/test none bind 0 0 result in a new mount at /mnt/test every time "mount -a" is run. [kzak@redhat.com: - use strappend() rather than asprintf()] Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* bugfix: fix possible segfault during umount -aRichard Fuchs2018-04-171-1/+2
| | | | | | | mnt_context_get_mtab() doesn't set its return **tb argument on error, and so in mnt_context_next_umount() mtab will remain uninitialized on error, later resulting in cxt->mtab containing garbage, possibly resulting in segfault on exit.
* libmount: include sys/mount.h only if necessaryKarel Zak2018-03-221-1/+8
| | | | | Addresses: https://github.com/systemd/systemd/issues/8507 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix example in docsKarel Zak2018-03-201-1/+1
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/599 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: deallocate on /proc/swaps parse errorKarel Zak2018-03-201-5/+6
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/596 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: make sure we deallocate on parse errorKarel Zak2018-03-201-2/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: make libmount.h more robustKarel Zak2018-03-201-0/+1
| | | | | | | | | | Let's include sys/mount.h to be sure that our local libmount fallbacks are not used by default to avoid possible conflicts with later included sys/mount.h. Addresses: https://github.com/systemd/systemd/pull/8452 Reported-by: Lennart Poettering <lennart@poettering.net> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix fs pattern usage in mount --allKarel Zak2018-03-061-0/+12
| | | | | | | | | | | | | | | | | The command "mount -a -t <pattern>" uses the -t as pattern to filter fstab entries. And "mount -t <type>" is used to specify FS type. Unfortunately libmount does not care about this difference when it calls standard mount functionality. The original pattern is still in the library control struct and mnt_do_mount() tries to use it as FS type. This patch is just bugfix. Maybe the long term solution would be to differentiate between the pattern and type in the library API. Now the library follows mount(8) command line and it's little bit messy. Reported-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: fix typos using codespellRuediger Meier2018-02-162-6/+6
| | | | | | Some more funny typos, please review carefully. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* libmount: fix debug messageKarel Zak2018-02-011-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: remove %p from debug messagesKarel Zak2018-02-013-12/+6Star
| | | | | | From libs where suid program may be executed by non-root user. Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: remove redundant EXTRA_DIST filesRuediger Meier2018-01-221-2/+1Star
| | | | | | | The sources of AC_CONFIG_FILES (*.in) are automatically distributed. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* build-sys: avoid using prog_DEPENDENCIESRuediger Meier2018-01-221-3/+1Star
| | | | | | | Use EXTRA_prog_DEPENDENCIES to have the benefit of automake's automatic prog_DEPENDENCIES. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* build-sys: remove unneeded dependencies on bla.h.inRuediger Meier2018-01-221-2/+1Star
| | | | | | | | | | We have already automakes's automatic dependencies like bla.h.in -> bla.h -> foo.o -> bar.la An explicit direct dependency bla.h.in -> bar.la is redundant and useless anyways. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* build-sys: automake is able to find headers in builddir ...Ruediger Meier2018-01-221-1/+1
| | | | Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* build-sys: remove generated headers from dist tar ballRuediger Meier2018-01-221-4/+2Star
| | | | | | | | | | | | | Headers should only be listed in either *_HEADERS or *_SOURCES, especially when we want nodist_*_HEADERS. Since all the generated headers are made by configure we don't even need to use BUILT_SOURCES or other tricks. Also see automake docs 9.4.1 Built Sources Example: case "Build bindir.h from configure" Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()Karel Zak2018-01-171-1/+1
| | | | | | | Let's make it possible to use debug.h without environment variables. Suggested-by: J William Piggott <elseifthen@gmx.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* include/debug: don't print pointer address for SUID programsKarel Zak2018-01-121-0/+3
| | | | | | | | | | | | | | | | * introduce new flag __UL_DEBUG_FL_NOADDR to suppress pointer address printing * use __UL_DEBUG_FL_NOADDR when SUID * move ul_debugobj() to debugobj.h, and require UL_DEBUG_CURRENT_MASK to provide access to the current mask from ul_debugobj(). It's better than modify all ul_debugobj() calls and use the global mask as argument. * remove never used UL_DEBUG_DEFINE_FLAG Reported-by: halfdog <me@halfdog.net> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix mnt_table_is_fs_mounted() for rbindKarel Zak2018-01-031-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There is no difference between "bind" and "rbind" if we want to FS root to search for the FS in mountinfo file. fstab: /dev/sdc1 /mnt/foo xfs defaults 0 0 /mnt/foo /mnt/test none rw,rbind 0 0 use -a more than once: mount -a mount -a /proc/mounts (the current result): /dev/sdc1 /mnt/foo xfs rw,relatime,attr2,inode64,noquota 0 0 /dev/sdc1 /mnt/test xfs rw,relatime,attr2,inode64,noquota 0 0 /dev/sdc1 /mnt/test xfs rw,relatime,attr2,inode64,noquota 0 0 /dev/sdc1 /mnt/foo xfs rw,relatime,attr2,inode64,noquota 0 0 expected (fixed version) result: /dev/sdc1 /mnt/foo xfs rw,relatime,attr2,inode64,noquota 0 0 /dev/sdc1 /mnt/test xfs rw,relatime,attr2,inode64,noquota 0 0 Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1528959 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add nsfs between pseudo filesystemsKarel Zak2017-11-211-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: minimize utimensat() write test usageKarel Zak2017-11-162-9/+21
| | | | | | | | | | | | | | | utimensat() is pretty expensive when mounting parallel filesystems from the same source. It's possible to ignore all this if mtab is not writable. Note that this change is irrelevant for default util-linux builds where all around mtab is already disabled since v2.30 (commit 89958178f6d6ebe0944d423feaea66be521fff43). This change is relevant only for users who still use --enable-libmount-support-mtab. Reported-by: Douglas Jacobsen <dmjacobsen@lbl.gov> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix access() utab write testKarel Zak2017-11-084-20/+42
| | | | | | | | | | | | | | | | | The commit c08396c7691e1e6a04b6b45892e7e4612ceed8d7 replaces open(O_CREATE) with ecaccess(). Unfortunately, another code depends on the original behavior. * let's make utab when really necessary rather than in the try_write() test * __mnt_new_table_from_file() returns NULL if tab-file does not exists. This is incorrect for tab_update.c stuff. We need empty table in this case. * we can check /run/mount/ directory for write access if eaccess(filename) return ENOENT (because file does not exist) Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: Allow MNT_FORCE and MNT_DETACH at umountJoshua Watt2017-11-081-1/+1
| | | | | | | | | MNT_FORCE and MNT_DETACH are orthogonal in the Linux kernel, so both may be specified without any problems. Even if there were a problem with this combination, it should be up to the kernel to take the correct action or report an error. Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
* libmount: check waitpid() return codeKarel Zak2017-11-062-10/+22
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: Use waitpid() when waiting for mount helper child processVratislav Podzimek2017-11-062-4/+8
| | | | | | | | | | | | | Using wait() in a library may be problematic as it may reap some totally unrelated child process instead of the just forked one. That can result in the library call doing weird things and returning bad return values, but also in a breakage of an arbitrary other thing in the program using the library. [[kzak@redhat.com: - use waitpid() for umount too - keep the current codding style] Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: use eacess() rather than open() to check mtab/utabKarel Zak2017-10-201-6/+13
| | | | | | | | | The open() syscall is probably the most strong way how to check write accessibility in all situations, but it's overkill and on some paranoid systems with enabled audit/selinux. It fills logs with "Permission denied" entries. Let's use eaccess() if available. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: make sure we call stat() propely [coverity scan]Karel Zak2017-10-111-4/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add human compatible message for EBADMSG errnoKarel Zak2017-10-021-0/+8
| | | | | | | | | | | mount: /media/sdb5: mount(2) system call failed: Bad message. is really ugly for end users. It seems XFS, extN (etc) use EBADMSG for bad checksums. For network or pseudo filesystems continue to use "Bad message" error... Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1496764 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: export locking errors as MNT_EX_FILEIOKarel Zak2017-09-154-10/+37
| | | | | | | | | | | | The mount man page assumes locking errors mapped to MNT_EX_FILEIO (16) return code. Unfortunately, this is internally not exported as a special error code, so it's returned as a generic (errno based) stuff. This patch fixes this issue. Note that we still use locking for example for utab or when enabled /etc/mtab (disabled by default). Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: don't use non-existing UUID_LIBSRuediger Meier2017-07-181-1/+1
| | | | | | | We've added UUID_LIBS in f77a4d1087 but I don't see what it was good for. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* libmount: make mnt_context_is_fs_mounted work for /procIvan Delalande2017-07-181-2/+12
| | | | | | | | | | | | Assume that /proc is not mounted instead of returning an error when we are unable to open the mounts and mountinfo files in /proc. Also set cxt->mtab back to NULL so that it gets properly parsed when we check if the next filesystem is mounted. The goal is to have mount -a work when /proc is not mounted, typically with /proc on the first line of fstab. Signed-off-by: Ivan Delalande <colona@arista.com>
* libmount: use _exit() in <type> handlersKarel Zak2017-06-292-7/+7
| | | | | | | The originally used exit() is bad idea for the shared library. Reported-by: Ruediger Meier <sweet_f_a@gmx.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: ignore "bind" from fstab on command line "remount"Karel Zak2017-06-201-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current code always apply all flags from /etc/fstab on remount. Unfortunately remount+bind has special semantic and it's impossible from command line to avoid interaction with the "bind" from fstab. Example, fstab: /dev/sda1 /bar ext4 defaults 0 1 /bar /foo none bind 0 0 Command line: # mount /foo -o remount,rw produces: mount(... MS_REMOUNT|MS_BIND ) syscall This changes the per-mountpoint (VFS) ro flag to rw, but doesn't change the filesystem itself. This patch forces libmount to ignore "bind" from fstab when "-o remount" specified on command line. If you need remount+bind semantic you have to specify the "bind" flag on command line. This allow to differentiate between # mount /foo -o remount,bind,rw --> mount(MS_REMOUNT|MS_BIND) and # mount /foo -o remount,rw --> mount(MS_REMOUNT) Suggested-by: NeilBrown <neilb@suse.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix warning "set but not used"Ruediger Meier2017-06-151-4/+2Star
| | | | Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: remove stray semicolonsSami Kerola2017-06-143-4/+4
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: fix reassigned values before old ones has been used [cppcheck]Sami Kerola2017-06-147-10/+10
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libmount: btrfs, remove unused setter functionsRuediger Meier2017-06-141-4/+0Star
| | | | | | | We have never used them since introduced in 2cd28fc8. clang compiler warned about it. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* libmount: (umount) use mount table filter on -c onlyKarel Zak2017-06-071-2/+9
| | | | | | | 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>
* libmount: use mount table filter on --no-canonicalizeKarel Zak2017-06-072-14/+19
| | | | | | | 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>
* umount: never 'stat' the path when "-c" is given.NeilBrown2017-06-061-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* build-sys: fix library order when linkingRuediger Meier2017-06-011-1/+1
| | | | | | | | | | 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>
* libmount: (docs) add missing 'since' tagsKarel Zak2017-05-232-0/+10
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: don't pass -1 to close() [coverity scan]Karel Zak2017-05-171-4/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix memory leak [coverity scan]Karel Zak2017-05-171-1/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* tests: (libmount) parse version from command lineKarel Zak2017-05-171-0/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: (docs) remove unwanted tagKarel Zak2017-04-281-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add read-only warningKarel Zak2017-04-282-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>