blob: f5621a1fa9b9f4eef5b9041dbccc8db7bd780ce0 [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
Denys Vlasenkodd898c92016-11-23 11:46:32 +010013//config: select VOLUMEID
14//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020015//config: Prints the name of a filesystem with given label or UUID.
Denys Vlasenkodd898c92016-11-23 11:46:32 +010016
17/* Benefits from suid root: better access to /dev/BLOCKDEVs: */
18//applet:IF_FINDFS(APPLET(findfs, BB_DIR_SBIN, BB_SUID_MAYBE))
19
20//kbuild:lib-$(CONFIG_FINDFS) += findfs.o
Denis Vlasenkode7684a2008-02-18 21:08:49 +000021
Pere Orga5bc8c002011-04-11 03:29:49 +020022//usage:#define findfs_trivial_usage
23//usage: "LABEL=label or UUID=uuid"
24//usage:#define findfs_full_usage "\n\n"
25//usage: "Find a filesystem device based on a label or UUID"
26//usage:
27//usage:#define findfs_example_usage
28//usage: "$ findfs LABEL=MyDevice"
29
Denis Vlasenkode7684a2008-02-18 21:08:49 +000030#include "libbb.h"
31#include "volume_id.h"
32
33int findfs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Natanael Copa9aff2992009-09-20 04:28:22 +020034int findfs_main(int argc UNUSED_PARAM, char **argv)
Denis Vlasenkode7684a2008-02-18 21:08:49 +000035{
Natanael Copa9aff2992009-09-20 04:28:22 +020036 char *dev = *++argv;
Denis Vlasenkode7684a2008-02-18 21:08:49 +000037
Natanael Copa9aff2992009-09-20 04:28:22 +020038 if (!dev)
Denis Vlasenko53ce7f02008-02-19 11:29:46 +000039 bb_show_usage();
Denis Vlasenkode7684a2008-02-18 21:08:49 +000040
Denys Vlasenko8dff01d2015-03-12 17:48:34 +010041 if (is_prefixed_with(dev, "/dev/")) {
Natanael Copa9aff2992009-09-20 04:28:22 +020042 /* Just pass any /dev/xxx name right through.
43 * This might aid in some scripts being able
44 * to call this unconditionally */
45 dev = NULL;
46 } else {
47 /* Otherwise, handle LABEL=xxx and UUID=xxx,
48 * fail on anything else */
49 if (!resolve_mount_spec(argv))
50 bb_show_usage();
51 }
Denis Vlasenko53ce7f02008-02-19 11:29:46 +000052
Natanael Copa9aff2992009-09-20 04:28:22 +020053 if (*argv != dev) {
54 puts(*argv);
Denis Vlasenkode7684a2008-02-18 21:08:49 +000055 return 0;
56 }
57 return 1;
Denis Vlasenko53ce7f02008-02-19 11:29:46 +000058}