1
0

200-mnt_path_check.patch 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. --- a/lib/sysfs_utils.c
  2. +++ b/lib/sysfs_utils.c
  3. @@ -22,6 +22,7 @@
  4. */
  5. #include "libsysfs.h"
  6. #include "sysfs.h"
  7. +#include <mntent.h>
  8. /**
  9. * sysfs_remove_trailing_slash: Removes any trailing '/' in the given path
  10. @@ -53,6 +54,9 @@ int sysfs_get_mnt_path(char *mnt_path, s
  11. {
  12. static char sysfs_path[SYSFS_PATH_MAX] = "";
  13. const char *sysfs_path_env;
  14. + FILE *mnt;
  15. + struct mntent *mntent;
  16. + int ret;
  17. if (len == 0 || mnt_path == NULL)
  18. return -1;
  19. @@ -64,12 +68,31 @@ int sysfs_get_mnt_path(char *mnt_path, s
  20. if (sysfs_path_env != NULL) {
  21. safestrcpymax(mnt_path, sysfs_path_env, len);
  22. sysfs_remove_trailing_slash(mnt_path);
  23. - return 0;
  24. + } else {
  25. + safestrcpymax(mnt_path, SYSFS_MNT_PATH, len);
  26. }
  27. - safestrcpymax(mnt_path, SYSFS_MNT_PATH, len);
  28. }
  29. - return 0;
  30. + /* check that mount point is indeed mounted */
  31. + ret = -1;
  32. + if ((mnt = setmntent(SYSFS_PROC_MNTS, "r")) == NULL) {
  33. + dprintf("Error getting mount information\n");
  34. + return -1;
  35. + }
  36. + while ((mntent = getmntent(mnt)) != NULL) {
  37. + if (strcmp(mntent->mnt_type, SYSFS_FSTYPE_NAME) == 0 &&
  38. + strcmp(mntent->mnt_dir, mnt_path) == 0) {
  39. + ret = 0;
  40. + break;
  41. + }
  42. + }
  43. +
  44. + endmntent(mnt);
  45. +
  46. + if (ret < 0)
  47. + errno = ENOENT;
  48. +
  49. + return ret;
  50. }
  51. /**