]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: add mnt_fs_streq_srcpath()
authorKarel Zak <kzak@redhat.com>
Fri, 2 Mar 2012 12:29:39 +0000 (13:29 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 2 Mar 2012 12:29:39 +0000 (13:29 +0100)
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>
libmount/src/fs.c
libmount/src/mountP.h
libmount/src/tab.c
libmount/src/tab_parse.c
sys-utils/mount.c

index 5e4139c6aea8e5d569ecddef5130d659e16a2ea2..ba57dabb34dbd4213415f89219fa9d61a81d1eae 100644 (file)
@@ -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 */
index fa0edf50cdf00a91dfd703dba3cde4bc9ab8f7c9..f62acbd1011d3db37903497ecee0d90995e40333 100644 (file)
@@ -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);
index 7dd965458ffed1a32673e825fd968c5867919388..d2a954bbabba10fab4ca981a819e16a092e2aad1 100644 (file)
@@ -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)
index 5bc55ae43d11d7089b1b4ab28f147ba00117a953..4d581c31e5d0908bbf4f0b41b8d25b2082d03bd2 100644 (file)
@@ -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;
        }
index 8f5dcdbd6a09245469b6bc8c9033983aa7b9d794..8c94052e59431c913dc41299294cc28c6c5bc08f 100644 (file)
@@ -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);
                        }