summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2015-12-09 10:26:16 +0100
committerKarel Zak2015-12-09 10:26:16 +0100
commit6589a1632b313db1304b673a6ce41a48f203eb98 (patch)
treebf8398e1a37e228359235121a9901a49b4e835fe
parentlibmount: add cgroup2 pseudo FS (diff)
downloadkernel-qcow2-util-linux-6589a1632b313db1304b673a6ce41a48f203eb98.tar.gz
kernel-qcow2-util-linux-6589a1632b313db1304b673a6ce41a48f203eb98.tar.xz
kernel-qcow2-util-linux-6589a1632b313db1304b673a6ce41a48f203eb98.zip
libmount: use fstatat(AT_NO_AUTOMOUNT) for mountpoints
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--Documentation/TODO4
-rw-r--r--libmount/src/context.c4
-rw-r--r--libmount/src/context_umount.c4
-rw-r--r--libmount/src/mountP.h1
-rw-r--r--libmount/src/utils.c13
5 files changed, 20 insertions, 6 deletions
diff --git a/Documentation/TODO b/Documentation/TODO
index 22fa0e06f..6b4ee3020 100644
--- a/Documentation/TODO
+++ b/Documentation/TODO
@@ -1,6 +1,10 @@
Note that items with (!) have high priority.
+canonicalize
+------------
+ - reimplement realpath(3) (for lib/canonicalize()) to use fstatat(AT_NO_AUTOMOUNT)
+
lsblk
-----
- currently it does not show mountpoint for all devices in btrfs RAID. It's because
diff --git a/libmount/src/context.c b/libmount/src/context.c
index 5ab0b794e..7b965a07f 100644
--- a/libmount/src/context.c
+++ b/libmount/src/context.c
@@ -1069,7 +1069,7 @@ int mnt_context_get_mtab_for_target(struct libmnt_context *cxt,
char *cn_tgt = NULL;
int rc;
- if (stat(tgt, &st) == 0 && S_ISDIR(st.st_mode)) {
+ if (mnt_stat_mountpoint(tgt, &st) == 0 && S_ISDIR(st.st_mode)) {
cache = mnt_context_get_cache(cxt);
cn_tgt = mnt_resolve_path(tgt, cache);
if (cn_tgt)
@@ -1540,7 +1540,7 @@ static int mkdir_target(const char *tgt, struct libmnt_fs *fs)
if (mnt_optstr_get_option(fs->user_optstr, "x-mount.mkdir", &mstr, &mstr_sz) != 0)
return 0;
- if (stat(tgt, &st) == 0)
+ if (mnt_stat_mountpoint(tgt, &st) == 0)
return 0;
if (mstr && mstr_sz) {
diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c
index c4e9ebbee..b67f48b91 100644
--- a/libmount/src/context_umount.c
+++ b/libmount/src/context_umount.c
@@ -129,7 +129,7 @@ try_loopdev:
*/
struct stat st;
- if (stat(tgt, &st) == 0 && S_ISREG(st.st_mode)) {
+ if (mnt_stat_mountpoint(tgt, &st) == 0 && S_ISREG(st.st_mode)) {
int count;
struct libmnt_cache *cache = mnt_context_get_cache(cxt);
const char *bf = cache ? mnt_resolve_path(tgt, cache) : tgt;
@@ -242,7 +242,7 @@ static int lookup_umount_fs(struct libmnt_context *cxt)
&& !mnt_context_is_force(cxt)
&& !mnt_context_is_lazy(cxt)
&& !mnt_context_is_loopdel(cxt)
- && stat(tgt, &st) == 0 && S_ISDIR(st.st_mode)
+ && mnt_stat_mountpoint(tgt, &st) == 0 && S_ISDIR(st.st_mode)
&& !has_utab_entry(cxt, tgt)) {
const char *type = mnt_fs_get_fstype(cxt->fs);
diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h
index 660e0ad08..25418a2e4 100644
--- a/libmount/src/mountP.h
+++ b/libmount/src/mountP.h
@@ -99,6 +99,7 @@ extern int mnt_get_filesystems(char ***filesystems, const char *pattern);
extern void mnt_free_filesystems(char **filesystems);
extern char *mnt_get_kernel_cmdline_option(const char *name);
+extern int mnt_stat_mountpoint(const char *target, struct stat *st);
/* tab.c */
extern int is_mountinfo(struct libmnt_table *tb);
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
index 6c9217ee9..e57eb33ba 100644
--- a/libmount/src/utils.c
+++ b/libmount/src/utils.c
@@ -117,6 +117,15 @@ static int fstype_cmp(const void *v1, const void *v2)
return strcmp(s1, s2);
}
+int mnt_stat_mountpoint(const char *target, struct stat *st)
+{
+#ifdef AT_NO_AUTOMOUNT
+ return fstatat(-1, target, st, AT_NO_AUTOMOUNT);
+#else
+ return stat(target, st);
+#endif
+}
+
/*
* Note that the @target has to be an absolute path (so at least "/"). The
* @filename returns an allocated buffer with the last path component, for example:
@@ -983,7 +992,7 @@ char *mnt_get_mountpoint(const char *path)
if (*mnt == '/' && *(mnt + 1) == '\0')
goto done;
- if (stat(mnt, &st))
+ if (mnt_stat_mountpoint(mnt, &st))
goto err;
base = st.st_dev;
@@ -992,7 +1001,7 @@ char *mnt_get_mountpoint(const char *path)
if (!p)
break;
- if (stat(*mnt ? mnt : "/", &st))
+ if (mnt_stat_mountpoint(*mnt ? mnt : "/", &st))
goto err;
dir = st.st_dev;
if (dir != base) {