diff options
| author | Karel Zak <kzak@redhat.com> | 2023-04-17 13:22:03 +0200 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2023-04-17 13:22:03 +0200 |
| commit | 0d754deeddb60c016e199faa6ad4f1b26e934897 (patch) | |
| tree | bca8bbf685679991ff348dda02c9d0dddf07b962 /libmount | |
| parent | 7f99cc2880a00a1d48b44df550a1dba03c0f6f40 (diff) | |
| download | util-linux-0d754deeddb60c016e199faa6ad4f1b26e934897.tar.gz | |
libmount: don't define struct stat is unnecessary
Let's introduce simple function to hide 'struct stat' if unnecessary.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount')
| -rw-r--r-- | libmount/src/hook_mkdir.c | 3 | ||||
| -rw-r--r-- | libmount/src/mountP.h | 2 | ||||
| -rw-r--r-- | libmount/src/tab.c | 3 | ||||
| -rw-r--r-- | libmount/src/utils.c | 8 |
4 files changed, 12 insertions, 4 deletions
diff --git a/libmount/src/hook_mkdir.c b/libmount/src/hook_mkdir.c index 6e4d73663..da9c407ea 100644 --- a/libmount/src/hook_mkdir.c +++ b/libmount/src/hook_mkdir.c @@ -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); diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h index 7e280a4f8..4af212388 100644 --- a/libmount/src/mountP.h +++ b/libmount/src/mountP.h @@ -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); diff --git a/libmount/src/tab.c b/libmount/src/tab.c index a7da09481..d8b239b30 100644 --- a/libmount/src/tab.c +++ b/libmount/src/tab.c @@ -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); diff --git a/libmount/src/utils.c b/libmount/src/utils.c index 26c5aef7b..e4347f3ea 100644 --- a/libmount/src/utils.c +++ b/libmount/src/utils.c @@ -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 |
