/*static char *SCCSID = "@(#)fsc.h	6.6 91/12/16";*/
/*
 *	File System Control block - FSC
 *
 *	The FSC is a structure that is pointed to by VPBs and SFTs to
 *	keep track of the file system that is associated with a certain
 *	volume in the drive. It contains pointers to ALL the entry points
 *	for the various functions that an FSD (File System Driver)
 *	is supposed to provide.
 *
 *	An FSD may also provide groups of optional services, such as pageio
 *	functions or network resolver functions.  A functional group must
 *	be fully supported; an FSD that exports entry points to some but not
 *	all of any functional group will not be loaded.  The basic core
 *	of 30 or so entry points is considered a group (the REQUIRED group).
 *
 *	A functional group may be added quite simply by assiging it an id
 *	(this is just an equate, such as FSGroup_PAGEIO; in this file) and
 *	adding its entry points to the FS_ENTRY (below) and the fscNameList
 *	in fsc.asm.
 *
 *	In addition, the kernel will support emulation of some functionality
 *	groups, for the case where the FSD does not directly support (ie,
 *	export entry points for) the functionality and the functionality is
 *	needed for system operation.  The address of the emulation routine
 *	for an entry point will be entered directly into the FSC in this case.
 *	Emulation will therefore be transparent to callers.  See the
 *	fscnameent macro and fscNameList in fsc.asm.
 *
 *	The FSCs in the system are all kept in ONE segment that is
 *	managed very simply.  One segment will allow more than 500 FSCs in
 *	the system, which is clearly adequate.  The structures are managed
 *	as an array of records, with GDT_FSC representing the selector to
 *	access the segment.  Only the segments limits and the FSC records
 *	are stored in the segment.
 *
 *	GDT_FSC:0   +-------------------+
 *		    | word: fss_Limit	|-----+
 *		    +-------------------+     |
 *		    | FSC structure	|     |
 *		    +-------------------+     |
 *			    ...		      |
 *		    +-------------------+     |
 *		    | last FSC struc.	|     |
 *		    +-------------------+     |
 *					 <----+ 1 past last byte in segment
 *
 *	An FSC (an hence the file system it represents) is known by it's
 *	offset into the FSC segment.
 */

/*
 *   Structure layout of the File System Control block (FSC)
 *
 *   This structure defines the layout of the table that is used by the
 *   kernel to call the appropriate entry point in the FSD driver to carry
 *   out the operation that is required.
 *
 *   A typical call sequence would be something like
 *
 *	CALL	ES:[DI].FS_READ
 *
 *   WARNING ** The names in FS_ENTRY must match the names in fscNameList,  **
 *	     ** both in spelling and in order.  See fsc.asm.		    **
 */

/* WARNING: This structure must match the fscnameent macro in fsc.asm. */

struct fscnameentstruc {
    unsigned long FSCNmEnt_Emulation;
    unsigned char FSCNmEnt_Group;
    unsigned char FSCNmEnt_NameLen;
    unsigned char FSCNmEnt_ProcName;
};

/* WARNING: This structure must match the uncfscentr macro in fsc.asm. */

struct uncfscentrstruc {
    unsigned long  UNCfsc_VpbID;  /* Unique ID UNC VPB */
    unsigned long  UNCfsc_FSCptr; /* Hold Seg:Ofs to UNC FSD's FSC */
    unsigned short UNCfsc_hVPB;	  /* Handle to VPB in VPB Seg(offset) */
    unsigned short UNCfsc_Active; /* Does this entry contain UNC FSD Info? */
};

/* WARNING: This structure must match the uncfscList in fsc.asm. */

struct uncliststruc {
    struct uncfscentrstruc UNCfsc_1;
    struct uncfscentrstruc UNCfsc_2;
    struct uncfscentrstruc UNCfsc_3;
    struct uncfscentrstruc UNCfsc_4;
};

/*
 * Names of FSD functionality groups go here.
 */
#define FSGroup_REQUIRED     0	  /* base set of required entry points	     */
#define FSGroup_PAGEIO	     1	  /* pageio functions			     */
#define FSGroup_SDTIMEONLY   2	  /* elements used only at shutdown	     */
#define FSGroup_UNCREQRD     3	  /* Required entry point for UNC redirs     */
#define FSGroup_FILELOCKS    4	  /* Entry points for new 2.00 filelock fcns */


