/*static char *SCCSID = "@(#)cch.c	6.3 91/05/23";*/
#define SCCSID "@(#)cch.c	6.3 91/05/23"
/********************************************************/
/*                                                      */
/*       IBM/Microsoft Confidential                     */
/*                                                      */
/*       Copyright (c) IBM Corporation 1987, 1989       */
/*       Copyright (c) Microsoft Corporation 1987, 1989 */
/*                                                      */
/*       All Rights Reserved                            */
/********************************************************/

#define FNO_NUM FNO_CCH_C
#define INCL_TYPES                      // for basedef.h typedefs
#include <osconst.h>
#include <ostypes.h>
#include <basemac.h>
#include <basedef.h>
#include <bseerr.h>
#include <fnofs.h>
#include <osmac.h>
#include <mi.h>
#include <vmexport.h>
#include <selxport.h>
#include <pgexport.h>
#include <tkexport.h>
#include <sched.h>
#include <smexport.h>
#include <sft.h>
#include <cache.h>
#include <strat2.h>
#include <vmowner.h>
#include <fslocal.h>

/*
 ***    CCH - Check Cache Hit
 *
 *      CCH checks to see if a given physical sector is
 *      in the cache.  CCH doesn't worry about whether or
 *      not the cache block is locked or not, and it assumes
 *      that the supplied sector number is already rounded down
 *      to a multiple of SECPERBUF
 *
 *      ENTRY   rba = physical sector number (must be multiple of SECPERBUF)
 *              hVPB = handle to volume
 *
 *      RETURNS the cache header address
 *              or NULL if not in cache
 *
 */

PBUFHDR CCH(rba,hVPB)
ulong_t rba;                        /* Physical Sector Number */
ulong_t hVPB;
{
    PBUFHDR pbuf;              /*  buffer to find */

    MMPHPreCCH();       /* Performance Hook (3202) */

    while (TRUE) {

        pbuf = HashFind (rba,hVPB);

        if (pbuf != NULL) {
          pTCBCur->TCBSpareFlags |= SPFLAGS_XTIME_SLICE;  //#97886
          break;
        }

        /*      We didn't find the rba in the cache--if fGFBActive is
         *      set, we'll wait for the process using GFB to finish,
         *      since it might be getting our sector.
         */
        if (!fGFBActive) {
            break;
        }

        GFBWait();
    }
    MMPHPostCCH();         /* Performance Hook (3286) */
    return pbuf;
}
