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 | */ |
| 10 | |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 11 | //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 Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 19 | #include "libbb.h" |
| 20 | #include "volume_id.h" |
| 21 | |
| 22 | int findfs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Natanael Copa | 9aff299 | 2009-09-20 04:28:22 +0200 | [diff] [blame] | 23 | int findfs_main(int argc UNUSED_PARAM, char **argv) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 24 | { |
Natanael Copa | 9aff299 | 2009-09-20 04:28:22 +0200 | [diff] [blame] | 25 | char *dev = *++argv; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 26 | |
Natanael Copa | 9aff299 | 2009-09-20 04:28:22 +0200 | [diff] [blame] | 27 | if (!dev) |
Denis Vlasenko | 53ce7f0 | 2008-02-19 11:29:46 +0000 | [diff] [blame] | 28 | bb_show_usage(); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 29 | |
Natanael Copa | 9aff299 | 2009-09-20 04:28:22 +0200 | [diff] [blame] | 30 | 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 Vlasenko | 53ce7f0 | 2008-02-19 11:29:46 +0000 | [diff] [blame] | 41 | |
Natanael Copa | 9aff299 | 2009-09-20 04:28:22 +0200 | [diff] [blame] | 42 | if (*argv != dev) { |
| 43 | puts(*argv); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 44 | return 0; |
| 45 | } |
| 46 | return 1; |
Denis Vlasenko | 53ce7f0 | 2008-02-19 11:29:46 +0000 | [diff] [blame] | 47 | } |