/*static char *SCCSID = "@(#)chkhchn.c	6.1 90/11/17";*/
/*static char *SCCSID = "@(#)chkhchn.c      13.3 90/01/25";*/
#include <os2def.h>

#include "api.h"
#include "const.h"
#include "misc.h"
#include "chain.h"
#include "buf.h"
#include "dir.h"
#include "volume.h"
#include "storage.h"
#include "fnode.h"
#include "tables.h"
#include "pb_ifs.h"
#include "superb.h"
#include "lw.h"
#include "frame.h"
#include "fsdata.h"
#include "pr_DEBUG.h"
#include "pr_MISC.h"

/*
 ***	ChkHashChain - Check Hash Chain for Validity
 *
 *	verify that each hash chain is circular and contains only
 *	sectors of the right type
 *
 *	ENTRY none
 *	EXIT  none
 *
 */
void far
ChkHashChain ()
{
    USHORT us;
    PBUFNODE pbuf, pbufHead;

    if (FF_CHKHCHN & flFastFile) {
	for (us = 0; us < HASHCNT; us++) {

	    /* if this hash bucket is not null, then go down the chain */
	    if (apbufHashTable [us] != NULL) {

		pbuf = pbufHead = apbufHashTable [us];

		/* do while not back at the head */
		do {
		    if (pbuf->lsnSec != LSN_BOGUS) {

			/* check that the vol bits are on */
			if (pbuf->lsnSec <= SECMASK) {
			    INTERR (__FILE__": vlsn too small, vol bits not on");
			}

			/* check that this buffer is in the right hash bucket */
			if (HASHVAL (pbuf->lsnSec) != us) {
			    INTERR (__FILE__": hash value wrong");
			}
		    }
		    pbuf = pbuf->dcbpHash.pbufFwd;

		} while (pbuf != pbufHead);
	    }
	}
    }
}
