/*static char *SCCSID = "@(#)find.h	6.3 91/11/13";*/
/*	SCCSID = @(#)find.h	6.3 91/11/13 */

//	 IBM/Microsoft Confidential
//
//	 Copyright (c) IBM Corporation 1987, 1989
//	 Copyright (c) Microsoft Corporation 1987, 1989
//
//	 All Rights Reserved

//	WARNING - Do not change this structure without examining the
//		  code for w_Findfirst, w_Findnext (the pmode API search
//		  calls.)  Also examine SearchHand and SearchBuf in pdata.asm
//

#define	MAXPNAME		13
#define	MAXMETANAME		24
#define	CNYBUFLEN		1024

//   Note find_buf_cominfo is defined outside of find_buf becuase MASM will not
//   allow nested structures.

struct find_buf_cominfo {
//----+----+----+----+----+----+----+----+----+----+----+----+----+----+----;
//	     C	A  V  E	 A  T	  P  R	O  G  R	 A  M  M  E  R		    ;
//									    ;
	char		find_buf_drive;		// drive of search
	char		find_buf_name[MAXMETANAME];// asciiz name with metas
	char		find_buf_sattr;		// attribute of search
	ushort_t	find_buf_LastEnt;	// LastEnt
	ushort_t	find_buf_DirStart;	// DirStart
	ushort_t	find_buf_hVPB;		// handle to VPB for drive
	char		find_buf_NetID[2];	// Reserved for NET
	char		find_buf_flags;		// flags - whether name contains metas
//									    ;
//	     C	A  V  E	 A  T	  P  R	O  G  R	 A  M  M  E  R		    ;
//----+----+----+----+----+----+----+----+----+----+----+----+----+----+----;
};

#define	OLD_SEARCH_INFO_SIZE	21  // 21-byte area search continuation info
				    // used to be returned in.
struct find_buf32 {
	ushort_t	find_buf32_handle;
	ushort_t	find_buf32_signature;
	ulong_t		find_buf32_position;
	char		find_buf32_name[1];
};

struct find_buf {
	char		find_buf_prefix[OLD_SEARCH_INFO_SIZE];

//	This is the output format used for the Int21h search returns

	char		find_buf_attr;			// attribute found
	ushort_t	find_buf_time;			// time
	ushort_t	find_buf_date;			// date
	ushort_t	find_buf_size_l;		// low(size)
	ushort_t	find_buf_size_h;		// high(size)
	char		find_buf_pname[MAXPNAME];	// packed name
};


//	The follow structure defines Searchbuf during rename operations

struct find_buf_search {
	struct	find_buf_cominfo fbs_prefix;
	struct	dir_entry fbs_dir_entry;	// dir.inc
};

//	SRCHBUFSIZE = size of control buffer + size of directory entry
//		This is the size of the entity returned by DOS_Search_First,
//		and DOS_Search_Next.

#define	SRCHBUFSIZE		sizeof(struct find_buf_search)



//	This is the output format used for the pmode API search returns
//	for InfoLevel 1
//
//	WARNING Code in dossrch.asm assumes that api_fbuf_pname is
//		last field in api_fbuf, and that api_fbuf_namelen is
//		immediately followed by api_fbuf_pname.
//		Same rules apply to ssi_fbuf_namelen and ssi_fbuf_pname.

struct api_fbuf {
	ushort_t	api_fbuf_crtdate;		// creation date
	ushort_t	api_fbuf_crttime;		// creation time
	ushort_t	api_fbuf_accdate;		// access date
	ushort_t	api_fbuf_acctime;		// access time
	ushort_t	api_fbuf_wrtdate;		// write date
	ushort_t	api_fbuf_wrttime;		// write time
	ushort_t	api_fbuf_size_l;		// low(size)
	ushort_t	api_fbuf_size_h;		// high(size)
	ushort_t	api_fbuf_alloc_l;		// low(allocation)
	ushort_t	api_fbuf_alloc_h;		// high(allocation)
	ushort_t	api_fbuf_attr;			// attribute
	char		api_fbuf_namelen;		// length of name
	char		api_fbuf_pname[MAXPNAME];	// name
};


