#ifndef _FCALL_H_ #define _FCALL_H_ 1 #ifdef __cplusplus extern "C" { #endif /* #pragma src "/sys/src/libc/9sys" #pragma lib "libc.a" */ #define VERSION9P "9P2000" #define MAXWELEM 16 typedef struct Fcall { uchar type; uint32 fid; uint16 tag; uint32 msize; /* Tversion, Rversion */ char *version; /* Tversion, Rversion */ uint16 oldtag; /* Tflush */ char *ename; /* Rerror */ Qid qid; /* Rattach, Ropen, Rcreate */ uint32 iounit; /* Ropen, Rcreate */ Qid aqid; /* Rauth */ uint32 afid; /* Tauth, Tattach */ char *uname; /* Tauth, Tattach */ char *aname; /* Tauth, Tattach */ uint32 perm; /* Tcreate */ char *name; /* Tcreate */ uchar mode; /* Tcreate, Topen */ uint32 newfid; /* Twalk */ uint16 nwname; /* Twalk */ char *wname[MAXWELEM]; /* Twalk */ uint16 nwqid; /* Rwalk */ Qid wqid[MAXWELEM]; /* Rwalk */ int64 offset; /* Tread, Twrite */ uint32 count; /* Tread, Twrite, Rread */ char *data; /* Twrite, Rread */ uint16 nstat; /* Twstat, Rstat */ uchar *stat; /* Twstat, Rstat */ int unixfd; /* Ropenfd */ /* 9P2000.u extensions */ uint32 errornum; /* Rerror */ uint32 uidnum; /* Tattach, Tauth */ char *extension; /* Tcreate */ } Fcall; #define GBIT8(p) ((p)[0]) #define GBIT16(p) ((uint16)(p)[0]<<0 |\ ((uint16)(p)[1]<<8)) #define GBIT32(p) ((uint32)((uint32)(p)[0]<<0 | \ ((uint32)(p)[1]<<8) | \ ((uint32)(p)[2]<<16) | \ ((uint32)(p)[3]<<24))) #define GBIT64(p) ((uint64)((uint64)(p)[0]<<0 | \ ((uint64)(p)[1]<<8) | \ ((uint64)(p)[2]<<16) | \ ((uint64)(p)[3]<<24) | \ ((uint64)(p)[4]<<32) | \ ((uint64)(p)[5]<<40) | \ ((uint64)(p)[6]<<48) | \ ((uint64)(p)[7]<<56))) #define PBIT8(p,v) (p)[0]=(v) #define PBIT16(p,v) (p)[0]=((uint16)(v)>>0);\ (p)[1]=((uint16)(v)>>8) #define PBIT32(p,v) (p)[0]=((uint32)(v)>>0);\ (p)[1]=((uint32)(v)>>8);\ (p)[2]=((uint32)(v)>>16);\ (p)[3]=((uint32)(v)>>24) #define PBIT64(p,v) (p)[0]=((uint64)(v)>>0);\ (p)[1]=((uint64)(v)>>8);\ (p)[2]=((uint64)(v)>>16);\ (p)[3]=((uint64)(v)>>24);\ (p)[4]=((uint64)(v)>>32);\ (p)[5]=((uint64)(v)>>40);\ (p)[6]=((uint64)(v)>>48);\ (p)[7]=((uint64)(v)>>56) #define BIT8SZ 1 #define BIT16SZ 2 #define BIT32SZ 4 #define BIT64SZ 8 #define QIDSZ (BIT8SZ+BIT32SZ+BIT64SZ) /* STATFIXLEN includes leading 16-bit count */ /* The count, however, excludes itself; total size is BIT16SZ+count */ #define STATFIXLEN (BIT16SZ+QIDSZ+5*BIT16SZ+4*BIT32SZ+1*BIT64SZ) /* amount of fixed length data in a stat buffer */ #define STATFIXLENU (STATFIXLEN+BIT16SZ+3*BIT32SZ) /* for 9P2000.u */ #define NOTAG (ushort)~0U /* Dummy tag */ #define NOFID (uint32)~0U /* Dummy fid */ #define NOUID (-1) /* Dummy uid */ #define IOHDRSZ 24 /* ample room for Twrite/Rread header (iounit) */ enum { Tversion = 100, Rversion, Tauth = 102, Rauth, Tattach = 104, Rattach, Terror = 106, /* illegal */ Rerror, Tflush = 108, Rflush, Twalk = 110, Rwalk, Topen = 112, Ropen, Tcreate = 114, Rcreate, Tread = 116, Rread, Twrite = 118, Rwrite, Tclunk = 120, Rclunk, Tremove = 122, Rremove, Tstat = 124, Rstat, Twstat = 126, Rwstat, Tmax, Topenfd = 98, Ropenfd }; uint32 convM2S(uchar*, uint32, Fcall*); uint32 convS2M(Fcall*, uchar*, uint32); uint32 sizeS2M(Fcall*); int statcheck(uchar *abuf, uint nbuf); uint32 convM2D(uchar*, uint32, Dir*, char*); uint32 convD2M(Dir*, uchar*, uint32); uint32 sizeD2M(Dir*); uint32 convM2Su(uchar*, uint32, Fcall*, int); uint32 convS2Mu(Fcall*, uchar*, uint32, int); uint32 sizeS2Mu(Fcall*, int); int statchecku(uchar *abuf, uint nbuf, int); uint32 convM2Du(uchar*, uint32, Dir*, char*, int); uint32 convD2Mu(Dir*, uchar*, uint32, int); uint32 sizeD2Mu(Dir*, int); /* int fcallfmt(Fmt*); int dirfmt(Fmt*); int dirmodefmt(Fmt*); */ int read9pmsg(int, void*, uint32); /* #pragma varargck type "F" Fcall* #pragma varargck type "M" ulong #pragma varargck type "D" Dir* */ #ifdef __cplusplus } #endif #endif