3
0

findfs.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. //usage:#define findfs_trivial_usage
  11. //usage: "LABEL=label or UUID=uuid"
  12. //usage:#define findfs_full_usage "\n\n"
  13. //usage: "Find a filesystem device based on a label or UUID"
  14. //usage:
  15. //usage:#define findfs_example_usage
  16. //usage: "$ findfs LABEL=MyDevice"
  17. #include "libbb.h"
  18. #include "volume_id.h"
  19. int findfs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  20. int findfs_main(int argc UNUSED_PARAM, char **argv)
  21. {
  22. char *dev = *++argv;
  23. if (!dev)
  24. bb_show_usage();
  25. if (strncmp(dev, "/dev/", 5) == 0) {
  26. /* Just pass any /dev/xxx name right through.
  27. * This might aid in some scripts being able
  28. * to call this unconditionally */
  29. dev = NULL;
  30. } else {
  31. /* Otherwise, handle LABEL=xxx and UUID=xxx,
  32. * fail on anything else */
  33. if (!resolve_mount_spec(argv))
  34. bb_show_usage();
  35. }
  36. if (*argv != dev) {
  37. puts(*argv);
  38. return 0;
  39. }
  40. return 1;
  41. }