+ if (in_fd) {
+ ret = read(in_fd, (char *)&handle[i], sizeof(*handle));
+ if (ret < sizeof(*handle)) {
+ fprintf(stderr, "failed reading file handle #%d from '%s'\n", i, infile);
+ return EXIT_FAILURE;
+ }
+ } else {
+ handle[i].fh.handle_bytes = MAX_HANDLE_SZ;
+ ret = name_to_handle_at(AT_FDCWD, fname, &handle[i].fh, &mount_id, 0);
+ if (ret < 0) {
+ strcat(fname, ": name_to_handle");
+ perror(fname);
+ return EXIT_FAILURE;
+ }
+ }
+ if (keepopen) {
+ /* Open without close to keep unlinked files around */
+ fd = open(fname, O_RDONLY);
+ if (fd < 0) {
+ strcat(fname, ": open(O_RDONLY)");
+ perror(fname);
+ return EXIT_FAILURE;
+ }
+ }
+ if (out_fd) {
+ ret = write(out_fd, (char *)&handle[i], sizeof(*handle));
+ if (ret < sizeof(*handle)) {
+ fprintf(stderr, "failed writing file handle #%d to '%s'\n", i, outfile);
+ return EXIT_FAILURE;
+ }
+ }
+ }
+
+ if (parent) {
+ if (in_fd) {
+ ret = read(in_fd, (char *)&dir_handle, sizeof(*handle));
+ if (ret < sizeof(*handle)) {
+ fprintf(stderr, "failed reading dir file handle from '%s'\n", infile);
+ return EXIT_FAILURE;
+ }
+ } else {
+ dir_handle.fh.handle_bytes = MAX_HANDLE_SZ;
+ ret = name_to_handle_at(AT_FDCWD, test_dir, &dir_handle.fh, &mount_id, 0);
+ if (ret < 0) {
+ strcat(dname, ": name_to_handle");
+ perror(dname);
+ return EXIT_FAILURE;
+ }
+ }
+ if (out_fd) {
+ ret = write(out_fd, (char *)&dir_handle, sizeof(*handle));
+ if (ret < sizeof(*handle)) {
+ fprintf(stderr, "failed writing dir file handle to '%s'\n", outfile);
+ return EXIT_FAILURE;
+ }
+ }
+ }
+
+ /* write data to files */
+ for (i=0; wr && i < numfiles; i++) {
+ sprintf(fname, "%s/file%06d", test_dir, i);
+ fd = open(fname, O_WRONLY, 0644);
+ if (fd < 0) {
+ strcat(fname, ": open");