struct FS_ENTRY {
    unsigned long FS_ATTRIBUTE;		/* -> FSD attribute. (in FSD memory) */
    unsigned long FS_NAME;		/* -> FSD name.	     (in FSD memory) */

/* Function dispatch table */

    unsigned long FS_ATTACH;		/* DosQFsAttach, DosFsAttach */
    unsigned long FS_CHDIR;		/* DosChdir */
    unsigned long FS_CHGFILEPTR;	/* DosChgFilePtr */
    unsigned long FS_CLOSE;		/* DosClose */
    unsigned long FS_COPY;		/* DosCopy */
    unsigned long FS_DELETE;		/* DosDelete */
    unsigned long FS_EXIT;		/* DosExit */
    unsigned long FS_FILEATTRIBUTE;	/* DosFileInfo, DosSetFileMode */
    unsigned long FS_FILEINFO;		/* DosQFileInfo, DosSetFileInfo */
    unsigned long FS_FILEIO;		/* DosFileIO */
    unsigned long FS_FINDCLOSE;		/* DosFindClose */
    unsigned long FS_FINDFIRST;		/* DosFindFirst */
    unsigned long FS_FINDFROMNAME;	/* DosFindFromName-Private to server */
    unsigned long FS_FINDNEXT;		/* DosFindNext */
    unsigned long FS_FINDNOTIFYCLOSE;	/* DosFindNotifyClose */
    unsigned long FS_FINDNOTIFYFIRST;	/* DosFindNotifyFirst */
    unsigned long FS_FINDNOTIFYNEXT;	/* DosFindNotifyNext */
    unsigned long FS_FSINFO;		/* DosQFsInfo, DosSetFsInfo */
    unsigned long FS_INIT;		/* -- No corresponding API */
    unsigned long FS_IOCTL;		/* DosDevIoctl */
    unsigned long FS_MKDIR;		/* DosMkdir */
    unsigned long FS_MOUNT;		/* -- No corresponding API */
    unsigned long FS_MOVE;		/* DosMove */
    unsigned long FS_NEWSIZE;		/* DosNewsize */
    unsigned long FS_NMPIPE;		/* All named pipe related API's */
    unsigned long FS_OPENCREATE;	/* DosOpen */
    unsigned long FS_PATHINFO;		/* DosQPathInfo, DosSetPathInfo */
    unsigned long FS_PROCESSNAME;	/* -- No corresponding API */
    unsigned long FS_READ;		/* DosRead, DosReadAsync */
    unsigned long FS_RMDIR;		/* DosRmdir */
    unsigned long FS_SETSWAP;		/* -- No correcponding API */
    unsigned long FS_WRITE;		/* DosWrite, DosWriteAsync */

    unsigned long FS_OPENPAGEFILE;	/* init time only */
    unsigned long FS_ALLOCATEPAGESPACE; /* size swap file */

/* the following fields are required by FSDs that set the LOCKINFO bit */

    unsigned long FS_CANCELLOCKREQUEST; /* DosCancelLockRequest */
    unsigned long FS_FILELOCKS;		/* DosSetFileLocks */

/* The following item is to query UNC paths and is required for UNC redirs */

    unsigned long FS_VERIFYUNCNAME;	/* Used to save function addresses */

/* the following fields were moved to the end to simplify Shutdown */

    unsigned long FS_COMMIT;		/* DosBufReset, DosClose */
    unsigned long FS_DOPAGEIO;		/* perform paging */
    unsigned long FS_FSCTL;		/* DosFsCtl */
    unsigned long FS_FLUSHBUF;		/* DosBufReset */
    unsigned long FS_SHUTDOWN;		/* DosShutdown */

/* The following items are only used at shutdown time */

    unsigned long FS_SDCHGFILEPTR;	/* Used to save function addresses */
    unsigned long FS_SDFSINFO;		/* at shutdown time.  These functions */
    unsigned long FS_SDREAD;		/* will only be called by shutdown */
    unsigned long FS_SDWRITE;		/* filters. */
};

