/*static char *SCCSID = "@(#)lsddb.c	6.2 92/01/31";*/
#define INCL_DOSERRORS
#include <os2.h>
#include "const.h"
#include "misc.h"
#include "chain.h"
#include "buf.h"
#include "dir.h"
#include "volume.h"
#include "storage.h"
#include "tables.h"
#include "lw.h"
#include "frame.h"
#include "fsdata.h"
#include "assert.h"

#include "pr_CACHE.h"
#include "pr_DEBUG.h"
#include "pr_MISC.h"

/*
 ***	LsdDB - Locate Sector Data - DIRBLK
 *
 *	LSDBM is identical to LSD except that it returns NULL if
 *	any of the sectors in the cache block are defective.
 *	This is used to read DIRBLKs which occupy the whole cache block.
 *
 *	LSDDB is also used to read in bitmap blocks, since they also
 *	fill the cache block.  (WHAT?  See LSDBM!!)
 *
 *	ENTRY	pscpDesired = (eax) address of SECPTR structure
 *		priBuf	    = (dl)  priority of buffer once found
 *	EXIT	Returns		    NULL if error
 *		Returns		    address of data sector if OK
 *		  *ppbuf    = (ECX) address of the buffer header
 *
 *		Yields CPU
 *
 *  Change activity:
 *  ----------------
 *  73714 Skip Nizinski. Move ASSERT_DB after check for bBadMask since
 *                       read failure will most likely result in
 *                       invalid dirblk.
 */

PVOID
LSDDB (pscpDesired, priBuf, ppbuf, pfrm)
PSECPTR		pscpDesired;	/* pointer to desired sector/hint pair */
USHORT		priBuf;		/* where does it belong in LRU chain?  */
PBUFNODE far	*ppbuf;		/* pointer to the PBUFNODE for desired sector */
PFRAME		pfrm;
{
	PVOID pb;

	pb = LSD(pscpDesired, priBuf, ppbuf, pfrm);

	if ((*ppbuf)->bBadMask != 0) {
	    SETHARDERR (ERROR_READ_FAULT);
	    return NULL;
	}
   else {
       ASSERT_DB (pb);     /* Moved here for 73714 since we know
                              that the buffer should contain a valid
                              dirblk at this point.                 73714 */
	    return pb;
   }
}
