*
* 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)
ntags++;
}
- return ntags ? 1 : 0;
+ return ntags ? 0 : 1;
error:
blkid_free_probe(pr);
close(fd);
return 0;
}
+/**
+ * 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
return 0;
/* read @source's tags to the cache */
- if (mnt_cache_read_tags(cache, cn) < 1) {
+ if (mnt_cache_read_tags(cache, cn) < 0) {
if (errno == EACCES) {
/* we don't have permissions to read TAGs from
* @source, but can translate @fs tag to devname.
extern int mnt_cache_read_tags(mnt_cache *cache, const char *devname);
extern int mnt_cache_device_has_tag(mnt_cache *cache, const char *devname,
const char *token, const char *value);
+
+extern char *mnt_cache_find_tag_value(mnt_cache *cache,
+ const char *devname, const char *token);
+
extern char *mnt_resolve_path(const char *path, mnt_cache *cache);
extern char *mnt_resolve_tag(const char *token, const char *value, mnt_cache *cache);
extern char *mnt_resolve_spec(const char *spec, mnt_cache *cache);
mnt_cache_device_has_tag;
mnt_cache_find_path;
mnt_cache_find_tag;
+ mnt_cache_find_tag_value;
mnt_cache_read_tags;
mnt_fprintf_line;
mnt_free_cache;
/* evaluated tag */
if (ntags) {
+ int rc = mnt_cache_read_tags(tb->cache, cn);
+
mnt_reset_iter(&itr, direction);
- if (mnt_cache_read_tags(tb->cache, cn) > 0) {
+ if (rc == 0) {
/* @path's TAGs are in the cache */
while(mnt_tab_next_fs(tb, &itr, &fs) == 0) {
const char *t, *v;
if (mnt_cache_device_has_tag(tb->cache, cn, t, v))
return fs;
}
- } else if (errno == EACCES) {
+ } else if (rc < 0 && errno == EACCES) {
/* @path is unaccessible, try evaluate all TAGs in @tb
* by udev symlinks -- this could be expensive on systems
* with huge fstab/mtab */