/*static char *SCCSID = "@(#)ntfyscan.c	6.2 92/01/31";*/
#define _BTXT _BTXT
/*
 ***	Ntfyscan.c - scan notify list of a directory
 *
 *	Copyright Microsoft, 1988.
 *
 *	HISTORY
 *	    19-Sep-89 by JR (John Rogers, JohnRo@Microsoft)
 *		- Avoid warnings from Microsoft C 5.2 (on slash-slash comments).
 */

#define INCL_DOSERRORS
#include <os2def.h>
#include <bse.h>
#include "api.h"
#include "const.h"
#include "chain.h"
#include "misc.h"
#include "buf.h"
#include "dir.h"
#include "volume.h"
#include "storage.h"
#include "frame.h"
#include "ea.h"
#include "find.h"
#include "tables.h"
#include "pb_ifs.h"
#include "notify.h"
#include "pbmacros.h"
#include "lw.h"
#include "fsdata.h"

#include "pr_find.h"
#include "pr_debug.h"
#include "pr_misc.h"


/***	NotifyScan - scan notify list
 *
 *	This routine scans the notify list of a directory.  It is called
 *	as a result of create, mkdir, delete, rmdir, close, commit, rename,
 *	setpathinfo, setfileinfo, and setfilemode applying to a file or
 *	directory contained in a directory being monitored by a
 *	DosFindNotifyFirst or DosFindNotifyNext call.
 *
 *	Returns:    no return value
 *		    cusChanges updated for all relevant NOTIFY structs in list
 *		    may cause NotifyFirst/Next callers to wake up.
 */

void far
NotifyScan(PNOTIFY pnotHead,	    /* ptr to first NOTIFY struct in the list */
	   PDIRENT pde,		    /* directory entry of file that changed */
	   PFRAME  pfrm)
{
    PNOTIFY pnot;

    pnot = pnotHead;
    do {
	if (FATTRFIND(pde->fAttr, pnot->usSearchAttr)
		&& (pnot->ppsPattern == 0
		|| MetaMatch(pnot->ppsPattern, (PPASCALSTRING)&pde->cchName,
				pfrm->pvol->paiCodePage [pde->bCodePage])
							== METAMATCH_EQUAL)) {

	    if (++pnot->cusChanges >= pnot->cusNeeded) {
		pnot->cusNeeded = -1;	/* indicate nobody waiting now */
#ifdef NOTIFY_ROUTINE
		(*pnot->wrWakeRtn)(pnot);
#else
		ProcRun (&pnot->cusNeeded);	  /* wakeup in NotifyWait. */
#endif
	    }
	}
    } while ((pnot = pnot->dcpNext) != pnotHead);
}