/*
 * Bit masks for FS_ATTRIBUTE (remember FS_ATTRIBUTE points to the attribute
 * word rather than containing it directly.)
 */

#define FS_ATTR_REMOTE		0x0001	/* 0 = local FSD, 1 = remote FSD     */
#define FS_ATTR_UNC		0x0002	/* 0 = normal, 1 = this is UNC FSD   */
#define FS_ATTR_LOCKINFO	0x0004	/* 0 = no notice, 1=notify filelocks */
#define FS_ATTR_LVL7		0x0008	/* 0 = no level 7 requests, 1 = yes  */
#define FS_ATTR_PIPESVR		0x0010	/* 0 = don't FSD on PIPE req,1 = yes */
#define FS_ATTR_LOW_USED      (FS_ATTR_REMOTE | FS_ATTR_UNC | FS_ATTR_LOCKINFO | FS_ATTR_LVL7 | FS_ATTR_PIPESVR)
#define FS_ATTR_LOW_RESV      (~ FS_ATTR_LOW_USED)	    /* Reserved bits */

/* bit masks for FS_ATTRIBUTE (High Word) */
#define FS_ATTR_VERNO		0x7000	/* bits 28-30 version no */
#define FS_ATTR_EA		0x8000	/* bit 31 -> 1 = extended attribute */
#define FS_ATTR_HI_USED	     (FS_ATTR_VERNO | FS_ATTR_EA)
#define FS_ATTR_HI_RESV	     (~ FS_ATTR_HI_USED)	    /* Reserved bits */

/* equates for commit type */
#define FS_COMMIT_ALL		2	/* all handles commit */
#define FS_COMMIT_ONE		1	/* one handle commit */

/* equates for close type */
#define FS_CL_ORDINARY		0	/* ordinary close */
#define FS_CL_FORPROC		1	/* final close for process */
#define FS_CL_FORSYS		2	/* final close for system */

/*
 *   Reserved symbols used for dispatch control.
 *
 *   Some bodies of code, like the local fat file system,
 *   don't have FSCs.  Instead of using a normal FSC offset, they use special
 *   offsets so that the dispatch code will know to call them rather than
 *   dispatch through an FSC.  All reserved values must be above FSC_RESERVED.
 *   All real FSCs must have offsets below FSC_RESERVED.
 */

#define FSC_RESERVED	(64*1024 - size FS_ENTRY)
#define FSC_LOCAL	FSC_RESERVED

#define FSC_BAD		0xffff		/* Special error detection value. */

/*
 *   Structure layout of the Mini File System Control block (FSC)
 *
 *   This structure defines the layout of the table that is used by the
 *   kernel to call the appropriate entry point in the Mini FSD driver to carry
 *   out the operation that is required.
 *
 *   A typical call sequence would be something like
 *
 *	CALL	ES:[DI].MFS_READ
 *
 *   WARNING ** The names in MFS_ENTRY must match the names in mfscNameList, **
 *	     ** both in spelling and in order.  See fsc.asm.		     **
 */


struct mFS_ENTRY {
/* Function dispatch table */
    unsigned long MFS_CHGFILEPTR;	/* DosChgFilePtr */
    unsigned long MFS_CLOSE;		/* DosClose */
    unsigned long MFS_INIT;		/* -- No corresponding API */
    unsigned long MFS_OPEN;		/* DosOpen */
    unsigned long MFS_READ;		/* DosRead, DosReadAsync */
    unsigned long MFS_TERM;		/* DosRead, DosReadAsync */

};


/* Fixed fields at front of FSC segment */

struct FSCSEG {
    unsigned short fss_Limit;		/* Offset PAST last allocated byte */
    unsigned short fss_ShutdownFlags;	/* flags for shutdown */
    unsigned short fss_SDWaitCount;	/* number of processes pending before */
    unsigned short fss_pad;		/* shutdown can commence (DWORD align)*/
/* First FSC goes HERE.  This is offset described by FSCBASE. */
};

#define FSCBASE	  sizeof(struct FSCSEG) /* Offset of first FSC in array */
