blob: 49e8979acf0b85b2120fa174f672b4baa6e4bdab [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 */
10
Pere Orga5bc8c002011-04-11 03:29:49 +020011//usage:#define findfs_trivial_usage
12//usage: "LABEL=label or UUID=uuid"
13//usage:#define findfs_full_usage "\n\n"
14//usage: "Find a filesystem device based on a label or UUID"
15//usage:
16//usage:#define findfs_example_usage
17//usage: "$ findfs LABEL=MyDevice"
18
Denis Vlasenkode7684a2008-02-18 21:08:49 +000019#include "libbb.h"
20#include "volume_id.h"
21
22int findfs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Natanael Copa9aff2992009-09-20 04:28:22 +020023int findfs_main(int argc UNUSED_PARAM, char **argv)
Denis Vlasenkode7684a2008-02-18 21:08:49 +000024{
Natanael Copa9aff2992009-09-20 04:28:22 +020025 char *dev = *++argv;
Denis Vlasenkode7684a2008-02-18 21:08:49 +000026
Natanael Copa9aff2992009-09-20 04:28:22 +020027 if (!dev)
Denis Vlasenko53ce7f02008-02-19 11:29:46 +000028 bb_show_usage();
Denis Vlasenkode7684a2008-02-18 21:08:49 +000029
Natanael Copa9aff2992009-09-20 04:28:22 +020030 if (strncmp(dev, "/dev/", 5) == 0) {
31 /* Just pass any /dev/xxx name right through.
32 * This might aid in some scripts being able
33 * to call this unconditionally */
34 dev = NULL;
35 } else {
36 /* Otherwise, handle LABEL=xxx and UUID=xxx,
37 * fail on anything else */
38 if (!resolve_mount_spec(argv))
39 bb_show_usage();
40 }
Denis Vlasenko53ce7f02008-02-19 11:29:46 +000041
Natanael Copa9aff2992009-09-20 04:28:22 +020042 if (*argv != dev) {
43 puts(*argv);
Denis Vlasenkode7684a2008-02-18 21:08:49 +000044 return 0;
45 }
46 return 1;
Denis Vlasenko53ce7f02008-02-19 11:29:46 +000047}