match_fstype.c 879 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. int len;
  18. if (!t_fstype)
  19. return match;
  20. if (t_fstype[0] == 'n' && t_fstype[1] == 'o') {
  21. match--;
  22. t_fstype += 2;
  23. }
  24. len = strlen(mt->mnt_type);
  25. while (1) {
  26. if (strncmp(mt->mnt_type, t_fstype, len) == 0
  27. && (t_fstype[len] == '\0' || t_fstype[len] == ',')
  28. ) {
  29. return match;
  30. }
  31. t_fstype = strchr(t_fstype, ',');
  32. if (!t_fstype)
  33. break;
  34. t_fstype++;
  35. }
  36. return !match;
  37. }
  38. #endif /* HAVE_MNTENT_H */