/*static char *SCCSID = "@(#)getphys.c	6.2 92/01/31";*/
#define _BTXT _BTXT
#define INCL_DOSERRORS
#include <os2def.h>
#include <bse.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 "lw.h"
#include "frame.h"
#include "assert.h"
#include "fsdata.h"
#include "pr_misc.h"
#include "pr_read.h"
#include "pr_debug.h"

/*
 ***	GetPhySec - Get Physical Sector #
 *
 *	GetPhySec takes a file handle and a seek position and returns
 *	the corresponding physical sector # and the size of the extent
 *	from that sector on.
 *
 *	ENTRY	pfht (eax) = file handle
 *		ulSeek (ecx) = seek position
 *
 *	EXIT	*plsn (esi) = physical sector # (0 if seek pos was off
 *			      end of file)
 *		*pulSects (edi) = # of sectors at that location
 *		'C' clear if OK
 *		'C' set if error
 *		  (al) = error code
 *		  (esi) = 0
 *	USES	all but EBP
 */

USHORT far
GetPhySec (pfht, ulSeek, plsn, pulSects, pfrm)
PFHT pfht;
ULONG ulSeek;
PLSN plsn;
PULONG pulSects;
PFRAME pfrm;
{
	ASSERT_OFT (pfht->poft);

	if (ulSeek >= pfht->poft->ulFActualLen) {
		*plsn = 0;
		*pulSects = 0;
		return NO_ERROR;
	}
/* gps10: */
	*plsn = CPSFar(ulSeek, pfht->poft, pulSects, pfrm);
	if (*plsn == LSN_BOGUS) {
/* gps20: */
		*plsn = 0;
		return GetHrdErr_ ();
	}
	return NO_ERROR;
}
