/* This function destroys subtree of the TNC tree. Returns number of clean znodes in the subtree.  */
long ubifs_destroy_tnc_subtree(struct ubifs_znode *znode)
/* This function destroys subtree of the TNC tree. Returns number of clean znodes in the subtree.  */
long ubifs_destroy_tnc_subtree(struct ubifs_znode *znode)
{
	struct ubifs_znode *zn = ubifs_tnc_postorder_first(znode);
	long clean_freed = 0;
	int n;
	ubifs_assert(zn);
	while (1) {
		for (n = 0; n < zn->child_cnt; n++) {
			if (!zn->zbranch[n].znode)
				continue;
			if (zn->level > 0 &&
			    !ubifs_zn_dirty(zn->zbranch[n].znode))
				clean_freed += 1;
			cond_resched();
			kfree(zn->zbranch[n].znode);
		}
		if (zn == znode) {
			if (!ubifs_zn_dirty(zn))
				clean_freed += 1;
			kfree(zn);
			return clean_freed;
		}
		zn = ubifs_tnc_postorder_next(zn);
	}
}