/*static char *SCCSID = "@(#)tfn.c	6.2 92/01/31";*/
#define INCL_DOSINFOSEG
#include <os2def.h>
#include <bse.h>
#include "chain.h"
#include "const.h"
#include "misc.h"
#include "buf.h"
#include "dir.h"
#include "storage.h"
#include "volume.h"
#include "tables.h"
#include "pb_ifs.h"
#include "lw.h"
#include "frame.h"
#include "fsdata.h"

#include "pr_ALLOC.h"
#include "pr_FSSUB.h"


/*
 ***	TFN - Truncate FNode
 *
 *	TFN truncates a file to a specific length and then updates two
 *	FNODE fields:  OFT_LAST is set to zero so that it will be
 *	recomputed, and if there was an allocation tree and the file
 *	is sufficiently shrunken we collapse the tree.
 *
 *	ENTRY	culSectors = new length, in sectors
 *		poft = OFT address
 *
 *	EXIT	Returns TRUE if OK
 *		Return FALSE if error
 *
 *	Note:	Yields CPU
 *
 * Function defined as macro in pr_alloc.h
 */

/*
 ***	TFN_ - Truncate FNode with specified write thru bits
 *
 *	TFN truncates a file to a specific length and then updates two
 *	FNODE fields:  OFT_LAST is set to zero so that it will be
 *	recomputed, and if there was an allocation tree and the file
 *	is sufficiently shrunken we collapse the tree.
 *
 *	ENTRY	culSectors = new length, in sectors
 *		poft = OFT address
 *		fWrtThru = TRUE if write through is to be done
 *
 *	EXIT	Returns TRUE if OK
 *		Return FALSE if error
 *
 *	Note:	Yields CPU
 */

BOOL TFN_ ( ULONG culSectors, POFT poft, BOOL fWrtThru, PFRAME pfrm )
{
    BOOL bRet;

    bRet = TFA (&poft->fst.alb, culSectors, fWrtThru, pfrm );

    poft->lsnLast = 0;

    if (bRet & TFA_RET_BIT_ERROR) {
	/* hard error - mark the OFT corrupt */
	OFTCorrupt(poft,pfrm);
	bRet = FALSE;
    } else {
	bRet = TRUE;
    }

    return bRet;
}
