]> git.ipfire.org Git - thirdparty/util-linux.git/blob - misc-utils/findfs.c
textual: add a docstring to most of the utilities
[thirdparty/util-linux.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
12 #include <blkid.h>
13
14 #include "nls.h"
15 #include "closestream.h"
16 #include "c.h"
17 #include "exitcodes.h"
18
19 /* Exit codes used by findfs. */
20 #define FINDFS_SUCCESS 0 /* no errors */
21 #define FINDFS_NOT_FOUND 1 /* label or uuid cannot be found */
22 #define FINDFS_USAGE_ERROR 2 /* user did something unexpected */
23
24 static void __attribute__((__noreturn__)) usage(int rc)
25 {
26 FILE *out = rc ? stderr : stdout;
27 fputs(USAGE_HEADER, out);
28 fprintf(out, _(" %s [options] {LABEL,UUID,PARTUUID,PARTLABEL}=<value>\n"),
29 program_invocation_short_name);
30
31 fputs(USAGE_SEPARATOR, out);
32 fputs(_("Find a filesystem by label or UUID.\n"), out);
33
34 fputs(USAGE_OPTIONS, out);
35 fputs(USAGE_HELP, out);
36 fputs(USAGE_VERSION, out);
37 fprintf(out, USAGE_MAN_TAIL("findfs(8)"));
38 exit(rc);
39 }
40
41 int main(int argc, char **argv)
42 {
43 char *dev;
44
45 setlocale(LC_ALL, "");
46 bindtextdomain(PACKAGE, LOCALEDIR);
47 textdomain(PACKAGE);
48 atexit(close_stdout);
49
50 if (argc != 2)
51 /* we return '2' for backward compatibility
52 * with version from e2fsprogs */
53 usage(FINDFS_USAGE_ERROR);
54
55 if (strcmp(argv[1], "-V") == 0 ||
56 strcmp(argv[1], "--version") == 0) {
57 printf(UTIL_LINUX_VERSION);
58 return FINDFS_SUCCESS;
59 } else if (strcmp(argv[1], "-h") == 0 ||
60 strcmp(argv[1], "--help") == 0) {
61 usage(FINDFS_SUCCESS);
62 } else if (argv[1][0] == '-')
63 usage(FINDFS_USAGE_ERROR);
64
65 dev = blkid_evaluate_tag(argv[1], NULL, NULL);
66 if (!dev)
67 errx(FINDFS_NOT_FOUND, _("unable to resolve '%s'"), argv[1]);
68
69 puts(dev);
70 return FINDFS_SUCCESS;
71 }
72