+
+ if (parent) {
+ fd = open_by_handle_at(mount_fd, &dir_handle.fh, O_RDONLY|O_DIRECTORY);
+ if (fd >= 0) {
+ if (!nlink) {
+ printf("open_by_handle(%s) opened an unlinked dir!\n", dname);
+ return EXIT_FAILURE;
+ } else if (rd) {
+ /*
+ * Sanity check dir fd - expect to access orig file IFF
+ * it was not unlinked nor renamed.
+ */
+ strcpy(fname, "file000000");
+ ret = faccessat(fd, fname, F_OK, 0);
+ if ((ret == 0) != (!delete && !move) ||
+ ((ret < 0) && errno != ENOENT)) {
+ strcat(fname, ": unexpected result from faccessat");
+ perror(fname);
+ return EXIT_FAILURE;
+ }
+ /*
+ * Expect to access link file if ran test with -l flag
+ * (nlink > 1), -m flag (orig moved to link name) or
+ * -u flag (which implied previous -l run).
+ */
+ strcpy(fname2, "link000000");
+ ret = faccessat(fd, fname2, F_OK, 0);
+ if (ret < 0 && (nlink > 1 || delete || move ||
+ errno != ENOENT)) {
+ strcat(fname2, ": unexpected result from faccessat");
+ perror(fname2);
+ return EXIT_FAILURE;
+ }
+ }
+ close(fd);
+ } else if (nlink || !(errno == ENOENT || errno == ESTALE)) {
+ printf("open_by_handle(%s) returned %d incorrectly on %s dir!\n",
+ dname, errno,
+ nlink ? "a linked" : "an unlinked");
+ return EXIT_FAILURE;
+ }
+ }
+