]> git.ipfire.org Git - thirdparty/util-linux.git/blame - misc-utils/findfs.c
chsh: keep struct options in .rodata
[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"
753d9bb2
SK
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 */
940817b7
KZ
23
24static void __attribute__((__noreturn__)) usage(int rc)
25{
efe030d6
SK
26 FILE *out = rc ? stderr : stdout;
27 fputs(USAGE_HEADER, out);
c48508c2 28 fprintf(out, _(" %s [options] {LABEL,UUID,PARTUUID,PARTLABEL}=<value>\n"),
efe030d6
SK
29 program_invocation_short_name);
30 fputs(USAGE_OPTIONS, out);
31 fputs(USAGE_HELP, out);
32 fputs(USAGE_VERSION, out);
33 fprintf(out, USAGE_MAN_TAIL("findfs(8)"));
940817b7
KZ
34 exit(rc);
35}
36
37int main(int argc, char **argv)
38{
c48508c2 39 char *dev;
940817b7
KZ
40
41 setlocale(LC_ALL, "");
42 bindtextdomain(PACKAGE, LOCALEDIR);
43 textdomain(PACKAGE);
c05a80ca 44 atexit(close_stdout);
940817b7
KZ
45
46 if (argc != 2)
47 /* we return '2' for backward compatibility
48 * with version from e2fsprogs */
753d9bb2 49 usage(FINDFS_USAGE_ERROR);
940817b7 50
c48508c2 51 if (strcmp(argv[1], "-V") == 0 ||
efe030d6
SK
52 strcmp(argv[1], "--version") == 0) {
53 printf(UTIL_LINUX_VERSION);
753d9bb2 54 return FINDFS_SUCCESS;
efe030d6
SK
55 } else if (strcmp(argv[1], "-h") == 0 ||
56 strcmp(argv[1], "--help") == 0) {
753d9bb2 57 usage(FINDFS_SUCCESS);
c48508c2 58 } else if (argv[1][0] == '-')
753d9bb2 59 usage(FINDFS_USAGE_ERROR);
940817b7 60
c48508c2 61 dev = blkid_evaluate_tag(argv[1], NULL, NULL);
940817b7 62 if (!dev)
753d9bb2 63 errx(FINDFS_NOT_FOUND, _("unable to resolve '%s'"), argv[1]);
940817b7
KZ
64
65 puts(dev);
753d9bb2 66 return FINDFS_SUCCESS;
940817b7
KZ
67}
68