#ifndef		V_FS_H
#define		V_FS_H

/*		Returned by file->seek() and file->tell() on error */
#define	INVALID_IO_OFFSET		0xFFFFFFFF

#ifdef	__cplusplus
extern "C" {
#endif	/* __cplusplus */
	/*	========== FS service routines ================================ */
	/*	Enumerates contents of current directory (and, optionally, all
	 *	subdirectories).
	 *	Input:
	 *		- dir_callback (can be NULL): caller - supplied callback
	 *			for directories;
	 *		- file_callback (can be NULL): caller - supplied callback
	 *			for files;
	 *		- recursive: if nonzero, fsScan enumerates all subdirs.
	 *	Notes.
	 *		1. dir_callback always called BEFORE directory processing;
	 *	for example, if recursive == 0 than fsScan called 'dir_callback',
	 *	and than, for all files in directory, 'file_callback'.
	 *		2. Under MS OSes, names of files and directories passed in
	 *	UNIX - style: "c:\winnt" becomes "//c/winnt", etc.
	 */
	void		V_GLOBAL	fsEnumFiles(
		void (V_CALL *dir_callback)(char *full_unix_style_dir_name),
		void (V_CALL *file_callback)(char *full_unix_style_file_name),
		vboolean recursive);
	/* Splits full UNIX path */
	void		V_GLOBAL	fsSplitPath(char *full_path,
    	char *dir_ret,char *name_ret,char *ext_ret);
	void		V_GLOBAL	fsMakePath(char *path_ret,
    	char *dir,char *name, char *ext);
	/* Replaces extension in filename */
	void		V_GLOBAL	fsReplaceExt(char *dst,char *name,char *ext);
	/*	========== VFS service routines ================================ */
	/*	Mounts all recognized volumes in current directory and all 
	 *	subdirectories */
	void	V_GLOBAL	fsInit(void);
	/*	Unmounts all virtual filesystems */
	void	V_GLOBAL	fsShutdown();
	/*	========== file service routines ============================== */
	/*
	 * All names in UNIX form. For MS OSes, see note #2 for
     * 'fsEnumFiles()'. These functions perform minimal validity checks
     * and than call appropriate method from ioport_base_t object.
	 */
	vsize_t	V_GLOBAL	fileRead(vhandle_t handle,void *buf,vsize_t len);
	vsize_t	V_GLOBAL	fileWrite(vhandle_t handle,void *buf,vsize_t len);
	vsize_t	V_GLOBAL	fileSeek(vhandle_t handle,vssize_t offset,int whence);
	vsize_t	V_GLOBAL	fileTell(vhandle_t handle);
	vsize_t	V_GLOBAL	fileSize(vhandle_t handle);
	vboolean	V_GLOBAL	fileControl(vhandle_t handle,unsigned code,
    	void *parameters);
	vboolean	V_GLOBAL	fileClose(vhandle_t handle);
    /* IO port factory functions */
	vhandle_t		V_GLOBAL	fileOpenRead(char *name);
	vhandle_t		V_GLOBAL	fileOpenWrite(char *name);
	vhandle_t		V_GLOBAL	fileOpenAppend(char *name);
	vboolean		V_GLOBAL	fileCopy(char *dst_name,char *src_name,vboolean overwrite);
	/*
	 * Keeps data in temp file, at fileClose() renames it
	 * (implemented in safeover.c).
	 */
	vhandle_t		V_GLOBAL	fileOpenSafeOverwrite(char *name);
	/*
	 * Erases output file without saving its contents.
	 * If the same file already present, it will be preserved.
	 */
	void			V_GLOBAL	fileCancelSafeOverwrite(vhandle_t handle);
	/* IO port misc functions */
	vboolean	V_GLOBAL	fileEof(vhandle_t file);
	char_t		V_GLOBAL	fileGetc(vhandle_t file);
	/*	Reads little-endian word */
	u16_t		V_GLOBAL	fileGetLittleShort(vhandle_t f);
	/*	Reads little-endian dword */
	u32_t		V_GLOBAL	fileGetLittleLong(vhandle_t f);
	vboolean	V_GLOBAL	filePutc(vhandle_t file,int c);
	/* NOTE: Writes system-dependent EOL after the string. */
	vboolean	V_GLOBAL	filePuts(vhandle_t file,char *str);
	/* End-of-line sequence NOT APPENDED */
	vboolean	V_GLOBAL_VA	filePrintf(vhandle_t file,const char *fmt,...);
	/*	Writes little-endian word */
	void		V_GLOBAL	filePutLittleShort(vhandle_t f,u16_t w);
	/*	Writes little-endian dword */
	void		V_GLOBAL	filePutLittleLong(vhandle_t f,u32_t dw);
#ifdef	BUILD_DLL
	/*
	 * Quite useful for Delphi apps
	 */
	void V_GLOBAL libvDosPathToUnixPath(char *unix_path_ret,char *dos_path);
	void V_GLOBAL libvUnixPathToDosPath(char *dos_path_ret,char *unix_path);
#endif	/* BUILD_DLL */

#ifdef	__cplusplus
}

#endif	/* __cplusplus */

#endif	/* V_FS_H */
