Upload Tizen:Base source
[framework/base/util-linux-ng.git] / misc-utils / findfs.c
1 /*
2  * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
3  *
4  * This file may be redistributed under the terms of the GNU Public
5  * License.
6  */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <errno.h>
11 #include <err.h>
12
13 #include <blkid.h>
14
15 #include "nls.h"
16
17 static void __attribute__((__noreturn__)) usage(int rc)
18 {
19         const char *p = program_invocation_short_name;
20
21         if (!p)
22                 p = "findfs";
23
24         fprintf(stderr, _("Usage: %s LABEL=<label>|UUID=<uuid>\n"), p);
25         exit(rc);
26 }
27
28 int main(int argc, char **argv)
29 {
30         char    *dev, *tk, *vl;
31
32         setlocale(LC_ALL, "");
33         bindtextdomain(PACKAGE, LOCALEDIR);
34         textdomain(PACKAGE);
35
36         if (argc != 2)
37                 /* we return '2' for backward compatibility
38                  * with version from e2fsprogs */
39                 usage(2);
40
41         if (!strncmp(argv[1], "LABEL=", 6)) {
42                 tk = "LABEL";
43                 vl = argv[1] + 6;
44         } else if (!strncmp(argv[1], "UUID=", 5)) {
45                 tk = "UUID";
46                 vl = argv[1] + 5;
47         } else if (!strcmp(argv[1], "-h") == 0 ||
48                    !strcmp(argv[1], "--help") == 0) {
49                 usage(EXIT_SUCCESS);
50         } else
51                 usage(2);
52
53         dev = blkid_evaluate_tag(tk, vl, NULL);
54         if (!dev)
55                 errx(EXIT_FAILURE, _("unable to resolve '%s'"), argv[1]);
56
57         puts(dev);
58         exit(EXIT_SUCCESS);
59 }
60