]> git.ipfire.org Git - thirdparty/util-linux.git/blame - misc-utils/findfs.c
mcookie: add --max-size option
[thirdparty/util-linux.git] / misc-utils / findfs.c
CommitLineData
940817b7
KZ
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>
940817b7
KZ
11
12#include <blkid.h>
13
14#include "nls.h"
c05a80ca 15#include "closestream.h"
eb76ca98 16#include "c.h"
940817b7
KZ
17
18static void __attribute__((__noreturn__)) usage(int rc)
19{
efe030d6
SK
20 FILE *out = rc ? stderr : stdout;
21 fputs(USAGE_HEADER, out);
22 fprintf(out, _(" %1$s [options] LABEL=<label>\n"
23 " %1$s [options] UUID=<uuid>\n"),
24 program_invocation_short_name);
25 fputs(USAGE_OPTIONS, out);
26 fputs(USAGE_HELP, out);
27 fputs(USAGE_VERSION, out);
28 fprintf(out, USAGE_MAN_TAIL("findfs(8)"));
940817b7
KZ
29 exit(rc);
30}
31
32int main(int argc, char **argv)
33{
34 char *dev, *tk, *vl;
35
36 setlocale(LC_ALL, "");
37 bindtextdomain(PACKAGE, LOCALEDIR);
38 textdomain(PACKAGE);
c05a80ca 39 atexit(close_stdout);
940817b7
KZ
40
41 if (argc != 2)
42 /* we return '2' for backward compatibility
43 * with version from e2fsprogs */
44 usage(2);
45
46 if (!strncmp(argv[1], "LABEL=", 6)) {
47 tk = "LABEL";
48 vl = argv[1] + 6;
49 } else if (!strncmp(argv[1], "UUID=", 5)) {
50 tk = "UUID";
51 vl = argv[1] + 5;
efe030d6
SK
52 } else if (strcmp(argv[1], "-V") == 0 ||
53 strcmp(argv[1], "--version") == 0) {
54 printf(UTIL_LINUX_VERSION);
55 return EXIT_SUCCESS;
56 } else if (strcmp(argv[1], "-h") == 0 ||
57 strcmp(argv[1], "--help") == 0) {
940817b7
KZ
58 usage(EXIT_SUCCESS);
59 } else
60 usage(2);
61
cee95a95 62 dev = blkid_evaluate_tag(tk, vl, NULL);
940817b7
KZ
63 if (!dev)
64 errx(EXIT_FAILURE, _("unable to resolve '%s'"), argv[1]);
65
66 puts(dev);
67 exit(EXIT_SUCCESS);
68}
69