findfs.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 kb)"
  12. //config: default y
  13. //config: select VOLUMEID
  14. //config: help
  15. //config: Prints the name of a filesystem with given label or UUID.
  16. /* Benefits from suid root: better access to /dev/BLOCKDEVs: */
  17. //applet:IF_FINDFS(APPLET(findfs, BB_DIR_SBIN, BB_SUID_MAYBE))
  18. //kbuild:lib-$(CONFIG_FINDFS) += findfs.o
  19. //usage:#define findfs_trivial_usage
  20. //usage: "LABEL=label or UUID=uuid"
  21. //usage:#define findfs_full_usage "\n\n"
  22. //usage: "Find a filesystem device based on a label or UUID"
  23. //usage:
  24. //usage:#define findfs_example_usage
  25. //usage: "$ findfs LABEL=MyDevice"
  26. #include "libbb.h"
  27. #include "volume_id.h"
  28. int findfs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  29. int findfs_main(int argc UNUSED_PARAM, char **argv)
  30. {
  31. char *dev = *++argv;
  32. if (!dev)
  33. bb_show_usage();
  34. if (is_prefixed_with(dev, "/dev/")) {
  35. /* Just pass any /dev/xxx name right through.
  36. * This might aid in some scripts being able
  37. * to call this unconditionally */
  38. dev = NULL;
  39. } else {
  40. /* Otherwise, handle LABEL=xxx and UUID=xxx,
  41. * fail on anything else */
  42. if (!resolve_mount_spec(argv))
  43. bb_show_usage();
  44. }
  45. if (*argv != dev) {
  46. puts(*argv);
  47. return 0;
  48. }
  49. return 1;
  50. }