From: Karel Zak Date: Tue, 26 Apr 2011 14:32:09 +0000 (+0200) Subject: libmount: support NULL source path for mnt_table_find_* functions X-Git-Tag: v2.20-rc1~321 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f12aac6e3e440166917092a83cd76a6300077abd;p=thirdparty%2Futil-linux.git libmount: support NULL source path for mnt_table_find_* functions Signed-off-by: Karel Zak --- diff --git a/shlibs/mount/src/fs.c b/shlibs/mount/src/fs.c index c7a4fce025..21b7ab95d2 100644 --- a/shlibs/mount/src/fs.c +++ b/shlibs/mount/src/fs.c @@ -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 */ diff --git a/shlibs/mount/src/tab.c b/shlibs/mount/src/tab.c index 2d2e72fd1e..fff56b7e06 100644 --- a/shlibs/mount/src/tab.c +++ b/shlibs/mount/src/tab.c @@ -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)); diff --git a/shlibs/mount/src/tab_update.c b/shlibs/mount/src/tab_update.c index d514641845..5abb566b59 100644 --- a/shlibs/mount/src/tab_update.c +++ b/shlibs/mount/src/tab_update.c @@ -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.