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