/*static char *SCCSID = "@(#)mfs_open.c	6.3 92/02/21";*/
#define INCL_DOSERRORS
#include <os2.h>
#include <fsd.h>

#include "heap.h"
#include "api.h"
#include "filemode.h"
#include "const.h"
#include "misc.h"
#include "chain.h"
#include "buf.h"
#include "dir.h"
#include "storage.h"
#include "volume.h"
#include "tables.h"
#include "pb_ifs.h"
#include "pbmacros.h"
#include "superb.h"
#include "lw.h"
#include "frame.h"
#include "fsdata.h"
#include "tefti.h"
#include "pr_CACHE.h"
#include "pr_FCN.h"
#include "pr_HEAP.h"
#include "pr_MISC.h"
#include "pr_WRSUB.h"
#include "pr_DEBUG.h"
#include "pr_MFS.h"

/*
 ***	MFS_OPEN - open a stage one file
 *
 *	This function is called to open a file during stage 1 of the boot
 *	sequence.  It searches for the file on the disk (which must be the
 *	boot disk, although it may be in a subdirectory), and if the file
 *	exists, returns a value of 0.  Subsequent calls to MFS_READ will
 *	assume to be from that file.
 *
 *	Entry	pucName = pathname of file to open
 *		pulSize = address of a DWORD to fill with the file's size
 *
 *	Returns error code (0 for success)
 *	*pulSize = size of file in bytes
 *
 *	HISTORY
 *	    26-May-1989 by JR (John Rogers, JohnRo@Microsoft)
 *		- DCR 259.2: changed names of macros in "frame.h".
 */

int far pascal
MFS_OPEN (pcName, pulSize)
PCHAR pcName;
PULONG pulSize;
{
	PCRACKEDPATH pcp;	/*  points to cracked path for Open	*/
	USHORT us;		/*  stores return code from Open	*/
	USHORT RetAction;
	FRAME  frm;

	frm.usHardErr = NO_ERROR;
	frm.fRecheckAddr = TRUE;
#ifdef PRINTFS
	dprintf ("MFS_OPEN (`%Fs')\n", pcName);
#endif

/*
 * The second parameter is pcName-3 because CrackPath expects the name
 * to begin with a drive, colon, and backslash.
 */

	if ((us = CrackPath(1, pcName-3, &pcp, &frm)) == NO_ERROR) {
	    us = OpenFar (OPEN_FOR_READ | SHARING_DENY_NONE | OPEN_AUTOFAIL |
		       OPEN_WRITE_THROUGH,
		       1,
		       0,
		       0L,
		       pcp,
		       pulSize,
		       &Stage1PFHT,
		       (PUSHORT)&RetAction,
		       NULL,
		       &frm);
	}

	if (pcp != NULL)
	    RetHeap (pcp);

	Stage1Pos = 0L;

#ifdef DEBUG
	VBS ();

	if (us)
	  dprintf ("MFS_OPEN: Cannot open file %Fs\n", pcName);
	else
	  dprintf ("MFS_OPEN: Successfully opened %Fs\n", pcName);
#endif
	return (us);
}
