/* This may release the path, and so you may lose any locks held at the time you call it.  */
int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path)
/* This may release the path, and so you may lose any locks held at the time you call it.  */
int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path)
{
	struct btrfs_key key;
	struct btrfs_disk_key found_key;
	int ret;
	btrfs_item_key_to_cpu(path->nodes[0], &key, 0);
	if (key.offset > 0)
		key.offset--;
	else if (key.type > 0)
		key.type--;
	else if (key.objectid > 0)
		key.objectid--;
	else
		return 1;
	btrfs_release_path(root, path);
	ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
	if (ret < 0)
		return ret;
	btrfs_item_key(path->nodes[0], &found_key, 0);
	ret = comp_keys(&found_key, &key);
	if (ret < 0)
		return 0;
	return 1;
}