/*static char *SCCSID = "@(#)deleadat.c	6.2 92/01/31";*/
#define BSWAP0 BSWAP0

#define INCL_DOSERRORS
#include <os2def.h>
#include <bse.h>

#include "const.h"
#include "heap.h"
#include "misc.h"
#include "buf.h"
#include "storage.h"
#include "ea.h"
#include "fnode.h"
#include "chain.h"
#include "dir.h"
#include "volume.h"
#include "tables.h"
#include "pbmacros.h"
#include "frame.h"
#include "lw.h"
#include "fsdata.h"



#include "pr_alloc.h"
#include "pr_ea.h"
#include "pr_heap.h"
#include "pr_misc.h"
#include "pr_debug.h"

/*
 * DelEAData
 *
 *  Scans a list of FEA's and deletes the big data allocation
 *  structures for the ones with big data.
 *
 *	HISTORY
 *	    19-Sep-89 by JR (John Rogers, JohnRo@Microsoft)
 *		- Avoid warnings from Microsoft C 5.2 (on slash-slash comments).
 */
void DelEAData( PFEA pfeaLst, PFEA pfeaEnd, PFRAME pfrm )
{
    PALBLK palbTmp;
    UINT oAValue;	/* offset of aValue field in the FEA */


    for( ; OFFSETOF(pfeaLst) < OFFSETOF(pfeaEnd);
	 pfeaLst = (PFEA)BUMP_PTR( pfeaLst, oAValue + pfeaLst->cbValue ) ) {

	/*
	 * Find the offset of the abValue[0] field of the FEA
	 *
	 * offset = sizeof(FEA) - the abValue and szName fields +
	 * the size of the real name + 1 for the null at the end.
	 *
	 * NOTE when we use official base headers we need to get rid
	 * of the (-2) after sizeof(FEA).
	 */
	oAValue = (sizeof(FEA) - 2) + pfeaLst->cbName + sizeof((char)'\0');

	/*
	 * If this FEA has an external allocation for its data,
	 * than delete that allocation.
	 */
	if( (pfeaLst->fEA & FF_BIGD) != 0 ) {

	    CHECKSWAP(&swapBSWAP0);
	    palbTmp = BuildAlBlk((PEAAT)BUMP_PTR(pfeaLst, oAValue),
				  !((pfeaLst)->fEA & FF_DAT),pfrm);

	    /*
	     * Delete the allocation
	     *	 (This was a DelAlloc originally)
	     */
	    TFA (palbTmp, 0L, FALSE, pfrm);

	    /*	Note that we ignore hard errors from TFA.
	     *	They'll orphan disk space, which CHKDSK
	     *	will recover.
	     */
	    RetHeap (palbTmp);
	}
    }
}
