libmount: ignore tailing slash in netfs source paths
Addresses: https://bugzilla.novell.com/show_bug.cgi?id=728480 Signed-off-by: Petr Uzel <petr.uzel@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
0b14bf7af1
commit
b106d05238
6 changed files with 60 additions and 10 deletions
|
@ -47,4 +47,6 @@ extern int string_to_bitarray(const char *list, char *ary,
|
||||||
|
|
||||||
extern int parse_range(const char *str, int *lower, int *upper, int def);
|
extern int parse_range(const char *str, int *lower, int *upper, int def);
|
||||||
|
|
||||||
|
extern int streq_except_trailing_slash(const char *s1, const char *s2);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -504,6 +504,38 @@ int parse_range(const char *str, int *lower, int *upper, int def)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compare two strings for equality, ignoring at most one trailing
|
||||||
|
* slash.
|
||||||
|
*/
|
||||||
|
int streq_except_trailing_slash(const char *s1, const char *s2)
|
||||||
|
{
|
||||||
|
int equal;
|
||||||
|
|
||||||
|
if (!s1 && !s2)
|
||||||
|
return 1;
|
||||||
|
if (!s1 || !s2)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
equal = !strcmp(s1, s2);
|
||||||
|
|
||||||
|
if (!equal) {
|
||||||
|
size_t len1 = strlen(s1);
|
||||||
|
size_t len2 = strlen(s2);
|
||||||
|
|
||||||
|
if (len1 && *(s1 + len1 - 1) == '/')
|
||||||
|
len1--;
|
||||||
|
if (len2 && *(s2 + len2 - 1) == '/')
|
||||||
|
len2--;
|
||||||
|
if (len1 != len2)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
equal = !strncmp(s1, s2, len1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return equal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef TEST_PROGRAM
|
#ifdef TEST_PROGRAM
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "mountP.h"
|
#include "mountP.h"
|
||||||
|
#include "strutils.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mnt_new_fs:
|
* mnt_new_fs:
|
||||||
|
@ -1142,7 +1143,7 @@ int mnt_fs_match_source(struct libmnt_fs *fs, const char *source, struct libmnt_
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* 1) native paths/tags */
|
/* 1) native paths/tags */
|
||||||
if (!strcmp(source, fs->source))
|
if (streq_except_trailing_slash(source, fs->source))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (!cache)
|
if (!cache)
|
||||||
|
@ -1156,7 +1157,7 @@ int mnt_fs_match_source(struct libmnt_fs *fs, const char *source, struct libmnt_
|
||||||
|
|
||||||
/* 2) canonicalized and native */
|
/* 2) canonicalized and native */
|
||||||
src = mnt_fs_get_srcpath(fs);
|
src = mnt_fs_get_srcpath(fs);
|
||||||
if (src && !strcmp(cn, src))
|
if (src && streq_except_trailing_slash(cn, src))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* 3) canonicalized and canonicalized */
|
/* 3) canonicalized and canonicalized */
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include <blkid.h>
|
#include <blkid.h>
|
||||||
|
|
||||||
#include "mountP.h"
|
#include "mountP.h"
|
||||||
|
#include "strutils.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mnt_new_table:
|
* mnt_new_table:
|
||||||
|
@ -506,7 +507,7 @@ struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb, const char *pa
|
||||||
|
|
||||||
if (path == NULL && src == NULL)
|
if (path == NULL && src == NULL)
|
||||||
return fs; /* source is "none" */
|
return fs; /* source is "none" */
|
||||||
if (path && p && strcmp(p, path) == 0)
|
if (path && p && streq_except_trailing_slash(p, path))
|
||||||
return fs;
|
return fs;
|
||||||
if (!p && src)
|
if (!p && src)
|
||||||
ntags++; /* mnt_fs_get_srcpath() returs nothing, it's TAG */
|
ntags++; /* mnt_fs_get_srcpath() returs nothing, it's TAG */
|
||||||
|
@ -520,7 +521,7 @@ struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb, const char *pa
|
||||||
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) {
|
||||||
p = mnt_fs_get_srcpath(fs);
|
p = mnt_fs_get_srcpath(fs);
|
||||||
if (p && strcmp(p, cn) == 0)
|
if (p && streq_except_trailing_slash(p, cn))
|
||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -551,7 +552,7 @@ 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 && !strcmp(x, cn))
|
if (x && streq_except_trailing_slash(x, cn))
|
||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -566,7 +567,7 @@ 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 && strcmp(cn, p) == 0)
|
if (p && streq_except_trailing_slash(cn, p))
|
||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -856,8 +857,14 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs)
|
||||||
*t = mnt_fs_get_target(fs),
|
*t = mnt_fs_get_target(fs),
|
||||||
*r = mnt_fs_get_root(fs);
|
*r = mnt_fs_get_root(fs);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note that kernel can add tailing slash to the
|
||||||
|
* network filesystem source paths.
|
||||||
|
*/
|
||||||
if (t && s && r &&
|
if (t && s && r &&
|
||||||
!strcmp(t, tgt) && !strcmp(s, src) && !strcmp(r, root))
|
strcmp(t, tgt) == 0 &&
|
||||||
|
streq_except_trailing_slash(s, src) &&
|
||||||
|
strcmp(r, root) == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (fs)
|
if (fs)
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "mangle.h"
|
#include "mangle.h"
|
||||||
#include "mountP.h"
|
#include "mountP.h"
|
||||||
#include "pathnames.h"
|
#include "pathnames.h"
|
||||||
|
#include "strutils.h"
|
||||||
|
|
||||||
static inline char *skip_spaces(char *s)
|
static inline char *skip_spaces(char *s)
|
||||||
{
|
{
|
||||||
|
@ -654,8 +655,14 @@ static struct libmnt_fs *mnt_table_merge_user_fs(struct libmnt_table *tb, struct
|
||||||
if (fs->flags & MNT_FS_MERGED)
|
if (fs->flags & MNT_FS_MERGED)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (s && t && r && !strcmp(t, target) &&
|
/*
|
||||||
!strcmp(s, src) && !strcmp(r, root))
|
* Note that kernel can add tailing slash to the network
|
||||||
|
* filesystem source path
|
||||||
|
*/
|
||||||
|
if (s && t && r &&
|
||||||
|
strcmp(t, target) == 0 &&
|
||||||
|
streq_except_trailing_slash(s, src) &&
|
||||||
|
strcmp(r, root) == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "pathnames.h"
|
#include "pathnames.h"
|
||||||
#include "nls.h"
|
#include "nls.h"
|
||||||
#include "usleep.h"
|
#include "usleep.h"
|
||||||
|
#include "strutils.h"
|
||||||
|
|
||||||
#define streq(s, t) (strcmp ((s), (t)) == 0)
|
#define streq(s, t) (strcmp ((s), (t)) == 0)
|
||||||
|
|
||||||
|
@ -436,7 +437,7 @@ getfs_by_devdir (const char *dev, const char *dir) {
|
||||||
ok = has_uuid(dev, fs + 5);
|
ok = has_uuid(dev, fs + 5);
|
||||||
} else {
|
} else {
|
||||||
fs = canonicalize_spec(mc->m.mnt_fsname);
|
fs = canonicalize_spec(mc->m.mnt_fsname);
|
||||||
ok = streq(fs, dev);
|
ok = streq_except_trailing_slash(fs, dev);
|
||||||
my_free(fs);
|
my_free(fs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue