]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: support NULL source path for mnt_table_find_* functions
authorKarel Zak <kzak@redhat.com>
Tue, 26 Apr 2011 14:32:09 +0000 (16:32 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 26 Apr 2011 14:32:09 +0000 (16:32 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/mount/src/fs.c
shlibs/mount/src/tab.c
shlibs/mount/src/tab_update.c

index c7a4fce025bfdd25df8e5149c8669fb4c2a7c33f..21b7ab95d2611f9747400aca0923cc41a4f302b1 100644 (file)
@@ -1107,7 +1107,7 @@ int mnt_fs_match_target(struct libmnt_fs *fs, const char *target, struct libmnt_
 /**
  * mnt_fs_match_source:
  * @fs: filesystem
- * @source: tag or path (device or so)
+ * @source: tag or path (device or so) or NULL
  * @cache: tags/paths cache or NULL
  *
  * Possible are four attempts:
@@ -1119,6 +1119,10 @@ int mnt_fs_match_target(struct libmnt_fs *fs, const char *target, struct libmnt_
  * 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, struct libmnt_cache *cache)
@@ -1126,7 +1130,14 @@ int mnt_fs_match_source(struct libmnt_fs *fs, const char *source, struct libmnt_
        char *cn;
        const char *src, *t, *v;
 
-       if (!fs || !source || !fs->source)
+       if (!fs)
+               return 0;
+
+       /* undefined source -- "none" in /proc */
+       if (source == NULL && fs->source == NULL)
+               return 1;
+
+       if (source == NULL || fs->source == NULL)
                return 0;
 
        /* 1) native paths/tags */
index 2d2e72fd1ec49e1b53e2b4a3c7d81258cbffaaf5..fff56b7e06c1d7aae366a3839c2f54c26fc2e680 100644 (file)
@@ -461,7 +461,7 @@ struct libmnt_fs *mnt_table_find_target(struct libmnt_table *tb, const char *pat
 /**
  * mnt_table_find_srcpath:
  * @tb: tab pointer
- * @path: source path (devname or dirname)
+ * @path: source path (devname or dirname) or NULL
  * @direction: MNT_ITER_{FORWARD,BACKWARD}
  *
  * Try to lookup an entry in given tab, possible are four iterations, first
@@ -471,6 +471,10 @@ struct libmnt_fs *mnt_table_find_target(struct libmnt_table *tb, const char *pat
  * The 2nd, 3rd and 4th iterations are not performed when @tb cache is not
  * set (see mnt_table_set_cache()).
  *
+ * 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: a tab entry or NULL.
  */
 struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb, const char *path, int direction)
@@ -482,22 +486,25 @@ struct libmnt_fs *mnt_table_find_srcpath(struct libmnt_table *tb, const char *pa
        const char *p;
 
        assert(tb);
-       assert(path);
 
        DBG(TAB, mnt_debug_h(tb, "lookup srcpath: %s", path));
 
        /* 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)
+                       return fs;                      /* source is "none" */
                if (p && strcmp(p, path) == 0)
                        return fs;
-               if (!p)
-                       /* mnt_fs_get_srcpath() returs nothing, it's TAG */
-                       ntags++;
+               if (!p && src)
+                       ntags++;                        /* mnt_fs_get_srcpath() returs nothing, it's TAG */
        }
 
-       if (!tb->cache || !(cn = mnt_resolve_path(path, tb->cache)))
+       if (!path || !tb->cache || !(cn = mnt_resolve_path(path, tb->cache)))
                return NULL;
 
        /* canonicalized paths in struct libmnt_table */
@@ -619,19 +626,19 @@ struct libmnt_fs *mnt_table_find_tag(struct libmnt_table *tb, const char *tag,
  *
  * Returns: a tab entry or NULL.
  */
-struct libmnt_fs *mnt_table_find_source(struct libmnt_table *tb, const char *source, int direction)
+struct libmnt_fs *mnt_table_find_source(struct libmnt_table *tb,
+                                       const char *source, int direction)
 {
        struct libmnt_fs *fs = NULL;
 
        assert(tb);
-       assert(source);
 
-       if (!tb || !source)
+       if (!tb)
                return NULL;
 
        DBG(TAB, mnt_debug_h(tb, "lookup SOURCE: %s", source));
 
-       if (strchr(source, '=')) {
+       if (source && strchr(source, '=')) {
                char *tag, *val;
 
                if (blkid_parse_tag_string(source, &tag, &val) == 0) {
@@ -661,16 +668,15 @@ struct libmnt_fs *mnt_table_find_source(struct libmnt_table *tb, const char *sou
  * Returns: a tab entry or NULL.
  */
 struct libmnt_fs *mnt_table_find_pair(struct libmnt_table *tb, const char *source,
-                       const char *target, int direction)
+                                     const char *target, int direction)
 {
        struct libmnt_fs *fs = NULL;
        struct libmnt_iter itr;
 
        assert(tb);
-       assert(source);
        assert(target);
 
-       if (!tb || !source || !target)
+       if (!tb || !target)
                return NULL;
 
        DBG(TAB, mnt_debug_h(tb, "lookup SOURCE: %s TARGET: %s", source, target));
index d51464184535087b28deacd9743ac819a1f92dea..5abb566b594d914a344373e1272159581dfb6358 100644 (file)
@@ -153,7 +153,7 @@ int mnt_update_is_ready(struct libmnt_update *upd)
  * mnt_update_set_fs:
  * @upd: update handler
  * @mountflags: MS_* flags
- * @target: umount target, must be num for mount
+ * @target: umount target, must be NULL for mount
  * @fs: mount filesystem description, must be NULL for umount
  *
  * Returns: <0 in case on error, 0 on success, 1 if update is unnecessary.