//	This is the output format used for the pmode API search returns
//	for infolevel 2
//
//	WARNING Code in dossrch.asm assumes that api_fbuf_pname is
//		last field in api_fbuf, and that api_fbuf_namelen is
//		immediately followed by api_fbuf_pname.
//		Same rules apply to ssi_fbuf_namelen and ssi_fbuf_pname.

struct api_fbuf2 {
	ushort_t	api_fbuf2_crtdate;		// creation date
	ushort_t	api_fbuf2_crttime;		// creation time
	ushort_t	api_fbuf2_accdate;		// access date
	ushort_t	api_fbuf2_acctime;		// access time
	ushort_t	api_fbuf2_wrtdate;		// write date
	ushort_t	api_fbuf2_wrttime;		// write time
	ulong_t		api_fbuf2_size;			// size
	ulong_t		api_fbuf2_alloc;		// allocation
	ushort_t	api_fbuf2_attr;			// attribute
	ulong_t		api_fbuf2_cblist;		// length of FEAlist
	char		api_fbuf2_namelen;		// length of name
	char		api_fbuf2_pname[MAXPNAME];	// name
};

//	This is the output format used for the pmode API search returns
//	for InfoLevel 1 for Installable file systems

struct ifs_fbuf {
	ushort_t	ifs_fbuf_crtdate;		// creation date
	ushort_t	ifs_fbuf_crttime;		// creation time
	ushort_t	ifs_fbuf_accdate;		// access date
	ushort_t	ifs_fbuf_acctime;		// access time
	ushort_t	ifs_fbuf_wrtdate;		// write date
	ushort_t	ifs_fbuf_wrttime;		// write time
	ushort_t	ifs_fbuf_size_l;		// low(size)
	ushort_t	ifs_fbuf_size_h;		// high(size)
	ushort_t	ifs_fbuf_alloc_l;		// low(allocation)
	ushort_t	ifs_fbuf_alloc_h;		// high(allocation)
	ushort_t	ifs_fbuf_attr;			// attribute
	char		ifs_fbuf_namelen;		// length of name
	char		ifs_fbuf_pname[MAXCOMPLEN];	// name
};

//  Special server support for search continuation
//
//  The server has the requirement that it be able to restart a search from
//  somewhere within the directory, not necessarily where it last left off.
//  This is due to the fact that it asks for more than it needs, and caches
//  the rest of the information so that it does not repeatedly have to send
//  requests back and forth across the net.
//  In order to provide this support, we use the special ssi_ structures
//  below, which contain an additional DWORD at the beginning which identifies
//  the entry being passed. The file system should be able to restart the
//  search from the position that this field indicates.
//
//  For the FAT file system this DWORD comprises of a WORD for the cluster
//  of the directory on disk, and a WORD that indexes into this cluster.
//
//  These structures are used by DosFindFirst/DosFindFirst2/DosFindNext
//  and DosFindFromName if fSharing is TRUE (i.e. this is the server).

// ssi = special server interface - offsets used only when fSharing is
//	 true, they provide special support to network server.
//
// ssi_fbuf_common points to the structure api_fbuf which is used by
// FindFirst/Next for the non-server case. In order to access the fields,
// the same field names can be used as follows:
//
//   mov	    ax,ds:[si].ssi_fbuf_common.api_fbuf_alloc
//
struct ssi_fbuf {
	ulong_t	ssi_fbuf_Position;	// Positional reference for entry
	struct	api_fbuf ssi_fbuf_common;
};


//  ssi = special server interface - offsets used only when fSharing is
//	 true, they provide special support to network server.
//
// ssi_fbuf2_common points to the structure api_fbuf2 which is used by
// FindFirst2/Next for the non-server case. In order to access the fields,
// the same field names can be used as follows:
//
//   mov	    ax,ds:[si].ssi_fbuf2_common.api_fbuf2_alloc
//
struct ssi_fbuf2 {
	ulong_t	ssi_fbuf2_Position;	    // Positional reference for entry
	struct	api_fbuf2 ssi_fbuf2_common;
};


