/*static char *SCCSID = "@(#)lockoft.c	6.2 92/01/31";*/
#ifndef	 _BTXT
#define	 _BTXT _BTXT
#define	 _THISFILE "LOCKOFT.C"
#include _THISFILE.C
#undef	 _BTXT
#endif

#ifndef HDRS
#define HDRS

#include <os2def.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 "pbmacros.h"
#include "assert.h"
#include "log.h"
#include "frame.h"

#endif

#include "pr_FSSUB.h"
#include "pr_MISC.h"


/*
 ***	LockOFT - Put a Lock on an OFT
 *
 *	We Lock a file's OFT when the file is being written or closed.
 *	LockOFT blocks until the OFT is lockable, but does not set the
 *	lock flag.
 *
 *	ENTRY	poft (EDI) = OFT address
 *
 *	EXIT	OFT is lockable (but unlocked!)
 */

void
LockOFT (poft,pfrm)
POFT poft;
PFRAME pfrm;
{
    /* NOTE: The following loop is different than the 386 code!  It is:
     *
     *	    do {
     *		... Block ...
     *	    while (...);
     *
     *	I don't think it matters, since we only get here if one of the flags
     *	are set (I think).
     */

    while ((poft->bFlag & (OTF_LCK+OTF_PLK)) != 0) {
	poft->cWaits++;
	BlockOnOFT( poft,pfrm );
	poft->cWaits--;
	}

    ASSERT_OFT (poft);

    if (poft->cusHolds == 0)
	return;

    do {
	SetFlagsOFT( poft, OTF_PND + OTF_PLK );
	poft->cWaits++;
	BlockOnOFT( poft,pfrm );
	poft->cWaits--;

	ASSERT_OFT (poft);
    } while (poft->cusHolds != 0);

    ClrFlagsOFT(poft, OTF_PLK);
    if ((poft->bFlag & OTF_PSO) == 0)
	ClrFlagsOFT(poft, OTF_PND);


}
