/** * mnt_tag_is_valid: * @tag: NAME=value string * * Returns: 1 if the @tag is parsable and tag NAME= is supported by libmount, or 0. */ int mnt_tag_is_valid(const char *tag) { char *t = NULL; int rc = tag && blkid_parse_tag_string(tag, &t, NULL) == 0 && mnt_valid_tagname(t); free(t); return rc; }
int test_read_tags(struct libmnt_test *ts, int argc, char *argv[]) { char line[BUFSIZ]; struct libmnt_cache *cache; size_t i; cache = mnt_new_cache(); if (!cache) return -ENOMEM; while(fgets(line, sizeof(line), stdin)) { size_t sz = strlen(line); char *t = NULL, *v = NULL; if (sz > 0 && line[sz - 1] == '\n') line[sz - 1] = '\0'; if (!strcmp(line, "quit")) break; if (*line == '/') { if (mnt_cache_read_tags(cache, line) < 0) fprintf(stderr, "%s: read tags failed\n", line); } else if (blkid_parse_tag_string(line, &t, &v) == 0) { const char *cn = NULL; if (mnt_valid_tagname(t)) cn = cache_find_tag(cache, t, v); free(t); free(v); if (cn) printf("%s: %s\n", line, cn); else printf("%s: not cached\n", line); } } for (i = 0; i < cache->nents; i++) { struct mnt_cache_entry *e = &cache->ents[i]; if (!(e->flag & MNT_CACHE_ISTAG)) continue; printf("%15s : %5s : %s\n", e->value, e->key, e->key + strlen(e->key) + 1); } mnt_unref_cache(cache); return 0; }
/** * mnt_resolve_spec: * @spec: path or tag * @cache: paths cache * * Returns: canonicalized path or NULL. The result has to be * deallocated by free() if @cache is NULL. */ char *mnt_resolve_spec(const char *spec, struct libmnt_cache *cache) { char *cn = NULL; char *t = NULL, *v = NULL; if (!spec) return NULL; if (blkid_parse_tag_string(spec, &t, &v) == 0 && mnt_valid_tagname(t)) cn = mnt_resolve_tag(t, v, cache); else cn = mnt_resolve_path(spec, cache); free(t); free(v); return cn; }