libmount: add mnt_fs_streq_target() and export all mnt_fs_streq_*
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
dab3357387
commit
6699e742f2
|
@ -174,9 +174,9 @@ mnt_fs_get_userdata
|
||||||
mnt_fs_get_user_options
|
mnt_fs_get_user_options
|
||||||
mnt_fs_get_vfs_options
|
mnt_fs_get_vfs_options
|
||||||
mnt_fs_is_kernel
|
mnt_fs_is_kernel
|
||||||
mnt_fs_is_swaparea
|
|
||||||
mnt_fs_is_netfs
|
mnt_fs_is_netfs
|
||||||
mnt_fs_is_pseudofs
|
mnt_fs_is_pseudofs
|
||||||
|
mnt_fs_is_swaparea
|
||||||
mnt_fs_match_fstype
|
mnt_fs_match_fstype
|
||||||
mnt_fs_match_options
|
mnt_fs_match_options
|
||||||
mnt_fs_match_source
|
mnt_fs_match_source
|
||||||
|
@ -195,6 +195,8 @@ mnt_fs_set_source
|
||||||
mnt_fs_set_target
|
mnt_fs_set_target
|
||||||
mnt_fs_set_userdata
|
mnt_fs_set_userdata
|
||||||
mnt_fs_strdup_options
|
mnt_fs_strdup_options
|
||||||
|
mnt_fs_streq_srcpath
|
||||||
|
mnt_fs_streq_target
|
||||||
mnt_fs_to_mntent
|
mnt_fs_to_mntent
|
||||||
mnt_new_fs
|
mnt_new_fs
|
||||||
mnt_reset_fs
|
mnt_reset_fs
|
||||||
|
|
|
@ -350,22 +350,48 @@ int mnt_fs_set_source(struct libmnt_fs *fs, const char *source)
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mnt_fs_streq_srcpath:
|
||||||
|
* @fs: fs
|
||||||
|
* @path: source path
|
||||||
|
*
|
||||||
|
* Compares @fs source path with @path. The tailing slash is ignored.
|
||||||
|
* See also mnt_fs_match_source().
|
||||||
|
*
|
||||||
|
* Returns: 1 if @fs source path equal to @path, otherwise 0.
|
||||||
|
*/
|
||||||
int mnt_fs_streq_srcpath(struct libmnt_fs *fs, const char *path)
|
int mnt_fs_streq_srcpath(struct libmnt_fs *fs, const char *path)
|
||||||
{
|
{
|
||||||
const char *p = mnt_fs_get_srcpath(fs);
|
const char *p;
|
||||||
|
|
||||||
if (p == NULL && path == NULL)
|
if (!fs)
|
||||||
return 1;
|
|
||||||
if (p == NULL || path == NULL)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (mnt_fs_is_pseudofs(fs))
|
p = mnt_fs_get_srcpath(fs);
|
||||||
/* don't think about pseudo-fs source as about path */
|
|
||||||
return strcmp(p, path) == 0;
|
|
||||||
|
|
||||||
return streq_except_trailing_slash(p, path);
|
if (!mnt_fs_is_pseudofs(fs))
|
||||||
|
return streq_except_trailing_slash(p, path);
|
||||||
|
|
||||||
|
if (!p && !path)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return p && path && strcmp(p, path) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mnt_fs_streq_target:
|
||||||
|
* @fs: fs
|
||||||
|
* @path: mount point
|
||||||
|
*
|
||||||
|
* Compares @fs target path with @path. The tailing slash is ignored.
|
||||||
|
* See also mnt_fs_match_target().
|
||||||
|
*
|
||||||
|
* Returns: 1 if @fs target path equal to @path, otherwise 0.
|
||||||
|
*/
|
||||||
|
int mnt_fs_streq_target(struct libmnt_fs *fs, const char *path)
|
||||||
|
{
|
||||||
|
return fs && streq_except_trailing_slash(mnt_fs_get_target(fs), path);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mnt_fs_get_tag:
|
* mnt_fs_get_tag:
|
||||||
|
@ -1128,7 +1154,7 @@ int mnt_fs_match_target(struct libmnt_fs *fs, const char *target,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* 1) native paths */
|
/* 1) native paths */
|
||||||
rc = !strcmp(target, fs->target);
|
rc = mnt_fs_streq_target(fs, target);
|
||||||
|
|
||||||
if (!rc && cache) {
|
if (!rc && cache) {
|
||||||
/* 2) - canonicalized and non-canonicalized */
|
/* 2) - canonicalized and non-canonicalized */
|
||||||
|
|
|
@ -223,6 +223,9 @@ extern int mnt_fs_set_target(struct libmnt_fs *fs, const char *target);
|
||||||
extern const char *mnt_fs_get_fstype(struct libmnt_fs *fs);
|
extern const char *mnt_fs_get_fstype(struct libmnt_fs *fs);
|
||||||
extern int mnt_fs_set_fstype(struct libmnt_fs *fs, const char *fstype);
|
extern int mnt_fs_set_fstype(struct libmnt_fs *fs, const char *fstype);
|
||||||
|
|
||||||
|
extern int mnt_fs_streq_srcpath(struct libmnt_fs *fs, const char *path);
|
||||||
|
extern int mnt_fs_streq_target(struct libmnt_fs *fs, const char *path);
|
||||||
|
|
||||||
extern char *mnt_fs_strdup_options(struct libmnt_fs *fs);
|
extern char *mnt_fs_strdup_options(struct libmnt_fs *fs);
|
||||||
extern const char *mnt_fs_get_options(struct libmnt_fs *fs);
|
extern const char *mnt_fs_get_options(struct libmnt_fs *fs);
|
||||||
extern int mnt_fs_set_options(struct libmnt_fs *fs, const char *optstr);
|
extern int mnt_fs_set_options(struct libmnt_fs *fs, const char *optstr);
|
||||||
|
|
|
@ -225,3 +225,9 @@ global:
|
||||||
mnt_get_library_features;
|
mnt_get_library_features;
|
||||||
mnt_table_parse_dir;
|
mnt_table_parse_dir;
|
||||||
} MOUNT_2.20;
|
} MOUNT_2.20;
|
||||||
|
|
||||||
|
MOUNT_2.22 {
|
||||||
|
global:
|
||||||
|
mnt_fs_streq_target;
|
||||||
|
mnt_fs_streq_srcpath;
|
||||||
|
} MOUNT_2.21;
|
||||||
|
|
|
@ -366,7 +366,6 @@ extern int mnt_optstr_fix_user(char **optstr);
|
||||||
extern struct libmnt_fs *mnt_copy_mtab_fs(const struct libmnt_fs *fs);
|
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_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_set_fstype_ptr(struct libmnt_fs *fs, char *fstype);
|
||||||
extern int mnt_fs_streq_srcpath(struct libmnt_fs *fs, const char *path);
|
|
||||||
|
|
||||||
/* context.c */
|
/* context.c */
|
||||||
extern int mnt_context_prepare_srcpath(struct libmnt_context *cxt);
|
extern int mnt_context_prepare_srcpath(struct libmnt_context *cxt);
|
||||||
|
|
|
@ -438,7 +438,7 @@ struct libmnt_fs *mnt_table_find_target(struct libmnt_table *tb, const char *pat
|
||||||
/* native @target */
|
/* native @target */
|
||||||
mnt_reset_iter(&itr, direction);
|
mnt_reset_iter(&itr, direction);
|
||||||
while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
|
while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
|
||||||
if (fs->target && streq_except_trailing_slash(fs->target, path))
|
if (mnt_fs_streq_target(fs, path))
|
||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
if (!tb->cache || !(cn = mnt_resolve_path(path, tb->cache)))
|
if (!tb->cache || !(cn = mnt_resolve_path(path, tb->cache)))
|
||||||
|
@ -447,7 +447,7 @@ struct libmnt_fs *mnt_table_find_target(struct libmnt_table *tb, const char *pat
|
||||||
/* canonicalized paths in struct libmnt_table */
|
/* canonicalized paths in struct libmnt_table */
|
||||||
mnt_reset_iter(&itr, direction);
|
mnt_reset_iter(&itr, direction);
|
||||||
while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
|
while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
|
||||||
if (fs->target && strcmp(fs->target, cn) == 0)
|
if (mnt_fs_streq_target(fs, cn))
|
||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,7 +461,8 @@ struct libmnt_fs *mnt_table_find_target(struct libmnt_table *tb, const char *pat
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
p = mnt_resolve_path(fs->target, tb->cache);
|
p = mnt_resolve_path(fs->target, tb->cache);
|
||||||
if (strcmp(cn, p) == 0)
|
/* both canonicalized, strcmp() is fine here */
|
||||||
|
if (p && strcmp(cn, p) == 0)
|
||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -544,7 +545,9 @@ struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb, const char *pa
|
||||||
if (mnt_fs_get_tag(fs, &t, &v))
|
if (mnt_fs_get_tag(fs, &t, &v))
|
||||||
continue;
|
continue;
|
||||||
x = mnt_resolve_tag(t, v, tb->cache);
|
x = mnt_resolve_tag(t, v, tb->cache);
|
||||||
if (x && streq_except_trailing_slash(x, cn))
|
|
||||||
|
/* both canonicalized, strcmp() is fine here */
|
||||||
|
if (x && strcmp(x, cn) == 0)
|
||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -559,7 +562,9 @@ struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb, const char *pa
|
||||||
p = mnt_fs_get_srcpath(fs);
|
p = mnt_fs_get_srcpath(fs);
|
||||||
if (p)
|
if (p)
|
||||||
p = mnt_resolve_path(p, tb->cache);
|
p = mnt_resolve_path(p, tb->cache);
|
||||||
if (p && streq_except_trailing_slash(cn, p))
|
|
||||||
|
/* both canonicalized, strcmp() is fine here */
|
||||||
|
if (p && strcmp(p, cn) == 0)
|
||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -853,14 +858,11 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs)
|
||||||
mnt_reset_iter(&itr, MNT_ITER_FORWARD);
|
mnt_reset_iter(&itr, MNT_ITER_FORWARD);
|
||||||
|
|
||||||
while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
|
while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
|
||||||
const char *t = mnt_fs_get_target(fs),
|
const char *r = mnt_fs_get_root(fs);
|
||||||
*r = mnt_fs_get_root(fs);
|
|
||||||
|
|
||||||
if (t && r
|
if (r && strcmp(r, root) == 0
|
||||||
&& mnt_fs_get_srcpath(fs)
|
|
||||||
&& mnt_fs_streq_srcpath(fs, src)
|
&& mnt_fs_streq_srcpath(fs, src)
|
||||||
&& streq_except_trailing_slash(t, tgt)
|
&& mnt_fs_streq_target(fs, tgt))
|
||||||
&& strcmp(r, root) == 0)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (fs)
|
if (fs)
|
||||||
|
|
|
@ -728,21 +728,14 @@ static struct libmnt_fs *mnt_table_merge_user_fs(struct libmnt_table *tb, struct
|
||||||
mnt_reset_iter(&itr, MNT_ITER_BACKWARD);
|
mnt_reset_iter(&itr, MNT_ITER_BACKWARD);
|
||||||
|
|
||||||
while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
|
while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
|
||||||
const char *s = mnt_fs_get_srcpath(fs),
|
const char *r = mnt_fs_get_root(fs);
|
||||||
*t = mnt_fs_get_target(fs),
|
|
||||||
*r = mnt_fs_get_root(fs);
|
|
||||||
|
|
||||||
if (fs->flags & MNT_FS_MERGED)
|
if (fs->flags & MNT_FS_MERGED)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/*
|
if (r && strcmp(r, root) == 0
|
||||||
* Note that kernel can add tailing slash to the network
|
&& mnt_fs_streq_target(fs, target)
|
||||||
* filesystem source path
|
&& mnt_fs_streq_srcpath(fs, src))
|
||||||
*/
|
|
||||||
if (s && t && r &&
|
|
||||||
strcmp(t, target) == 0 &&
|
|
||||||
mnt_fs_streq_srcpath(fs, src) &&
|
|
||||||
strcmp(r, root) == 0)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -423,7 +423,7 @@ try_readonly:
|
||||||
const char *s = mnt_fs_get_srcpath(fs),
|
const char *s = mnt_fs_get_srcpath(fs),
|
||||||
*t = mnt_fs_get_target(fs);
|
*t = mnt_fs_get_target(fs);
|
||||||
|
|
||||||
if (t && s && mnt_fs_streq_strpath(fs, src))
|
if (t && s && mnt_fs_streq_srcpath(fs, src))
|
||||||
fprintf(stderr, _(
|
fprintf(stderr, _(
|
||||||
" %s is already mounted on %s\n"), s, t);
|
" %s is already mounted on %s\n"), s, t);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue