blob: b9cd95687b7dc366804f76efb85f1eb3bdc655e3 [file] [log] [blame]
Denis Vlasenkode7684a2008-02-18 21:08:49 +00001/* vi: set sw=4 ts=4: */
2/*
3 * Support functions for mounting devices by label/uuid
4 *
5 * Copyright (C) 2006 by Jason Schoon <floydpink@gmail.com>
6 * Some portions cribbed from e2fsprogs, util-linux, dosfstools
7 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02008 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Denis Vlasenkode7684a2008-02-18 21:08:49 +00009 */
Denys Vlasenkodd898c92016-11-23 11:46:32 +010010//config:config FINDFS
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020011//config: bool "findfs (11 kb)"
Denys Vlasenkodd898c92016-11-23 11:46:32 +010012//config: default y
13//config: select PLATFORM_LINUX
14//config: select VOLUMEID
15//config: help
16//config: Prints the name of a filesystem with given label or UUID.
17//config: WARNING:
18//config: With all submodules selected, it will add ~8k to busybox.
19
20/* Benefits from suid root: better access to /dev/BLOCKDEVs: */
21//applet:IF_FINDFS(APPLET(findfs, BB_DIR_SBIN, BB_SUID_MAYBE))
22
23//kbuild:lib-$(CONFIG_FINDFS) += findfs.o
Denis Vlasenkode7684a2008-02-18 21:08:49 +000024
Pere Orga5bc8c002011-04-11 03:29:49 +020025//usage:#define findfs_trivial_usage
26//usage: "LABEL=label or UUID=uuid"
27//usage:#define findfs_full_usage "\n\n"
28//usage: "Find a filesystem device based on a label or UUID"
29//usage:
30//usage:#define findfs_example_usage
31//usage: "$ findfs LABEL=MyDevice"
32
Denis Vlasenkode7684a2008-02-18 21:08:49 +000033#include "libbb.h"
34#include "volume_id.h"
35
36int findfs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Natanael Copa9aff2992009-09-20 04:28:22 +020037int findfs_main(int argc UNUSED_PARAM, char **argv)
Denis Vlasenkode7684a2008-02-18 21:08:49 +000038{
Natanael Copa9aff2992009-09-20 04:28:22 +020039 char *dev = *++argv;
Denis Vlasenkode7684a2008-02-18 21:08:49 +000040
Natanael Copa9aff2992009-09-20 04:28:22 +020041 if (!dev)
Denis Vlasenko53ce7f02008-02-19 11:29:46 +000042 bb_show_usage();
Denis Vlasenkode7684a2008-02-18 21:08:49 +000043
Denys Vlasenko8dff01d2015-03-12 17:48:34 +010044 if (is_prefixed_with(dev, "/dev/")) {
Natanael Copa9aff2992009-09-20 04:28:22 +020045 /* Just pass any /dev/xxx name right through.
46 * This might aid in some scripts being able
47 * to call this unconditionally */
48 dev = NULL;
49 } else {
50 /* Otherwise, handle LABEL=xxx and UUID=xxx,
51 * fail on anything else */
52 if (!resolve_mount_spec(argv))
53 bb_show_usage();
54 }
Denis Vlasenko53ce7f02008-02-19 11:29:46 +000055
Natanael Copa9aff2992009-09-20 04:28:22 +020056 if (*argv != dev) {
57 puts(*argv);
Denis Vlasenkode7684a2008-02-18 21:08:49 +000058 return 0;
59 }
60 return 1;
Denis Vlasenko53ce7f02008-02-19 11:29:46 +000061}