libmount: add mnt_fs_streq_srcpath()
We have to be careful with "none" or another dummy sources for pseudo filesystems. These strings should be canonicalized or compared as a paths. The function is not exported by library API. Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
41d6af28c3
commit
ab8c6e0569
|
@ -350,6 +350,23 @@ int mnt_fs_set_source(struct libmnt_fs *fs, const char *source)
|
|||
return rc;
|
||||
}
|
||||
|
||||
int mnt_fs_streq_srcpath(struct libmnt_fs *fs, const char *path)
|
||||
{
|
||||
const char *p = mnt_fs_get_srcpath(fs);
|
||||
|
||||
if (p == NULL && path == NULL)
|
||||
return 1;
|
||||
if (p == NULL || path == NULL)
|
||||
return 0;
|
||||
|
||||
if (mnt_fs_is_pseudofs(fs))
|
||||
/* don't think about pseudo-fs source as about path */
|
||||
return strcmp(p, path) == 0;
|
||||
|
||||
return streq_except_trailing_slash(p, path);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* mnt_fs_get_tag:
|
||||
* @fs: fs
|
||||
|
@ -1143,10 +1160,6 @@ int mnt_fs_match_target(struct libmnt_fs *fs, const char *target,
|
|||
* The 2nd, 3rd and 4th attempts are not performed when @cache is NULL. The
|
||||
* 2nd and 3rd attempts are not performed if @fs->source is tag.
|
||||
*
|
||||
* Note that valid source path is NULL; the libmount uses NULL instead of
|
||||
* "none". The "none" is used in /proc/{mounts,self/mountninfo} for pseudo
|
||||
* filesystems.
|
||||
*
|
||||
* Returns: 1 if @fs source is equal to @source else 0.
|
||||
*/
|
||||
int mnt_fs_match_source(struct libmnt_fs *fs, const char *source,
|
||||
|
@ -1158,15 +1171,15 @@ int mnt_fs_match_source(struct libmnt_fs *fs, const char *source,
|
|||
if (!fs)
|
||||
return 0;
|
||||
|
||||
/* undefined source -- "none" in /proc */
|
||||
if (source == NULL && fs->source == NULL)
|
||||
/* 1) native paths... */
|
||||
if (mnt_fs_streq_srcpath(fs, source) == 1)
|
||||
return 1;
|
||||
|
||||
if (source == NULL || fs->source == NULL)
|
||||
if (!source || !fs->source)
|
||||
return 0;
|
||||
|
||||
/* 1) native paths/tags */
|
||||
if (streq_except_trailing_slash(source, fs->source))
|
||||
/* ... and tags */
|
||||
if (fs->tagname && strcmp(source, fs->source) == 0)
|
||||
return 1;
|
||||
|
||||
if (!cache)
|
||||
|
@ -1180,7 +1193,7 @@ int mnt_fs_match_source(struct libmnt_fs *fs, const char *source,
|
|||
|
||||
/* 2) canonicalized and native */
|
||||
src = mnt_fs_get_srcpath(fs);
|
||||
if (src && streq_except_trailing_slash(cn, src))
|
||||
if (src && mnt_fs_streq_srcpath(fs, cn))
|
||||
return 1;
|
||||
|
||||
/* 3) canonicalized and canonicalized */
|
||||
|
|
|
@ -366,6 +366,7 @@ extern int mnt_optstr_fix_user(char **optstr);
|
|||
extern struct libmnt_fs *mnt_copy_mtab_fs(const struct libmnt_fs *fs);
|
||||
extern int __mnt_fs_set_source_ptr(struct libmnt_fs *fs, char *source);
|
||||
extern int __mnt_fs_set_fstype_ptr(struct libmnt_fs *fs, char *fstype);
|
||||
extern int mnt_fs_streq_srcpath(struct libmnt_fs *fs, const char *path);
|
||||
|
||||
/* context.c */
|
||||
extern int mnt_context_prepare_srcpath(struct libmnt_context *cxt);
|
||||
|
|
|
@ -500,16 +500,10 @@ struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb, const char *pa
|
|||
/* native paths */
|
||||
mnt_reset_iter(&itr, direction);
|
||||
while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
|
||||
const char *src = mnt_fs_get_source(fs);
|
||||
|
||||
p = mnt_fs_get_srcpath(fs);
|
||||
|
||||
if (path == NULL && (src == NULL || !strcmp(src, "none")))
|
||||
return fs; /* source is "none" */
|
||||
if (path && p && streq_except_trailing_slash(p, path))
|
||||
if (mnt_fs_streq_srcpath(fs, path))
|
||||
return fs;
|
||||
if (!p && src)
|
||||
ntags++; /* mnt_fs_get_srcpath() returs nothing, it's TAG */
|
||||
if (mnt_fs_get_tag(fs, NULL, NULL) == 0)
|
||||
ntags++;
|
||||
}
|
||||
|
||||
if (!path || !tb->cache || !(cn = mnt_resolve_path(path, tb->cache)))
|
||||
|
@ -519,8 +513,7 @@ struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb, const char *pa
|
|||
if (ntags < mnt_table_get_nents(tb)) {
|
||||
mnt_reset_iter(&itr, direction);
|
||||
while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
|
||||
p = mnt_fs_get_srcpath(fs);
|
||||
if (p && streq_except_trailing_slash(p, cn))
|
||||
if (mnt_fs_streq_srcpath(fs, cn))
|
||||
return fs;
|
||||
}
|
||||
}
|
||||
|
@ -860,18 +853,14 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs)
|
|||
mnt_reset_iter(&itr, MNT_ITER_FORWARD);
|
||||
|
||||
while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
|
||||
const char *s = mnt_fs_get_srcpath(fs),
|
||||
*t = mnt_fs_get_target(fs),
|
||||
const char *t = mnt_fs_get_target(fs),
|
||||
*r = mnt_fs_get_root(fs);
|
||||
|
||||
/*
|
||||
* Note that kernel can add tailing slash to the
|
||||
* network filesystem source paths.
|
||||
*/
|
||||
if (t && s && r &&
|
||||
streq_except_trailing_slash(t, tgt) &&
|
||||
streq_except_trailing_slash(s, src) &&
|
||||
strcmp(r, root) == 0)
|
||||
if (t && r
|
||||
&& mnt_fs_get_srcpath(fs)
|
||||
&& mnt_fs_streq_srcpath(fs, src)
|
||||
&& streq_except_trailing_slash(t, tgt)
|
||||
&& strcmp(r, root) == 0)
|
||||
break;
|
||||
}
|
||||
if (fs)
|
||||
|
|
|
@ -741,7 +741,7 @@ static struct libmnt_fs *mnt_table_merge_user_fs(struct libmnt_table *tb, struct
|
|||
*/
|
||||
if (s && t && r &&
|
||||
strcmp(t, target) == 0 &&
|
||||
streq_except_trailing_slash(s, src) &&
|
||||
mnt_fs_streq_srcpath(fs, src) &&
|
||||
strcmp(r, root) == 0)
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -423,7 +423,7 @@ try_readonly:
|
|||
const char *s = mnt_fs_get_srcpath(fs),
|
||||
*t = mnt_fs_get_target(fs);
|
||||
|
||||
if (t && s && streq_except_trailing_slash(s, src))
|
||||
if (t && s && mnt_fs_streq_strpath(fs, src))
|
||||
fprintf(stderr, _(
|
||||
" %s is already mounted on %s\n"), s, t);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue