/**
* 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:
* 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)
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 */
/**
* 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
* 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)
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 */
*
* 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) {
* 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));