+ error("realpath(%s) failed: %s", tomnt, strerror(-ret));
+ goto out;
+ }
+ rctx->dest_dir_fd = open(dest_dir_full_path, O_RDONLY | O_NOATIME);
+ if (rctx->dest_dir_fd < 0) {
+ ret = -errno;
+ error("cannot open destination directory %s: %s",
+ dest_dir_full_path, strerror(-ret));
+ goto out;
+ }
+
+ if (realmnt[0]) {
+ rctx->root_path = realmnt;
+ } else {
+ ret = find_mount_root(dest_dir_full_path, &rctx->root_path);
+ if (ret < 0) {
+ error("failed to determine mount point for %s: %s",
+ dest_dir_full_path, strerror(-ret));
+ ret = -EINVAL;
+ goto out;
+ }
+ if (ret > 0) {
+ error("%s doesn't belong to btrfs mount point",
+ dest_dir_full_path);
+ ret = -EINVAL;
+ goto out;
+ }
+ }
+ rctx->mnt_fd = open(rctx->root_path, O_RDONLY | O_NOATIME);
+ if (rctx->mnt_fd < 0) {
+ ret = -errno;
+ error("cannot open %s: %s", rctx->root_path, strerror(-ret));
+ goto out;
+ }
+
+ /*
+ * If we use -m or a default subvol we want to resolve the path to the
+ * subvolume we're sitting in so that we can adjust the paths of any
+ * subvols we want to receive in.
+ */
+ ret = btrfs_list_get_path_rootid(rctx->mnt_fd, &subvol_id);
+ if (ret)
+ goto out;
+
+ root_subvol_path[0] = 0;
+ ret = btrfs_subvolid_resolve(rctx->mnt_fd, root_subvol_path,
+ PATH_MAX, subvol_id);
+ if (ret) {
+ error("cannot resolve our subvol path");