findfs.c 1.5 KB

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