/*static char *SCCSID = "@(#)qpathea.c	6.2 92/01/31";*/
#define _BTXT _BTXT
#define INCL_DOSERRORS

#include <os2.h>

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

/*
 ***	QPathEA - Query EAs from Path Name
 *
 *	Query the Extended Attributes for a pathname
 *	DosQPathInfo levels 3 & 4)
 *
 *	ENTRY	pgeal	= ptr to GEA list (0 for level 4)
 *		pgeal	= ptr to FEA buffer
 *		pdb	= dirblock for pde
 *		pde	= ptr to dirent we are getting EA's for
 *
 *	RETURNS NO_ERROR iff No Error
 *		else
 *		  returns error code
 *		  *poffGEA = offset in GEA list of error (level 3 only)
 *	USES	ALL
 *
 *	HISTORY
 *	    19-Sep-89 by JR (John Rogers, JohnRo@Microsoft)
 *		- Avoid warnings from Microsoft C 5.2 (on slash-slash comments).
 */

USHORT
QPathEA (PGEALIST   pgeal,
	 PFEALIST   pfeal,
	 PDIRBLK    pdb,
	 PDIRENT    pde,
	 PUSHORT    poError,
    BOOL       fLevel,
	 PFRAME	   pfrm)

{
    USHORT   usRet;
    POFT     poftDir;

     /*
      * We've got to put a lock on this guy to prevent parallel EA updates.
      * We don't really want to lock out data access, but thats too bad.
      *
      * pdb  = address of start of dirblk
      * pde  = address of entry
      * pfeal = FEA buffer
      * pgeal = GEA list address
      * SBDIR held
      */

    if( pde->ulEALen == 0 ) {
	/* No ea's: skip everything and just copy the GEA list over */
	CHECKSWAP(&swapBSWAP0);
	usRet = MkFEAFromGEA( pgeal, pfeal, poError, fLevel );

    } else {

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

	if ( poftDir == NULL ) {

	    /*	    Hard error	*/
//	    ShutOFT(poftDir,pfrm);                  #122019
	    return( GetHardErr(ERROR_READ_FAULT) );
	}

	/*
	 * We have a hold (from GOFT) which will keep SetEA
	 *  from changing anything; therefore, we don't need to lock the OFT
	 */

	LOCKSWAP(&swapBSWAP0);
	usRet = GetEA (pfeal, pgeal, poftDir, poError, fLevel, pfrm);
	UNLOCKSWAP(&swapBSWAP0);

	/*
	 * We're done.  Now we release the OFT and exit.
	 *
	 *   usRet (al) = error code or 0 if OK
	 *   pfeal (ebx) = FEA buffer pointer
	 *   poftDir (edi) = OFT address, locked
	 */

	ShutOFT(poftDir,pfrm);
    }

    return usRet;
}
