]> git.ipfire.org Git - thirdparty/util-linux.git/blame - misc-utils/findfs.c
Merge branch 'meson-more-build-options' of https://github.com/jwillikers/util-linux
[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>
0e1fa6b6 11#include <getopt.h>
940817b7
KZ
12
13#include <blkid.h>
14
15#include "nls.h"
c05a80ca 16#include "closestream.h"
eb76ca98 17#include "c.h"
753d9bb2
SK
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 */
940817b7 23
5118d1be 24static void __attribute__((__noreturn__)) usage(void)
940817b7 25{
5118d1be 26 FILE *out = stdout;
efe030d6 27 fputs(USAGE_HEADER, out);
c48508c2 28 fprintf(out, _(" %s [options] {LABEL,UUID,PARTUUID,PARTLABEL}=<value>\n"),
efe030d6 29 program_invocation_short_name);
451dbcfa
BS
30
31 fputs(USAGE_SEPARATOR, out);
32 fputs(_("Find a filesystem by label or UUID.\n"), out);
33
efe030d6 34 fputs(USAGE_OPTIONS, out);
bad4c729
MY
35 fprintf(out, USAGE_HELP_OPTIONS(16));
36 fprintf(out, USAGE_MAN_TAIL("findfs(8)"));
5118d1be 37 exit(FINDFS_SUCCESS);
940817b7
KZ
38}
39
40int main(int argc, char **argv)
41{
c48508c2 42 char *dev;
0e1fa6b6
SK
43 int c;
44 static const struct option longopts[] = {
45 {"version", no_argument, NULL, 'V'},
46 {"help", no_argument, NULL, 'h'},
47 {NULL, 0, NULL, 0}
48 };
940817b7
KZ
49
50 setlocale(LC_ALL, "");
51 bindtextdomain(PACKAGE, LOCALEDIR);
52 textdomain(PACKAGE);
2c308875 53 close_stdout_atexit();
940817b7 54
5118d1be 55 if (argc != 2) {
940817b7
KZ
56 /* we return '2' for backward compatibility
57 * with version from e2fsprogs */
5118d1be
RM
58 warnx(_("bad usage"));
59 errtryhelp(FINDFS_USAGE_ERROR);
60 }
940817b7 61
0e1fa6b6
SK
62 while ((c = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
63 switch (c) {
64 case 'V':
2c308875 65 print_version(FINDFS_SUCCESS);
0e1fa6b6 66 case 'h':
5118d1be 67 usage();
0e1fa6b6 68 default:
05691d9e 69 errtryhelp(FINDFS_USAGE_ERROR);
0e1fa6b6 70 }
940817b7 71
c48508c2 72 dev = blkid_evaluate_tag(argv[1], NULL, NULL);
940817b7 73 if (!dev)
753d9bb2 74 errx(FINDFS_NOT_FOUND, _("unable to resolve '%s'"), argv[1]);
940817b7
KZ
75
76 puts(dev);
753d9bb2 77 return FINDFS_SUCCESS;
940817b7 78}