]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: don't define struct stat is unnecessary
authorKarel Zak <kzak@redhat.com>
Mon, 17 Apr 2023 11:22:03 +0000 (13:22 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 17 Apr 2023 11:22:03 +0000 (13:22 +0200)
Let's introduce simple function to hide 'struct stat' if unnecessary.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/hook_mkdir.c
libmount/src/mountP.h
libmount/src/tab.c
libmount/src/utils.c

index 6e4d73663885a295d18aa7dc2fd5f0e140a41c6a..da9c407ea2915759e4b05307e532828a04c2a514 100644 (file)
@@ -36,7 +36,6 @@ static int is_mkdir_required(struct libmnt_context *cxt, const char *tgt, mode_t
        struct libmnt_optlist *ol;
        struct libmnt_opt *opt;
        const char *mstr = NULL;
-       struct stat st;
 
        assert(cxt);
        assert(cxt->map_userspace);
@@ -57,7 +56,7 @@ static int is_mkdir_required(struct libmnt_context *cxt, const char *tgt, mode_t
        if (!opt)
                return 0;
 
-       if (mnt_stat_mountpoint(tgt, &st) == 0)
+       if (mnt_is_path(tgt))
                return 0;
 
        mstr = mnt_opt_get_value(opt);
index 7e280a4f8b2d7e5817abb8bf9b442ed32a83688e..4af212388c61651c619ac2a76f707aa9294ecfc9 100644 (file)
@@ -127,8 +127,10 @@ 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);
 extern int mnt_lstat_mountpoint(const char *target, struct stat *st);
+extern int mnt_is_path(const char *target);
 
 extern int mnt_tmptgt_unshare(int *old_ns_fd);
 extern int mnt_tmptgt_cleanup(int old_ns_fd);
index a7da09481c2f59a3cc600c1788c145f2cd623802..d8b239b305e4c833f5e92d46dffd2087b46d6cd0 100644 (file)
@@ -1010,7 +1010,6 @@ struct libmnt_fs *mnt_table_find_mountpoint(struct libmnt_table *tb,
                                            int direction)
 {
        char *mnt;
-       struct stat st;
 
        if (!tb || !path || !*path)
                return NULL;
@@ -1019,7 +1018,7 @@ struct libmnt_fs *mnt_table_find_mountpoint(struct libmnt_table *tb,
 
        DBG(TAB, ul_debugobj(tb, "lookup MOUNTPOINT: '%s'", path));
 
-       if (mnt_stat_mountpoint(path, &st))
+       if (!mnt_is_path(path))
                return NULL;
 
        mnt = strdup(path);
index 26c5aef7b1f459478b95e381dfeaf12228e24d55..e4347f3ea9af5e0cb7aab119a1155e089a1d9864 100644 (file)
@@ -118,6 +118,14 @@ int mnt_lstat_mountpoint(const char *target, struct stat *st)
 #endif
 }
 
+/* Don't use access() or stat() here, we need a way how to check the path
+ * without trigger an automount or hangs on NFS, etc. */
+int mnt_is_path(const char *target)
+{
+       struct stat st;
+
+       return mnt_stat_mountpoint(target, &st) == 0;
+}
 
 /*
  * Note that the @target has to be an absolute path (so at least "/").  The