Return any bind mounted source for a path. The caller should not free the returned buffer. Return NULL if no bind mount found. */
| 947 | The caller should not free the returned buffer. |
| 948 | Return NULL if no bind mount found. */ |
| 949 | NODISCARD |
| 950 | static char const * |
| 951 | find_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. */ |
| 988 | NODISCARD |