for (; ++epg <= t->bt_csp; ++t->lstat.bt_freed) {
while (++epg <= t->bt_csp) {
__bam_dpages(dbp, t)	DB *dbp;	BTREE *t;{	DBT a, b;	DB_LOCK lock;	EPG *epg;	PAGE *h;	db_pgno_t pgno;	db_recno_t rcnt;	int ret;	COMPQUIET(rcnt, 0);	epg = t->bt_sp;	/*	 * !!!	 * There is an interesting deadlock situation here.  We have to relink	 * the leaf page chain around the leaf page being deleted.  Consider	 * a cursor walking through the leaf pages, that has the previous page	 * read-locked and is waiting on a lock for the page we're deleting.	 * It will deadlock here.  This is a problem, because if our process is	 * selected to resolve the deadlock, we'll leave an empty leaf page	 * that we can never again access by walking down the tree.  So, before	 * we unlink the subtree, we relink the leaf page chain.	 */	if ((ret = __db_relink(dbp, t->bt_csp->page, NULL, 1)) != 0)		goto release;	/*	 * We have the entire stack of deletable pages locked.  Start from the	 * top of the tree and move to the bottom, as it's better to release	 * the inner pages as soon as possible.	 */	if ((ret = __bam_ditem(dbp, epg->page, epg->indx)) != 0)		goto release;	/*	 * If we deleted the next-to-last item from the root page, the tree	 * can collapse a level.  Try and write lock the remaining root + 1	 * page and copy it onto the root page.  If we can't get the lock,	 * that's okay, the tree just stays a level deeper than we'd like.	 */	h = epg->page;	if (h->pgno == PGNO_ROOT && NUM_ENT(h) == 1) {		pgno = TYPE(epg->page) == P_IBTREE ?		    GET_BINTERNAL(epg->page, 0)->pgno :		    GET_RINTERNAL(epg->page, 0)->pgno;		if ((ret = __bam_lget(dbp, 0, pgno, DB_LOCK_WRITE, &lock)) != 0)			goto release;		if ((ret = __bam_pget(dbp, &h, &pgno, 0)) != 0)			goto release;		/* Log the change. */		if (DB_LOGGING(dbp)) {			memset(&a, 0, sizeof(a));			a.data = h;			a.size = dbp->pgsize;			memset(&b, 0, sizeof(b));			b.data = P_ENTRY(epg->page, 0);			b.size = BINTERNAL_SIZE(((BINTERNAL *)b.data)->len);			__bam_rsplit_log(dbp->dbenv->lg_info, dbp->txn,			   &h->lsn, 0, dbp->log_fileid, h->pgno, &a,			   RE_NREC(epg->page), &b, &epg->page->lsn);		}		/*		 * Make the switch.		 *		 * One fixup -- if the tree has record numbers and we're not		 * converting to a leaf page, we have to preserve the total		 * record count.		 */		if (TYPE(h) == P_IRECNO ||		    (TYPE(h) == P_IBTREE && F_ISSET(dbp, DB_BT_RECNUM)))			rcnt = RE_NREC(epg->page);		memcpy(epg->page, h, dbp->pgsize);		epg->page->pgno = PGNO_ROOT;		if (TYPE(h) == P_IRECNO ||		    (TYPE(h) == P_IBTREE && F_ISSET(dbp, DB_BT_RECNUM)))			RE_NREC_SET(epg->page, rcnt);		(void)memp_fset(dbp->mpf, epg->page, DB_MPOOL_DIRTY);		/*		 * Free the last page in that level of the btree and discard		 * the lock.  (The call to __bam_free discards our reference		 * to the page.)		 */		(void)__bam_free(dbp, h);		(void)__BT_TLPUT(dbp, lock);		++t->lstat.bt_freed;		/* Adjust the cursors. */		__bam_ca_move(dbp, h->pgno, PGNO_ROOT);	}	/* Release the top page in the subtree. */	(void)memp_fput(dbp->mpf, epg->page, 0);	(void)__BT_TLPUT(dbp, epg->lock);	/*	 * Free the rest of the pages.	 *	 * XXX	 * Don't bother checking for errors.  We've unlinked the subtree from	 * the tree, and there's no possibility of recovery.	 */	for (; ++epg <= t->bt_csp; ++t->lstat.bt_freed) {		if (NUM_ENT(epg->page) != 0)			(void)__bam_ditem(dbp, epg->page, epg->indx);		(void)__bam_free(dbp, epg->page);		(void)__BT_TLPUT(dbp, epg->lock);	}	return (0);release:	/* Discard any remaining pages and return. */	for (; epg <= t->bt_csp; ++epg) {		(void)memp_fput(dbp->mpf, epg->page, 0);		(void)__BT_TLPUT(dbp, epg->lock);	}	return (ret);}