/*static char *SCCSID = "@(#)fs_mount.c	6.2 91/01/14";*/
#define SCCSID "@(#)fs_mount.c	6.2 91/01/14"
/*
 *	IBM/Microsoft Confidential
 *
 *	Copyright (c) IBM Corporation 1987, 1989
 *	Copyright (c) Microsoft Corporation 1987, 1989
 *
 *	All Rights Reserved
 *
 */

/*
 *  FS_MOUNT.C
 *
 *    DESCRIPTION
 *    
 *      Mount or unmount a volume
 *
 *
 *    FUNCTIONS DEFINED
 *
 *      FS_MOUNT () -   Mount or unmount a volume
 *
 * 
 *  REVISION HISTORY (in reverse chronological order)
 *  -----------------------------------------------------------------------
 *  2/7/90      Brian Andrew    Move VolMount to vol\vol.c
 *  1/2/90      Brian Andrew    Added path table size to volume id to try
 *                              to generate additional variation.
 * 
 *  12/4/89     Brian Andrew    Check global flag before mounting volume.
 * 
 *  11/16/89    Brian Andrew    Modified VolMount to reduce stack usage.
 * 
 *  11/15/89    Brian Andrew    Modified RecoverPathTable to reduce stack
 *                              usage.
 * 
 *  9/25/89     Brian Andrew    VolMount -- used value returned in vpfsi
 *                              for sector size.
 * 
 *  8/15/89     Brian Andrew    Working version
 * 
 *  8/4/89      Brian Andrew    Initial Blank Template
 *
 *
 *  TO DO
 *  -------------------------------------------------------------------------
 */


#define INCL_DOSERRORS
#define INCL_NOPMAPI
#include <os2.h>
#include <fsd.h>
#include <fsh.h>

#include "cdfs.h"
#include "sem.h"
#include "path.h"
#include "vol.h"
#include "file.h"
#include "buffer.h"
#include "mem.h"
#include "heap.h"
#include "message.h"

#ifdef STATS_H
#include "stats.h"
#endif

#include "fsdata.h"
#include "pr_memin.h"
#include "pr_vol.h"

#ifdef DEBUG
#include "pr_DEBUG.h"
#endif



/***    FS_MOUNT () -   Mount or unmount a volume
 *      
 *  DESCRIPTION
 *
 *      Take different action depending on what flag is passed in.
 *
 *      We only take action when requested to recognize a volume or
 *      when we are told that there are no more references to that volume.
 *
 *      
 *  ENTRY
 *
 *      fsOper  =   Type of operation requested.
 *      pvpfsi  =   Pointer to volume independent data.
 *      pvpfsd  =   Pointer to volume dependent data.
 *      hVPB    =   Volume handle.
 *      pBoot   =   Pointer to sector 0 data, (not used by us)
 *
 *
 *  LOCAL
 *
 *      usRet   =   Return value from this function.
 *
 *
 *  EXIT
 *
 *      NO_ERROR    If volume is recognized.
 *      Return value from InitMemory if error occurred.
 *      Return value from VolMount if called.
 *
 */


INT far pascal
FS_MOUNT (USHORT            fsOper, 
		  PVPFSI            pvpfsi, 
		  PVPFSD            pvpfsd, 
		  SHANDLE           hVPB,   
		  PCHAR             pBoot)  
{
	USHORT  usRet;

#ifdef DEBUG
	dprintf ("FS_MOUNT:fsOper=%d\n", fsOper);
#endif

#ifdef STATS_H
		CurSt.st_mount++;
#endif

	/* Check if first time initialization */
	if (usRet = CHECK_INIT)
		return usRet;

	/* Perform a switch based on the arguement flag */
	switch (fsOper)
	{
		case MOUNT_MOUNT :
			/* Check flag before mounting volume */
			if (fMountEnabled)
			{
				/* Attempt to mount volume */
				usRet = VolMount (hVPB, pvpfsi, (PVOL_DEP_DATA) pvpfsd);

			} /* end if mount is enabled */

			/* Else don't mount */
			else
			{
				usRet = ERROR_NOT_SUPPORTED;

			}
			break;

		case MOUNT_RELEASE :
			/* Free up the volume dependent data */
			FreeVolDepData ((PVOL_DEP_DATA) pvpfsd);
			break;

		case MOUNT_VOL_REMOVED :
		case MOUNT_ACCEPT :
			/* No Action */
			break;

		default :
			usRet = ERROR_INVALID_PARAMETER ;
			break;

	} /* end switch fsOper */


#ifdef DEBUG
	dprintf ("    FS_MOUNT:usRet=%d", usRet);

	/* Display whether this is ISO or HSG */
	if (!usRet && (fsOper == MOUNT_MOUNT))
	{
		if (((PVOL_DEP_DATA) pvpfsd)->pvdVolDesc)
		{
			if (((PVOL_DEP_DATA) pvpfsd)->pvdVolDesc->fISOVol)
			{
				dprintf (",  ISO volume found");
			}

			else
			{
				dprintf (",  HSG volume found");
			}


		}
	}

	dprintf ("\n");

#endif

	return usRet;

	/* no warnings */
	fsOper; pvpfsi; pvpfsd; hVPB; pBoot;

}   /* end FS_MOUNT */


