findfs.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. *
  8. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  9. */
  10. //config:config FINDFS
  11. //config: bool "findfs"
  12. //config: default y
  13. //config: select PLATFORM_LINUX
  14. //config: select VOLUMEID
  15. //config: help
  16. //config: Prints the name of a filesystem with given label or UUID.
  17. //config: WARNING:
  18. //config: With all submodules selected, it will add ~8k to busybox.
  19. /* Benefits from suid root: better access to /dev/BLOCKDEVs: */
  20. //applet:IF_FINDFS(APPLET(findfs, BB_DIR_SBIN, BB_SUID_MAYBE))
  21. //kbuild:lib-$(CONFIG_FINDFS) += findfs.o
  22. //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. #include "libbb.h"
  30. #include "volume_id.h"
  31. int findfs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  32. int findfs_main(int argc UNUSED_PARAM, char **argv)
  33. {
  34. char *dev = *++argv;
  35. if (!dev)
  36. bb_show_usage();
  37. if (is_prefixed_with(dev, "/dev/")) {
  38. /* Just pass any /dev/xxx name right through.
  39. * This might aid in some scripts being able
  40. * to call this unconditionally */
  41. dev = NULL;
  42. } else {
  43. /* Otherwise, handle LABEL=xxx and UUID=xxx,
  44. * fail on anything else */
  45. if (!resolve_mount_spec(argv))
  46. bb_show_usage();
  47. }
  48. if (*argv != dev) {
  49. puts(*argv);
  50. return 0;
  51. }
  52. return 1;
  53. }