diff options
author | Karel Zak | 2010-03-12 23:42:56 +0100 |
---|---|---|
committer | Karel Zak | 2010-06-03 15:20:11 +0200 |
commit | ba7232a1fe1398e7947d1af39fadc8d02b21bf69 (patch) | |
tree | dfa9aeae8f08bf02582055b4794164b91da4f947 /shlibs/mount/src/cache.c | |
parent | libmount: add support for userdata and work with VFS tree (diff) | |
download | kernel-qcow2-util-linux-ba7232a1fe1398e7947d1af39fadc8d02b21bf69.tar.gz kernel-qcow2-util-linux-ba7232a1fe1398e7947d1af39fadc8d02b21bf69.tar.xz kernel-qcow2-util-linux-ba7232a1fe1398e7947d1af39fadc8d02b21bf69.zip |
libmount: add mnt_cache_find_tag_value()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/mount/src/cache.c')
-rw-r--r-- | shlibs/mount/src/cache.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/shlibs/mount/src/cache.c b/shlibs/mount/src/cache.c index b9d89f438..62d514d89 100644 --- a/shlibs/mount/src/cache.c +++ b/shlibs/mount/src/cache.c @@ -220,7 +220,7 @@ const char *mnt_cache_find_tag(mnt_cache *cache, * * Reads @devname LABEL and UUID to the @cache. * - * Returns: 1 if at least on tag was added, 0 no tag was added or + * Returns: 0 if at least on tag was added, 1 if no tag was added or * -1 in case of error. */ int mnt_cache_read_tags(mnt_cache *cache, const char *devname) @@ -289,7 +289,7 @@ int mnt_cache_read_tags(mnt_cache *cache, const char *devname) ntags++; } - return ntags ? 1 : 0; + return ntags ? 0 : 1; error: blkid_free_probe(pr); close(fd); @@ -318,6 +318,37 @@ int mnt_cache_device_has_tag(mnt_cache *cache, const char *devname, } /** + * mnt_cache_find_tag_value: + * @cache: cache for results + * @devname: device name + * @token: tag name ("LABEL" or "UUID") + * + * Returns: LABEL or UUID for the @devname or NULL in case of error. + */ +char *mnt_cache_find_tag_value(mnt_cache *cache, + const char *devname, const char *token) +{ + int i; + + if (!cache || !devname || !token) + return NULL; + + if (mnt_cache_read_tags(cache, devname) != 0) + return NULL; + + for (i = 0; i < cache->nents; i++) { + struct mnt_cache_entry *e = &cache->ents[i]; + if (!(e->flag & MNT_CACHE_ISTAG)) + continue; + if (strcmp(e->real, devname) == 0 && /* dev name */ + strcmp(token, e->native) == 0) /* tag name */ + return e->native + strlen(token) + 1; /* tag value */ + } + + return NULL; +} + +/** * mnt_resolve_path: * @path: "native" path * @cache: cache for results or NULL |