+ if (dev != lastdev) {
+ /*
+ * We have crossed a mountpoint. For volumes like UDF
+ * the getattrlist name may not match the actual
+ * mountpoint, so we just copy the mountpoint directly.
+ * (3703138). However, the mountpoint may not be
+ * accessible, as when chroot-ed, so check first.
+ * There may be a file on the chroot-ed volume with
+ * the same name as the mountpoint, so compare device
+ * and inode numbers.
+ */
+ lastdev = dev;
+ if (statfs(resolved, &sfs) == 0 && lstat(sfs.f_mntonname, &sb) == 0 && dev == sb.st_dev && inode == sb.st_ino) {
+ /*
+ * However, it's possible that the mountpoint
+ * path matches, even though it isn't the real
+ * path in the chroot-ed environment, so check
+ * that each component of the mountpoint
+ * is a directory (and not a symlink)
+ */
+ char temp[sizeof(sfs.f_mntonname)];
+ char *cp;
+ int ok = 1;
+
+ strcpy(temp, sfs.f_mntonname);
+ for(;;) {
+ if ((cp = strrchr(temp, '/')) == NULL) {
+ ok = 0;
+ break;
+ }
+ if (cp <= temp)
+ break;
+ *cp = 0;
+ if (lstat(temp, &sb) < 0 || (sb.st_mode & S_IFMT) != S_IFDIR) {
+ ok = 0;
+ break;
+ }
+ }
+ if (ok) {
+ resolved_len = strlcpy(resolved, sfs.f_mntonname, PATH_MAX);
+ continue;
+ }
+ }
+ /* if we fail, use the other methods. */
+ }
+ if (islink) {