match_fstype.c 837 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 tarball for details.
  11. */
  12. #include "libbb.h"
  13. int FAST_FUNC match_fstype(const struct mntent *mt, const char *t_fstype)
  14. {
  15. int match = 1;
  16. int len;
  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. len = strlen(mt->mnt_type);
  24. while (1) {
  25. if (strncmp(mt->mnt_type, t_fstype, len) == 0
  26. && (t_fstype[len] == '\0' || t_fstype[len] == ',')
  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. }