]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - libblkid/src/resolve.c
2 * resolve.c - resolve names and tags into specific devices
4 * Copyright (C) 2001, 2003 Theodore Ts'o.
5 * Copyright (C) 2001 Andreas Dilger
8 * This file may be redistributed under the terms of the
9 * GNU Lesser General Public License.
20 #include <sys/types.h>
25 * Find a tagname (e.g. LABEL or UUID) on a specific device.
27 char *blkid_get_tag_value(blkid_cache cache
, const char *tagname
,
32 blkid_cache c
= cache
;
35 DBG(DEBUG_RESOLVE
, printf("looking for %s on %s\n", tagname
, devname
));
41 if (blkid_get_cache(&c
, NULL
) < 0)
45 if ((dev
= blkid_get_dev(c
, devname
, BLKID_DEV_NORMAL
)) &&
46 (found
= blkid_find_tag_dev(dev
, tagname
)))
47 ret
= found
->bit_val
? strdup(found
->bit_val
) : NULL
;
56 * Locate a device name from a token (NAME=value string), or (name, value)
57 * pair. In the case of a token, value is ignored. If the "token" is not
58 * of the form "NAME=value" and there is no value given, then it is assumed
59 * to be the actual devname and a copy is returned.
61 char *blkid_get_devname(blkid_cache cache
, const char *token
,
65 blkid_cache c
= cache
;
73 if (blkid_get_cache(&c
, NULL
) < 0)
78 printf("looking for %s%s%s %s\n", token
, value
? "=" : "",
79 value
? value
: "", cache
? "in cache" : "from disk"));
82 if (!strchr(token
, '=')) {
86 blkid_parse_tag_string(token
, &t
, &v
);
93 dev
= blkid_find_dev_with_tag(c
, token
, value
);
97 ret
= dev
->bid_name
? strdup(dev
->bid_name
) : NULL
;
107 int main(int argc
, char **argv
)
112 blkid_init_debug(DEBUG_ALL
);
113 if (argc
!= 2 && argc
!= 3) {
114 fprintf(stderr
, "Usage:\t%s tagname=value\n"
115 "\t%s tagname devname\n"
116 "Find which device holds a given token or\n"
117 "Find what the value of a tag is in a device\n",
121 if (blkid_get_cache(&cache
, "/dev/null") < 0) {
122 fprintf(stderr
, "Couldn't get blkid cache\n");
127 value
= blkid_get_tag_value(cache
, argv
[1], argv
[2]);
128 printf("%s has tag %s=%s\n", argv
[2], argv
[1],
129 value
? value
: "<missing>");
131 value
= blkid_get_devname(cache
, argv
[1], NULL
);
132 printf("%s has tag %s\n", value
? value
: "<none>", argv
[1]);
134 blkid_put_cache(cache
);
135 return value
? 0 : 1;