libmount: use fstatat(AT_NO_AUTOMOUNT) for mountpoints

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2015-12-09 10:26:16 +01:00
parent 624996a950
commit 6589a1632b
5 changed files with 20 additions and 6 deletions

View 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

View 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) {

View 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);

View 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);

View 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) {