- ret = get_subvol_info(fullpath, &get_ri);
- if (ret) {
- if (ret < 0) {
- error("Failed to get subvol info %s: %s",
- fullpath, strerror(-ret));
- } else {
- error("Failed to get subvol info %s: %d",
- fullpath, ret);
+ fd = open_file_or_dir(fullpath, &dirstream1);
+ if (fd < 0) {
+ error("can't access '%s'", fullpath);
+ goto out;
+ }
+
+ if (by_uuid) {
+ err = btrfs_util_create_subvolume_iterator_fd(fd,
+ BTRFS_FS_TREE_OBJECTID,
+ 0, &iter);
+ if (err) {
+ error_btrfs_util(err);
+ goto out;
+ }
+
+ for (;;) {
+ err = btrfs_util_subvolume_iterator_next_info(iter,
+ &subvol_path,
+ &subvol);
+ if (err == BTRFS_UTIL_ERROR_STOP_ITERATION) {
+ uuid_unparse(uuid_arg, uuidparse);
+ error("can't find uuid '%s' on '%s'", uuidparse,
+ fullpath);
+ btrfs_util_destroy_subvolume_iterator(iter);
+ goto out;
+ } else if (err) {
+ error_btrfs_util(err);
+ btrfs_util_destroy_subvolume_iterator(iter);
+ goto out;
+ }
+
+ if (uuid_compare(subvol.uuid, uuid_arg) == 0)
+ break;
+
+ free(subvol_path);
+ }
+ btrfs_util_destroy_subvolume_iterator(iter);
+ } else {
+ /*
+ * If !by_rootid, rootid_arg = 0, which means find the
+ * subvolume ID of the fd and use that.
+ */
+ err = btrfs_util_subvolume_info_fd(fd, rootid_arg, &subvol);
+ if (err) {
+ error_btrfs_util(err);
+ goto out;