diff options
Diffstat (limited to 'e2fsprogs/blkid/tag.c')
-rw-r--r-- | e2fsprogs/blkid/tag.c | 101 |
1 files changed, 100 insertions, 1 deletions
diff --git a/e2fsprogs/blkid/tag.c b/e2fsprogs/blkid/tag.c index 51615d4a5..61642464d 100644 --- a/e2fsprogs/blkid/tag.c +++ b/e2fsprogs/blkid/tag.c | |||
@@ -29,6 +29,18 @@ static blkid_tag blkid_new_tag(void) | |||
29 | return tag; | 29 | return tag; |
30 | } | 30 | } |
31 | 31 | ||
32 | #ifdef CONFIG_BLKID_DEBUG | ||
33 | void blkid_debug_dump_tag(blkid_tag tag) | ||
34 | { | ||
35 | if (!tag) { | ||
36 | printf(" tag: NULL\n"); | ||
37 | return; | ||
38 | } | ||
39 | |||
40 | printf(" tag: %s=\"%s\"\n", tag->bit_name, tag->bit_val); | ||
41 | } | ||
42 | #endif | ||
43 | |||
32 | void blkid_free_tag(blkid_tag tag) | 44 | void blkid_free_tag(blkid_tag tag) |
33 | { | 45 | { |
34 | if (!tag) | 46 | if (!tag) |
@@ -36,7 +48,7 @@ void blkid_free_tag(blkid_tag tag) | |||
36 | 48 | ||
37 | DBG(DEBUG_TAG, printf(" freeing tag %s=%s\n", tag->bit_name, | 49 | DBG(DEBUG_TAG, printf(" freeing tag %s=%s\n", tag->bit_name, |
38 | tag->bit_val ? tag->bit_val : "(NULL)")); | 50 | tag->bit_val ? tag->bit_val : "(NULL)")); |
39 | DEB_DUMP_TAG(DEBUG_TAG, tag); | 51 | DBG(DEBUG_TAG, blkid_debug_dump_tag(tag)); |
40 | 52 | ||
41 | list_del(&tag->bit_tags); /* list of tags for this device */ | 53 | list_del(&tag->bit_tags); /* list of tags for this device */ |
42 | list_del(&tag->bit_names); /* list of tags with this type */ | 54 | list_del(&tag->bit_names); /* list of tags with this type */ |
@@ -330,3 +342,90 @@ try_again: | |||
330 | } | 342 | } |
331 | return dev; | 343 | return dev; |
332 | } | 344 | } |
345 | |||
346 | #ifdef TEST_PROGRAM | ||
347 | #ifdef HAVE_GETOPT_H | ||
348 | #include <getopt.h> | ||
349 | #else | ||
350 | extern char *optarg; | ||
351 | extern int optind; | ||
352 | #endif | ||
353 | |||
354 | void usage(char *prog) | ||
355 | { | ||
356 | fprintf(stderr, "Usage: %s [-f blkid_file] [-m debug_mask] device " | ||
357 | "[type value]\n", | ||
358 | prog); | ||
359 | fprintf(stderr, "\tList all tags for a device and exit\n", prog); | ||
360 | exit(1); | ||
361 | } | ||
362 | |||
363 | int main(int argc, char **argv) | ||
364 | { | ||
365 | blkid_tag_iterate iter; | ||
366 | blkid_cache cache = NULL; | ||
367 | blkid_dev dev; | ||
368 | int c, ret, found; | ||
369 | int flags = BLKID_DEV_FIND; | ||
370 | char *tmp; | ||
371 | char *file = NULL; | ||
372 | char *devname = NULL; | ||
373 | char *search_type = NULL; | ||
374 | char *search_value = NULL; | ||
375 | const char *type, *value; | ||
376 | |||
377 | while ((c = getopt (argc, argv, "m:f:")) != EOF) | ||
378 | switch (c) { | ||
379 | case 'f': | ||
380 | file = optarg; | ||
381 | break; | ||
382 | case 'm': | ||
383 | blkid_debug_mask = strtoul (optarg, &tmp, 0); | ||
384 | if (*tmp) { | ||
385 | fprintf(stderr, "Invalid debug mask: %d\n", | ||
386 | optarg); | ||
387 | exit(1); | ||
388 | } | ||
389 | break; | ||
390 | case '?': | ||
391 | usage(argv[0]); | ||
392 | } | ||
393 | if (argc > optind) | ||
394 | devname = argv[optind++]; | ||
395 | if (argc > optind) | ||
396 | search_type = argv[optind++]; | ||
397 | if (argc > optind) | ||
398 | search_value = argv[optind++]; | ||
399 | if (!devname || (argc != optind)) | ||
400 | usage(argv[0]); | ||
401 | |||
402 | if ((ret = blkid_get_cache(&cache, file)) != 0) { | ||
403 | fprintf(stderr, "%s: error creating cache (%d)\n", | ||
404 | argv[0], ret); | ||
405 | exit(1); | ||
406 | } | ||
407 | |||
408 | dev = blkid_get_dev(cache, devname, flags); | ||
409 | if (!dev) { | ||
410 | fprintf(stderr, "%s: Can not find device in blkid cache\n"); | ||
411 | exit(1); | ||
412 | } | ||
413 | if (search_type) { | ||
414 | found = blkid_dev_has_tag(dev, search_type, search_value); | ||
415 | printf("Device %s: (%s, %s) %s\n", blkid_dev_devname(dev), | ||
416 | search_type, search_value ? search_value : "NULL", | ||
417 | found ? "FOUND" : "NOT FOUND"); | ||
418 | return(!found); | ||
419 | } | ||
420 | printf("Device %s...\n", blkid_dev_devname(dev)); | ||
421 | |||
422 | iter = blkid_tag_iterate_begin(dev); | ||
423 | while (blkid_tag_next(iter, &type, &value) == 0) { | ||
424 | printf("\tTag %s has value %s\n", type, value); | ||
425 | } | ||
426 | blkid_tag_iterate_end(iter); | ||
427 | |||
428 | blkid_put_cache(cache); | ||
429 | return (0); | ||
430 | } | ||
431 | #endif | ||