match_fstype.c 884 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Match fstypes for use in mount unmount
  4. * We accept notmpfs,nfs but not notmpfs,nonfs
  5. * This allows us to match fstypes that start with no like so
  6. * mount -at ,noddy
  7. *
  8. * Returns 1 for a match, otherwise 0
  9. *
  10. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  11. */
  12. #include "libbb.h"
  13. #ifdef HAVE_MNTENT_H
  14. int FAST_FUNC match_fstype(const struct mntent *mt, const char *t_fstype)
  15. {
  16. int match = 1;
  17. if (!t_fstype)
  18. return match;
  19. if (t_fstype[0] == 'n' && t_fstype[1] == 'o') {
  20. match--;
  21. t_fstype += 2;
  22. }
  23. while (1) {
  24. char *after_mnt_type = is_prefixed_with(t_fstype, mt->mnt_type);
  25. if (after_mnt_type
  26. && (*after_mnt_type == '\0' || *after_mnt_type == ',')
  27. ) {
  28. return match;
  29. }
  30. t_fstype = strchr(t_fstype, ',');
  31. if (!t_fstype)
  32. break;
  33. t_fstype++;
  34. }
  35. return !match;
  36. }
  37. #endif /* HAVE_MNTENT_H */