/*static char *SCCSID = "@(#)doscopy.h	6.2 92/02/26";*/
/*
 *
 * DOSCOPY.H - Header file for the OS/2 DOSCOPY API function
 *
 *	This file contains declarations and definitons for use by
 *	the DOSCOPY function, its helper functions, and the test
 *	functions.
 *
 *	NOTES:
 *
 *	1)  The contents of this file are intended for internal use only,
 *	    although it may be appropriate to export parts of it to other
 *	    header files.
 *
 *
 */


/*************************** Constants **********************************/


#define MINFEALISTSIZE (sizeof(struct FEAList) - sizeof(struct FEA))

/* Boolean constants (in case they're not defined elsewhere) */
#ifndef FALSE
#define FALSE	(1 == 0)
#define TRUE	(! FALSE)
#endif

#define DEFAULT_FINDFIRST_HANDLE    0x0001  /* System default handle for
					       directory searches */
#define ALLOCATE_FINDFIRST_HANDLE   0xFFFF  /* Allocate a new handle for
					       directory searches */

/* WARNING:  DEVICE_PREFIX must not contain any DBCS leading
 *	     bytes and must not contain any lower case letters.
 */

#define DEVICE_PREFIX		"\\DEV\\"   /* Prefix for device's pathname */
#define DEVICE_PREFIX_LEN	5

#define WILDCARD_MATCH_ALL	"*"	    /* Wildcard specifier to match
					       every file in a directory */
#define CURRENT_DIRECTORY	"."	    /* Shorthand for current
					       directory */
#define PARENT_DIRECTORY	".."	    /* Shorthand for parent
					       directory */

#define MIN_IO_BUF_SIZE		4096	    /* Minimum buffer needed for I/O
					       operations */

#define MAX_IO_BUF_SIZE		65535	    /* Maximum buffer needed for I/O
					       operations */

#define NONSHARED	       0x0000

/*************************** Structures *********************************/

/* Parameters to be passed to the copying functions.
 * We store them in a structure so that only one pointer need be passed in
 * each call, which conserves stack space.
 */

static struct copy_parms {

    /* Global buffers and data */

    char		szSourcePath[MAXPATHLEN] ;  /* Full source path */
    char		szTargetPath[MAXPATHLEN] ;  /* Full target path */
    unsigned char	usSourceType ;		    /* Source object type */
    unsigned char	usTargetType ;		    /* Target object type */
    unsigned short	fsOpMode ;		    /* Copy operation mode */
    char far *		pszBuf ;		    /* I/O / EA buffers */
    unsigned		cuBufSize ;		    /* size of pszBuf */
    unsigned		uBufRWSize;		    /* I/O size of pszBuf */
    struct EAOP		eaopData ;		    /* Struct for EA work */

    /* Stuff used in CopyTree */

    struct FileFindBuf	findbufSource ;
    unsigned		uFileAttr ;
    unsigned		uSearchCount ;
    unsigned		uRetVal ;

    /* Stuff used in CopyFile */

    struct FileStatus	fstsSourceInfo ;
    struct FileStatus	fstsTargetInfo ;
};

/* Opmode flags - see DosCopy spec for details */

#define CM_REPLACE_EXIST    0x01	  /* Replace existing file */
#define CM_APPEND	    0x02	  /* Append to (existing file) */
#define CM_EA_FAIL_COPY	    0x04	  /* fail copy if EAs not supported */
					    /* by destination file system */

#define CM_ALL		    (CM_REPLACE_EXIST | CM_APPEND | CM_EA_FAIL_COPY)


/* Object types */

#define COT_FILE	0x01	   /* Object is a file */
#define COT_DIRECTORY	0x02	   /* Object is a directory */
#define COT_PARENT	0x04	   /* Object does not exist but its parent does
				      (and is a directory) */
#define COT_DEVICE	0x08	   /* Object is a character device */
#define COT_OTHER	0x10	   /* Object is none of the above */


/* Info flags for copy_tree() */
#define CTF_SOURCE_APPEND_SLASH	    0x01      /* Append \ to source path */
#define CTF_TARGET_APPEND_SLASH	    0x02      /* Append \ to target path */


