/*
 * $Id: netfs.h,v 1.1 1993/12/02 20:45:46 Rhialto Exp $
 * $Log: netfs.h,v $
 * Revision 1.1  1993/12/02  20:45:46  Rhialto
 * Initial revision
 *
 *
 * Network file system data structures
 */

#include <stddef.h>

#ifndef CLIB_EXEC_PROTOS_H
#include <clib/exec_protos.h>
#endif
#ifndef CLIB_ALIB_PROTOS_H
#include <clib/alib_protos.h>
#endif

#ifndef DOS_H
#include "dos.h"
#endif

typedef struct {
    ULONG	    nfl_FileLock;   /* Remote identifier */
    ULONG	    nfl_Validation;
} NetFileLock;

typedef struct {
    ULONG	    nfh_FileHandle; /* Remote identifier */
    ULONG	    nfh_Validation;
} NetFileHandle;

typedef enum {
    pt_Retry = -1,
    pt_Request, pt_Reply, pt_AsyncReply,
    pt_Reset, pt_ResetReply
} Type;

typedef struct Packet {
    BYTE	    p_Type;
    BYTE	    p_Origin;
    BYTE	    p_Seq;	    /* Sequence number for reliable transnission */
    BYTE	    p_Ack;	    /* Acknowledgement */
#define COMMONSIZE  4
    union {
	/* Format for pt_Request */
	struct pu1 {
	    ULONG	    p1_Action;
	    ULONG	    p1_Arg[6];
	} p_Request;
	/* Format for pt_(Async)Reply */
	struct pu2 {
	    ULONG	    p2_Res1;
	    ULONG	    p2_Res2;
	    ULONG	    p2_Data[0];
	} p_Reply;
	/* Format for pt_Reset(Reply) */
	struct {
	    ULONG	    p3_Validation;
	} p_Reset;
	char		p_Pad[3*4+256+256];
    } p_Misc;
} Packet;

#define p_Action    p_Misc.p_Request.p1_Action
#define p_Arg	    p_Misc.p_Request.p1_Arg

#define p_Res1	    p_Misc.p_Reply.p2_Res1
#define p_Res2	    p_Misc.p_Reply.p2_Res2
#define p_Data	    p_Misc.p_Reply.p2_Data

#define p_Validation p_Misc.p_Reset.p3_Validation

#define REQSIZE(nargs)  (offsetof(Packet, p_Arg[0])+4*(nargs))

/* Standard reply size */
/*#define STDREPLY	offsetof(Packet, p_Data[0])*/
#define STDREPLY	(COMMONSIZE+sizeof(struct pu2))

#define MAXPKT		(COMMONSIZE+sizeof(struct pu1))
#define MAXDATA 	4096
#define PKTSIZE 	(MAXPKT + MAXDATA)

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

#define SRV_ADDR	1
#define CLI_ADDR	2
#define NETFS_PORT	0x25C	    /* randomly chosen */

#define PENDREADS	8

#ifndef Prototype
#define Prototype   extern
#endif
#ifndef Local
#define Local	    static
#endif

#include "proto.h"

