blob: 7ca9dc96b73e07215cc3b94e7cbeafe5769bd70b [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 Vlasenkob097a842018-12-28 03:20:17 +010011//config: bool "findfs (12 kb)"
Denys Vlasenkodd898c92016-11-23 11:46:32 +010012//config: default y
13//config: select PLATFORM_LINUX
14//config: select VOLUMEID
15//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020016//config: Prints the name of a filesystem with given label or UUID.
Denys Vlasenkodd898c92016-11-23 11:46:32 +010017
18/* Benefits from suid root: better access to /dev/BLOCKDEVs: */
19//applet:IF_FINDFS(APPLET(findfs, BB_DIR_SBIN, BB_SUID_MAYBE))
20
21//kbuild:lib-$(CONFIG_FINDFS) += findfs.o
Denis Vlasenkode7684a2008-02-18 21:08:49 +000022
Pere Orga5bc8c002011-04-11 03:29:49 +020023//usage:#define findfs_trivial_usage
24//usage: "LABEL=label or UUID=uuid"
25//usage:#define findfs_full_usage "\n\n"
26//usage: "Find a filesystem device based on a label or UUID"
27//usage:
28//usage:#define findfs_example_usage
29//usage: "$ findfs LABEL=MyDevice"
30
Denis Vlasenkode7684a2008-02-18 21:08:49 +000031#include "libbb.h"
32#include "volume_id.h"
33
34int findfs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Natanael Copa9aff2992009-09-20 04:28:22 +020035int findfs_main(int argc UNUSED_PARAM, char **argv)
Denis Vlasenkode7684a2008-02-18 21:08:49 +000036{
Natanael Copa9aff2992009-09-20 04:28:22 +020037 char *dev = *++argv;
Denis Vlasenkode7684a2008-02-18 21:08:49 +000038
Natanael Copa9aff2992009-09-20 04:28:22 +020039 if (!dev)
Denis Vlasenko53ce7f02008-02-19 11:29:46 +000040 bb_show_usage();
Denis Vlasenkode7684a2008-02-18 21:08:49 +000041
Denys Vlasenko8dff01d2015-03-12 17:48:34 +010042 if (is_prefixed_with(dev, "/dev/")) {
Natanael Copa9aff2992009-09-20 04:28:22 +020043 /* Just pass any /dev/xxx name right through.
44 * This might aid in some scripts being able
45 * to call this unconditionally */
46 dev = NULL;
47 } else {
48 /* Otherwise, handle LABEL=xxx and UUID=xxx,
49 * fail on anything else */
50 if (!resolve_mount_spec(argv))
51 bb_show_usage();
52 }
Denis Vlasenko53ce7f02008-02-19 11:29:46 +000053
Natanael Copa9aff2992009-09-20 04:28:22 +020054 if (*argv != dev) {
55 puts(*argv);
Denis Vlasenkode7684a2008-02-18 21:08:49 +000056 return 0;
57 }
58 return 1;
Denis Vlasenko53ce7f02008-02-19 11:29:46 +000059}