/*static char *SCCSID = "@(#)fs_read.c	6.3 92/01/31";*/
#define INCL_DOSINFOSEG /* for mmph */
#define INCL_DOSERRORS
#include <os2.h>
#include <fsd.h>
#include <pvwxport.h>

#include "heap.h"
#include "api.h"
#include "const.h"
#include "misc.h"
#include "chain.h"
#include "buf.h"
#include "dir.h"
#include "storage.h"
#include "volume.h"
#include "tables.h"
#include "pb_ifs.h"
#include "pbmacros.h"
#include "superb.h"
#include "lw.h"
#include "frame.h"
#include "fsdata.h"
#include "tefti.h"
#include "pvw.h"

#include "pr_CACHE.h"
#include "pr_FCN.h"
#include "pr_HEAP.h"
#include "pr_DEBUG.h"
#include "mmph.h"

/*
 * FS_READ
 *
 *	HISTORY
 *	    26-May-1989 by JR (John Rogers, JohnRo@Microsoft)
 *		- DCR 259.2: changed names of macros in "frame.h".
 *	    07-Oct-1988 17:06:14 by Jon Parati [jonpa]
 *		- added frame initialization
 */

int far pascal
FS_READ (psffsi, psffsd, pcData, pusLen, IOflag)
struct sffsi far	*psffsi;
struct sffsd far	*psffsd;
CHAR far		*pcData;
USHORT far		*pusLen;
USHORT			IOflag;
{
	USHORT usRet;
	FRAME  frm;

	frm.usHardErr = NO_ERROR;
	frm.fRecheckAddr = TRUE;

	MMPHPreFS_Read(); /* performance hook (330E) */

#ifdef TEFTI
	ClearCounter (0);
	StartCounter (0);
#endif

#ifdef PERFVIEW2
	PVWSTART(Rd,Total);
#endif

	usRet = Read (((PPB_SFD)(psffsd->sfd_work))->pfht,
		       pusLen,
		       psffsi -> sfi_position,
		       pcData,
		       &frm);

#ifdef PERFVIEW2
	PVWSTOP(Rd,Total);
#endif


	/* if an error return now */
	if (usRet) {
#ifdef TEFTI
	    StopCounter (0);
#endif

	    MMPHPostFS_Read() /* performance hook (338E) */

	    return (usRet);
	}

	/* update the seek pointer and return */
	psffsi -> sfi_position += *pusLen;

#ifdef DEBUG
	VBS ();
#endif
#ifdef TEFTI
	StopCounter (0);
	LatchCounter (0);
	dprintf (__FILE__ ": %dus\n", Get_cntCounter (0));
#endif

	MMPHPostFS_Read() /* performance hook (338E) */

	return (usRet);

	/* to prevent compiler warnings */
	IOflag;
}