//* FAT FS directory entry identifier
//
// This structure defines the fields used for the FAT file system to identify
// the directory entry. The fields can be used to access the information from
// ssi_fbuf_Position and ssi_fbuf2_Position.
//
struct ssi_FATFS_Position {
	ushort_t	ssi_LastEnt;		// LastEnt  - Directory Position
	ushort_t	ssi_DirStart;		// DirStart - Directory ID
};


// Make sure FATFS_Position is a DWORD
// Make sure that Position field is as big as the FATFS_Position structure

/* ASM
.errnz (size ssi_FATFS_Position - 4)
.errnz ((size ssi_FATFS_Position) - (ssi_fbuf2_common - ssi_fbuf2_Position))
.errnz ((size ssi_FATFS_Position) - (ssi_fbuf_common  - ssi_fbuf_Position))
*/


//  Equates for the flag field passed to FS_FindFirst/FS_FindNext/
//  FS_FindFromName
//
#define	FSSRCH_NOPOS	0	    // FSD should not return position field(s)
#define	FSSRCH_POS	1	    // FSD should return position field(s)

// This is the layout of an BMP record in the Global Bmp segment. It is used
// for all processes in the system.

struct CNY_GLOBAL {
	ushort_t	CNY_Next;	// offset to next global record
	ushort_t	CNY_PID;	// process id that owns this handle
	ushort_t	CNY_hVPB;	// VPB Handle
	ushort_t	CNY_InfoLevel;	// InfoLevel
	ulong_t		CNY_FSC;	// FSC pointer
	char		CNY_Flags;	// flags
	char     CNY_BUF[CNYBUFLEN];	// InfoBuf pointer
};

// This is the layout of an BMP record in the Global Bmp segment. It is used
// for all processes in the system.

struct FNY_GLOBAL {
	ushort_t	FNY_Next;	// offset to next global record
	ushort_t	FNY_PID;	// process id that owns this handle
	ushort_t	FNY_SubSys_Handle;	// Handle for Subsystem
	ushort_t	FNY_hVPB;	// VPB Handle
	ulong_t		FNY_FSC;	// FSC pointer
	ushort_t	FNY_InfoLevel;	// InfoLevel
	char		FNY_Flags;	// flags
};

// This is the layout of an RMP record for all ChangeNotify searches.
// The WFP must be the last thing in the structure.

struct CNY_FS {
	ushort_t	CNY_FS_Handle;		// FS Handle
	ushort_t	CNY_FS_ChangeCnt;	// Number of Changes Required
	ushort_t	CNY_FS_WrkChangeCnt;	// Working ChangeCnt Required
	ushort_t	CNY_FS_Attribute;	// Attributes to Watch
	ushort_t	CNY_FS_hVPB;		// Corresponding hVPB
	ushort_t	CNY_FS_WILDPTR;	// count of chars for the end
						// of last component in FAT_WFP
						// that does not have a wild char
	ushort_t	CNY_FS_WFPLEN;		// length of WFP
	char	CNY_FS_WFP[PMPATHLEN];		// WFP name to Watch
};

// Equates for the flag field in FNY_GLOBAL struc

#define fFNY_FREE	0	    // handle is not in use and is good
#define fFNY_INUSE	1	    // handle in use by a findnotify thread
#define fFNY_IN_PROG	2	    // a findnotifynext thread is in 'action'
#define fFNY_CLOSED	4	    // this handle is closed already

// This is the layout of an RMP record for the FAT FS. The WFP must be the last
// thing in the structure.

struct FNY_FAT {
	ushort_t	FNY_FAT_Handle;		// FAT FS Handle
	ushort_t	FNY_FAT_ChangeCnt;	// Number of Changes Required
	ushort_t	FNY_FAT_WrkChangeCnt;	// Working ChangeCnt Required
	ushort_t	FNY_FAT_Attribute;	// Attributes to Watch
	ushort_t	FNY_FAT_hVPB;		// Corresponding hVPB
	ushort_t	FNY_FAT_WILDPTR;	// count of chars for the end
						// of last component in FAT_WFP
						// that does not have a wild char
	ushort_t	FNY_FAT_WFPLEN;		// length of WFP
	char	FNY_FAT_WFP[PMPATHLEN];		// WFP name to Watch
};

