MCPcopy Create free account
hub / github.com/coreutils/coreutils / find_bind_mount

Function find_bind_mount

src/stat.c:949–985  ·  view source on GitHub ↗

Return any bind mounted source for a path. The caller should not free the returned buffer. Return NULL if no bind mount found. */

Source from the content-addressed store, hash-verified

947 The caller should not free the returned buffer.
948 Return NULL if no bind mount found. */
949NODISCARD
950static char const *
951find_bind_mount (char const * name)
952{
953 char const * bind_mount = NULL;
954
955 static struct mount_entry *mount_list;
956 static bool tried_mount_list = false;
957 if (!tried_mount_list) /* attempt/warn once per process. */
958 {
959 if (!(mount_list = read_file_system_list (false)))
960 error (0, errno, "%s", _("cannot read table of mounted file systems"));
961 tried_mount_list = true;
962 }
963
964 struct stat name_stats;
965 if (stat (name, &name_stats) != 0)
966 return NULL;
967
968 for (struct mount_entry *me = mount_list; me; me = me->me_next)
969 {
970 if (me->me_dummy && me->me_devname[0] == '/'
971 && streq (me->me_mountdir, name))
972 {
973 struct stat dev_stats;
974
975 if (stat (me->me_devname, &dev_stats) == 0
976 && psame_inode (&name_stats, &dev_stats))
977 {
978 bind_mount = me->me_devname;
979 break;
980 }
981 }
982 }
983
984 return bind_mount;
985}
986
987/* Print mount point. Return zero upon success, nonzero upon failure. */
988NODISCARD

Callers 1

out_mount_pointFunction · 0.85

Calls 1

statClass · 0.70

Tested by

no test coverage detected