]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: use fstatat(AT_NO_AUTOMOUNT) for mountpoints
authorKarel Zak <kzak@redhat.com>
Wed, 9 Dec 2015 09:26:16 +0000 (10:26 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 9 Dec 2015 09:26:16 +0000 (10:26 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
Documentation/TODO
libmount/src/context.c
libmount/src/context_umount.c
libmount/src/mountP.h
libmount/src/utils.c

index 22fa0e06f7f5336e837baa8b5f30bf39caa12c7d..6b4ee30207864fce028c5d6761d5ce00c33bca7d 100644 (file)
@@ -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
index 5ab0b794e467cd812dbaae8c9469611e5fdad74a..7b965a07f280d3d6f92ab02c44303783ea788df4 100644 (file)
@@ -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) {
index c4e9ebbee767c24a98cc5a9ce18e45cbcebebc7f..b67f48b918baea05ae3371bafc75cf053392af38 100644 (file)
@@ -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);
index 660e0ad08bf5857f58273eda2411692401377289..25418a2e40737726e329dcd75da948821d2712d3 100644 (file)
@@ -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);
index 6c9217ee96720a733b147b7c71aa1a8773583538..e57eb33ba30a8fff2cf9d256a27e92ef24431d6b 100644 (file)
@@ -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) {