/*static char *SCCSID = "@(#)fs_move.c	6.2 91/01/14";*/
#define SCCSID "@(#)fs_move.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_MOVE - Move a file or subdirectory
 *      
 *      Moves (renames) the specified file or subdirectory.
 *
 *
 *  REVISION HISTORY (in reverse chronological order)
 *  --------------------------------------------------------------------------
 *  2/22/90     Brian Andrew    Modified to simulate HPFS/FAT type response
 *                              when the disk would not need to be modified.
 *                              Return CDROM_WRITE_PROTECT otherwise.
 *  9/13/89     Paul Bingman    First CDROM version
 *  8/4/89      Brian Andrew    Initial blank template
 *
 *
 * TO DO
 * --------------------------------------------------------------------------
 *
 */


#define INCL_DOSERRORS
#define INCL_NOPMAPI
#include <os2.h>
#include <fsd.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 "pr_memin.h"
#include "pr_dbcs.h"

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


int far pascal
FS_MOVE (   PCDFSI  pcdfsi,
			PCDFSD  pcdfsd,
			PCHAR   pSrc,
			USHORT  iSrcCurDirEnd,
			PCHAR   pDst,
			USHORT  iDstCurDirEnd,
			USHORT  flags)
{

	USHORT  usRet;
	USHORT  afAttr;

#ifdef DEBUG
	dprintf ("FS_MOVE(\"%Fs\", \"%Fs\", flags=%d)\n", pSrc, pDst, flags);
#endif

	/*
	 *  If the names are the same, we look to see if the file/directory
	 *  exists.  If so we return NO_ERROR, otherwise the error from
	 *  searching for the file.
	 */

	/* Always search for the source file. If not there then return error. */
	if (! (usRet = FS_FILEATTRIBUTE (
						FA_RETRIEVE,
						pcdfsi,
						pcdfsd,
						pSrc,
						iSrcCurDirEnd,
						&afAttr)))
	{
		/* If the names don't match look for the destination file */
		if (StrCmpDBCS (pSrc, pDst))
		{
			if (! (usRet = FS_FILEATTRIBUTE (
								FA_RETRIEVE,
								pcdfsi,
								pcdfsd,
								pDst,
								iDstCurDirEnd,
								&afAttr)))
			{
				/*
				 *  Source exists, destination exists but they are not
				 *  the same file.  The error is ERROR_ACCESS_DENIED.
				 */

				usRet = ERROR_ACCESS_DENIED;
			}

			else
			{
				/*
				 *  Source exists but the destination doesn't.  Rather than
				 *  create the destination, we return
				 *  CDROM_WRITE_PROTECT.
				 */

				usRet = CDROM_WRITE_PROTECT;
			}

		}
	}

#ifdef DEBUG
	dprintf ("\tFS_MOVE: Return value -- %d\n", usRet);
#endif

	return usRet;

	/* defeat compiler warnings */

	pcdfsi;
	pcdfsd;
	pSrc;
	iSrcCurDirEnd;
	pDst;
	iDstCurDirEnd;
	flags;

}   /* end FS_MOVE */

/* end of fs_move.c */