// Equates for FNY_FAT_hVPB field
#define fFNY_INVALID_hVPB	0xffff		// Volume has changed

// Equates for FNY_FAT_WILDPTR field
#define fFNY_NO_WILDCHAR	0		// no wild chars in FNY object
#define fFNY_OBJ_REMOVED	0xffff		// FNY object removed

// other miscellaneous FINDNOTIFY EQUATES

#define fFNY_DELETE		1		// the fnotify wake call is for
						// a delete/rename operation
#define fFNY_NODELETE		0		// not for del/rename operation

#define FNOTIFY_GROWDELT	2		// Number to allocate at a time
#define	FNOTIFY_INFOLEVEL1	1		// info Level 1


//	CONBUFSIZE = size of control structure used to continue a search

#define	CONBUFSIZE		sizeof(find_buf_cominfo)

//	Search handle space description constants.
//
//	Start with NextSrchH = 1, so BASSRCHH will be first value we actually
//	use.  When we hit ALLOCSRCH, we'll wrap back to BASESRCH.

#define	ALLOCSRCH		0xFFFF		// Value to request new handle
#define	BASESRCH		2		// Base of useable handle space

//	Flags for DosFindFirst
//	3     1 1 1 1 1 1 1
//	1 ... 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
//
//	R ... R N R R R R R R R R R A D V S H O
//
//
//
//	R	  Reserved; must be 0.
//
//	N	  Normal  files;  excludes  normal files if  bit
//		  15=1.  Includes  normal  files  if   bit  15=0
//		  (current behavior).  Normal  files  are  those
//		  without any mode bits set.
//
//	A	  Archive  bit; includes files with  the archive
//		  bit  set  if	bit  5=1.  Excludes  files  with
//		  archive bit set if bit 5=0.
//
//	D	  Subdirectory	bit;  includes subdirectories if
//		  bit 4=1.  Excludes subdirectories if bit 4=0.
//
//	V	  Volume  label	 bit; must be  0.  Volume labels
//		  cannot be accessed with DosFindFirst.
//
//	S	  System file  bit; includes sustem files if bit
//		  2=1.	Excludes system files if bit 2=0.
//
//	H	  Hidden file bit; includes hidden files  if bit
//		  1=1.	Excludes hidden files if bit 1=0.
//
//	O	  Read-Only  file bit; includes	 read-only files
//		  if  bit  0=1.  Excludes  read-only   files  if
//		  bit0=0.
//
//
//	If bit 15=1, then "normal" files will never be returned.
//	Other files will be returned only if  Attribute	 selects
//	at least as many mode bits (i.e.  A,  D, S,  H and R) as
//	are set for the file.  For example,  if bits 0 and 5 are
//	set to 1  and all  other bits  are 0, then  DosFindFirst
//	(and DosFindNext)  will return normal files, as well  as
//	files	with   the   archive   or  read-only  bit   set.
//	Additionally,  files  that  have  both	the  archive and
//	read-only bits	set  will be  returned.  Files	with any
//	other mode bits set will not be returned (even	if  they
//	also have one or  both of the archive and read-only bits
//	set).
//
//	If bit 15=0,  then  "normal" files, and files  with  the
//	Archive	 or  Read-Only bits  set  are  always  returned.
//	Files  with the Hidden, System	or Directory bit set are
//	only returned if those bits are set.


#define fDFF_ATTR_NOT_NORM	0x00008000  // do not find normal files
#define fDFF_ATTR_ARCHIVE	0x00000020  // find files with archive bit set
#define fDFF_ATTR_SUBDIR	0x00000010  // find subdirectories
#define fDFF_ATTR_VOLLABEL	0x00000008  // find volume labels
#define fDFF_ATTR_SYSTEM	0x00000004  // find files with system bit set
#define fDFF_ATTR_HIDDEN	0x00000002  // find hidden files
#define fDFF_ATTR_READ_ONLY	0x00000001  // find read only files
