/* Delete the record pointed to by cur. The cursor refers to the place where the record was (could be inserted) when the operation returns.  */
int xfs_btree_delete(struct xfs_btree_cur *cur, int *stat)
/* Delete the record pointed to by cur. The cursor refers to the place where the record was (could be inserted) when the operation returns.  */
int xfs_btree_delete(struct xfs_btree_cur *cur, int *stat)
{
	int			error;
	int			level;
	int			i;
	XFS_BTREE_TRACE_CURSOR(cur, XBT_ENTRY);
	for (level = 0, i = 2; i == 2; level++) {
		error = xfs_btree_delrec(cur, level, &i);
		if (error)
			goto error0;
	}
	if (i == 0) {
		for (level = 1; level < cur->bc_nlevels; level++) {
			if (cur->bc_ptrs[level] == 0) {
				error = xfs_btree_decrement(cur, level, &i);
				if (error)
					goto error0;
				break;
			}
		}
	}
	XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
	*stat = i;
	return 0;
error0:
	XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR);
	return error;
}