char *
fsprobe_get_devname_by_spec(const char *spec)
{
- char *name, *value;
-
- if (!spec)
- return NULL;
- if (fsprobe_parse_spec(spec, &name, &value) != 0)
- return NULL; /* parse error */
- if (name) {
- char *nspec = NULL;
-
- if (!strcmp(name,"LABEL"))
- nspec = fsprobe_get_devname_by_label(value);
- else if (!strcmp(name,"UUID"))
- nspec = fsprobe_get_devname_by_uuid(value);
-
- free(name);
- free(value);
- return nspec;
- }
-
- return canonicalize_path(spec);
+ return blkid_evaluate_spec(spec, blcache);
}
int
extern int blkid_send_uevent(const char *devname, const char *action);
extern char *blkid_evaluate_tag(const char *token, const char *value,
blkid_cache *cache);
+extern char *blkid_evaluate_spec(const char *spec, blkid_cache *cache);
/* probe.c */
extern blkid_probe blkid_new_probe(void);
/*
- * version(s) since util-linux 2.15
+ * symbols since util-linux 2.15
*/
BLKID_2.15 {
global:
} BLKID_1.0;
/*
- * version(s) since util-linux 2.17
+ * symbols since util-linux 2.17
*/
BLKID_2.17 {
global:
} BLKID_2.15;
/*
- * version(s) since util-linux 2.18
+ * symbols since util-linux 2.18
*/
BLKID_2.18 {
global:
blkid_probe_get_wholedisk_devno;
blkid_probe_is_wholedisk;
} BLKID_2.17;
+
+/*
+ * symbols since util-linux 2.20
+ */
+BLKID_2.20 {
+global:
+ blkid_evaluate_spec;
+} BLKID_2.18;
+
/**
* blkid_evaluate_tag:
- * @token: token name (e.g "LABEL" or "UUID")
- * @value: token data
+ * @token: token name (e.g "LABEL" or "UUID") or unparsed tag (e.g. "LABEL=foo")
+ * @value: token data (e.g. "foo")
* @cache: pointer to cache (or NULL when you don't want to re-use the cache)
*
* Returns: allocated string with a device name.
return ret;
}
+/**
+ * blkid_evaluate_spec:
+ * @spec: unparsed tag (e.g. "LABEL=foo") or path (e.g. /dev/dm-0)
+ * @cache: pointer to cache (or NULL when you don't want to re-use the cache)
+ *
+ * All returned paths are canonicalized, device-mapper paths are converted
+ * to the /dev/mapper/<name> format.
+ *
+ * Returns: allocated string with a device name.
+ */
+char *blkid_evaluate_spec(const char *spec, blkid_cache *cache)
+{
+ char *t = NULL, *v = NULL, *res;
+
+ if (!spec)
+ return NULL;
+
+ if (strchr(spec, '=') &&
+ blkid_parse_tag_string(spec, &t, &v) != 0) /* parse error */
+ return NULL;
+
+ if (v)
+ res = blkid_evaluate_tag(t, v, cache);
+ else
+ res = canonicalize_path(spec);
+
+ free(t);
+ free(v);
+ return res;
+}
+
+
#ifdef TEST_PROGRAM
int main(int argc, char *argv[])
{
blkid_cache cache = NULL;
char *res;
- if (argc < 3) {
- fprintf(stderr, "usage: %s <token> <value>\n", argv[0]);
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s <tag> | <spec>\n", argv[0]);
return EXIT_FAILURE;
}
blkid_init_debug(0);
- res = blkid_evaluate_tag(argv[1], argv[2], &cache);
+ res = blkid_evaluate_spec(argv[1], &cache);
if (res)
printf("%s\n", res);
if (cache)