/*static char *SCCSID = "@(#)stpthea.c	6.2 92/01/31";*/
#define _BTXT _BTXT
#define INCL_DOSERRORS
#include <os2def.h>
#include <bse.h>

#include "const.h"
#include "misc.h"
#include "chain.h"
#include "buf.h"
#include "dir.h"
#include "storage.h"
#include "ea.h"
#include "fnode.h"
#include "volume.h"
#include "tables.h"
#include "pbmacros.h"
#include "superb.h"
#include "lw.h"
#include "frame.h"
#include "fsdata.h"
#include "log.h"
#include "pr_debug.h"
#include "pr_ea.h"
#include "pr_cache.h"
#include "pr_dir.h"
#include "pr_fssub.h"
#include "pr_misc.h"
#include "pr_read.h"

/*
 ***	SetPathEA - Set EAs for a Path Name
 *
 *	Set Extended Attributes for a pathname
 *	(DosSetPathInfo level 2)
 *
 *	NOTES
 *		On entry, the subdir in pfrm->psbd must be held.
 *		pbuf must also be held.  They both will be left
 *		in that state.
 *
 *	ENTRY	pfeal	   (edi) = ptr to FEA list buffer
 *		pdb		 = dirblock for dirent
 *		pde		 = dirent of file/subdir
 *		pbuf		 = buf for above dirblock
 *		poError		 = pointer to offset into ea list of error
 *
 *	EXIT	Returns: NO_ERROR if OK
 *
 *			 error code if error
 *			    *poError = offset of bad FEA in FEA buffer
 *
 *	HISTORY
 *	    19-Sep-89 by JR (John Rogers, JohnRo@Microsoft)
 *		- Avoid warnings from Microsoft C 5.2 (on slash-slash comments).
 *	    24-Feb-1989 16:17:25 by Jon Parati [jonpa]	send old ea sz to setea
 *	    06-Jan-1989 22:40:01 by Jon Parati [jonpa]	added UnHoldDir at end.
 *
 *BUGBUG - this should probably be resynced with gordons latest stuff! (1/6/89)
 *BUGBUG - ditto but with more emphasis due to access times etc. (2/24/88)
 *BUGBUG - ditto with a LOT more emphasis due to flDMask manipulations(4/24/89)
 *
 */

USHORT
SetPathEA( PFEALIST pfeal,
	   PDIRBLK  pdb,
	   PDIRENT  pde,
	   PBUFNODE pbuf,
	   PUSHORT  poError,
	   PFRAME   pfrm)
{
	USHORT usRet;
	USHORT usEALen;
	POFT poft;

	/* set this file in the frame and bump the global bit */
//	pfrm->flDMask = flDirtMask | (pfrm->usHardErr & 0xFF);
	pfrm->flDMask = flDirtMask;         //#114986

	if( (flDirtMask <<= 1) == 0 )
	    flDirtMask = DMASK_INIT;

	poft = GOFT(pde, pdb, pfrm->psbd, pfrm);

	if ( poft == NULL ) {
	    usRet = ERROR_READ_FAULT;
	    goto SPEAExit2;
	}

	if( !HoldToLock (poft,pfrm) ) {
	    /* We yielded instead of locking.  Lock it now */
	    SetLockOFT( poft );
	}

	usEALen = (USHORT)pde->ulEALen;

	/* try to set the ea's and get the new ea len */
	CHECKSWAP(&swapBSWAP0);
	if((usRet = SetEA(pfeal, poft, poError, &usEALen,
				 FALSE, pfrm)) == NO_ERROR) {

	    /*
	     * If the size of the ea's has changed then we need to change this
	     * in the dir ent.
	     */

	    /* set/reset the flags with the new need fea bit */
	    pde->fFlags = (pde->fFlags & ~DF_NEEDEAS) | (BYTE)*poError;

	    pde->ulEALen = (ULONG) usEALen;

	    /*
	     * Since this is not handle based, we must write thru
	     * the dir block if write thru is on.
	     */
	    SetDEDirt (pde, pbuf, pfrm->u.fWrtThru,pfrm);
	}

/* spea10: */

	/* We're done.  Now we release the OFT and exit */
	UnLockOFT (poft);

	/* remember: this does not actually increment the hold count */
	HoldOFT (poft,pfrm);
	IncrHoldsOFT (poft);

	ShutOFT(poft,pfrm);

SPEAExit2:                               //122019
	return (GetHardErr (usRet));
}