/* Info flags for copy_file() */
#define CFF_SOURCE_IS_FILE	    0x01      /* Source is a file */
#define CFF_TARGET_IS_FILE	    0x02      /* Target is a file */
#define CFF_TARGET_FILE_EXISTS	    0x04      /* Target file already exists */

/* bit definitions for file attributes */

#define FA_READ_ONLY	  0x0001      /* read only file		    */
#define FA_HIDDEN	  0x0002      /* hidden file		    */
#define FA_SYSTEM	  0x0004      /* system file		    */
#define FA_LABEL	  0x0008      /* volume label - exclusive   */
#define FA_SUBDIR	  0x0010      /* subdirectory		    */
#define FA_ARCHIVE	  0x0020      /* file archive		    */

/* bit definitions for DosOpen ActionTaken */

#define ACTION_EXISTED	1
#define ACTION_CREATED	2
#define ACTION_REPLACED 3

/* bit definitions for DosOpen OpenFlag */

#define OF_FAIL		    0x0000
#define OF_OPEN_FILE	    0x0001
#define OF_EXISTING_FILE    0x0001
#define OF_REPLACE_FILE	    0x0002
#define OF_CREATE_FILE	    0x0010

/* bit definitions for DosOpen OpenMode */

#define OM_DRIVE	 0x8000		/* open as "a:" for direct I/O	 */
#define OM_SYNC		 0x4000		/* write sectors before return	 */
#define OM_FAIL_RC	 0x2000		/* bypass critical error handler */
#define OM_NO_CACHE	 0x1000		/* caching is not advisable	 */
#define OM_SEQUENTIAL	 0x0100		/* File access mainly sequential */
#define OM_PRIVATE	 0x0080		/* handle private/not inherited	 */
#define OM_DENY_RW	 0x0010		/* deny read/write access	 */
#define OM_DENY_WRITE	 0x0020		/* deny write access		 */
#define OM_DENY_READ	 0x0030		/* deny read access		 */
#define OM_DENY_NONE	 0x0040		/* deny neither read nor write	 */
#define OM_READ_ONLY	 0x0000		/* access read only		 */
#define OM_WRITE_ONLY	 0x0001		/* access write only		 */
#define OM_READ_WRITE	 0x0002		/* access read/write		 */

/* definitions for DosChgFilePtr */

#define CFP_MT_START	 0	     /* move to offset from start   */
#define CFP_MT_CURRENT	 1	     /* to current location + offset*/
#define CFP_MT_EOF	 2	     /* to eof + offset		    */

/* bit definitions for DosSetSigHandler */

#define SH_DEFAULT   0		 /* take system default action	     */
#define SH_IGNORE    1		 /* signal is to be ignored	     */
#define SH_ROUTINE   2		 /* RoutineAddress has handler	     */
#define SH_ERROR     3		 /* error to signal this condition   */
#define SH_RESET     4		 /* reset signal		     */

#define SH_SIGINTR   1		 /* ctrl-C			     */
#define SH_SIGPIPE   2		 /* pipe owner ended		     */
#define SH_SIGTERM   3		 /* program terminated		     */
#define SH_SIGBREAK  4		 /* ctrl-break			     */

/* definitions for DosDevIOCtl	*/

#define IOCTL_CAT_DISK	   0x08	 /* disk/diskette control	     */

#define IOCTL_LOCK	   0x00	 /* lock drive		  ???????    */
#define IOCTL_UNLOCK	   0x01	 /* unlock drive	  ???????    */
#define IOCTL_MEDIA	   0x02	 /* redetermine media	  ???????    */
#define IOCTL_GET_PARMS	   0x63	 /* get device parameters ???????    */

/***************************** Macros ***********************************/

#define FARPTRFROMSEL(sel) ((void far *)MKULNG(0,sel))

#define MKULNG(l,h)  ((unsigned long)(((unsigned short)(l)) | \
			 ((unsigned long)((unsigned short)(h))) << 16))

#define FPF_SEG(fp) (*((unsigned far *)&(fp) + 1))
#define FPF_OFF(fp) (*((unsigned far *)&(fp)))

#define IS_ROOT_DIR(p)	((!((p)[1] == ':') || (p)[3]) ? FALSE : IsRootDir(p))


#define MIN(a,b)    (((a) < (b)) ? (a) : (b))
