Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 1 | /* 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 Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 9 | */ |
Denys Vlasenko | dd898c9 | 2016-11-23 11:46:32 +0100 | [diff] [blame] | 10 | //config:config FINDFS |
Denys Vlasenko | 4eed2c6 | 2017-07-18 22:01:24 +0200 | [diff] [blame] | 11 | //config: bool "findfs (11 kb)" |
Denys Vlasenko | dd898c9 | 2016-11-23 11:46:32 +0100 | [diff] [blame] | 12 | //config: default y |
| 13 | //config: select PLATFORM_LINUX |
| 14 | //config: select VOLUMEID |
| 15 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 16 | //config: Prints the name of a filesystem with given label or UUID. |
Denys Vlasenko | dd898c9 | 2016-11-23 11:46:32 +0100 | [diff] [blame] | 17 | |
| 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 Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 22 | |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 23 | //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 Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 31 | #include "libbb.h" |
| 32 | #include "volume_id.h" |
| 33 | |
| 34 | int findfs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Natanael Copa | 9aff299 | 2009-09-20 04:28:22 +0200 | [diff] [blame] | 35 | int findfs_main(int argc UNUSED_PARAM, char **argv) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 36 | { |
Natanael Copa | 9aff299 | 2009-09-20 04:28:22 +0200 | [diff] [blame] | 37 | char *dev = *++argv; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 38 | |
Natanael Copa | 9aff299 | 2009-09-20 04:28:22 +0200 | [diff] [blame] | 39 | if (!dev) |
Denis Vlasenko | 53ce7f0 | 2008-02-19 11:29:46 +0000 | [diff] [blame] | 40 | bb_show_usage(); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 41 | |
Denys Vlasenko | 8dff01d | 2015-03-12 17:48:34 +0100 | [diff] [blame] | 42 | if (is_prefixed_with(dev, "/dev/")) { |
Natanael Copa | 9aff299 | 2009-09-20 04:28:22 +0200 | [diff] [blame] | 43 | /* 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 Vlasenko | 53ce7f0 | 2008-02-19 11:29:46 +0000 | [diff] [blame] | 53 | |
Natanael Copa | 9aff299 | 2009-09-20 04:28:22 +0200 | [diff] [blame] | 54 | if (*argv != dev) { |
| 55 | puts(*argv); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 56 | return 0; |
| 57 | } |
| 58 | return 1; |
Denis Vlasenko | 53ce7f0 | 2008-02-19 11:29:46 +0000 | [diff] [blame] | 59 | } |