/*static char *SCCSID = "@(#)wipelook.c	6.1 90/11/18";*/
/*static char *SCCSID = "@(#)wipelook.c	13.3 90/01/25";*/
#define BSWAP2 BSWAP2
#include <os2.h>
#include "api.h"
#include "const.h"
#include "misc.h"
#include "chain.h"
#include "buf.h"
#include "dir.h"
#include "storage.h"
#include "fnode.h"
#include "volume.h"

#include "tables.h"
#include "pb_ifs.h"
#include "superb.h"
#include "lw.h"
#include "frame.h"
#include "fsdata.h"

#include "pr_MOVE.h"
#include "pr_MISC.h"

/*
 ***	WipeLook - Remove Obsolete DIRLOOK references
 *
 *	We're renaming a directory, so any DIRLOOK entrys to that
 *	directory or to directorys within it get purged.
 *
 *	ENTRY	(eax) = address of full path string of moving directory
 *	EXIT	none
 */
void
WipeLook (pcp)
PCRACKEDPATH pcp;
{

	PDIRLOOK pdlCur;	/*  used to traverse lookaside table  */
	USHORT cchCompLen;	/*  number of bytes to compare	*/
	USHORT i;		/*  Generic index variable	*/

	/*  The number of bytes to compare is the full length of
	 *  the cracked path, including the last component, but
	 *  excluding the initial length word.
	 */
	cchCompLen = pcp->cbPath + FILE_NAME(pcp)->c - sizeof(pcp->cbPath);

	pdlCur = (PDIRLOOK)(dcpDLHead.pFwd);
	for (i = 0; i < DLCNT; i++) {

	    /*	IF the DIRLOOK entry's pcpName:
	     *
	     *	  *  is not NULL,
	     *	  *  is not shorter than pcp, and
	     *	  *  matches pcp, except for the initial length word, for
	     *	     all of pcp's length, 
	     *	THEN it represents a subdirectory of the directory
	     *	represented by pcp (or pcp itself) and should be removed
	     *	from the directory-lookaside table.
	     *
	     */
	    if (pdlCur->pcpName &&
		cchCompLen <= pdlCur->pcpName->cbPath -
				 sizeof(pdlCur->pcpName->cbPath) &&
		memcmp(&pcp->sp, &pdlCur->pcpName->sp, cchCompLen) == 0) {

		/*
		 *  Zero out the checksum and the length byte of the
		 *  first component of the cracked path.
		 */
		pdlCur->cks = 0;
		pdlCur->pcpName->cbPath = 0;
	    }

	    pdlCur = (PDIRLOOK)(pdlCur->dcpLinks.pFwd);
	}
}
