changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > plan9front / sys/include/fcall.h

changeset 7213: c250493e2340
parent: b8ce396c0eaf
author: Ori Bernstein <ori@eigenstate.org>
date: Mon, 06 May 2019 17:26:38 -0700
permissions: -rw-r--r--
description: Sand edges down on GBIT64()/PBIT64() macros.

Now, you can safely use them in unbraced if statements, and
with char*s.
1 #pragma src "/sys/src/libc/9sys"
2 #pragma lib "libc.a"
3 
4 #define VERSION9P "9P2000"
5 
6 #define MAXWELEM 16
7 
8 typedef
9 struct Fcall
10 {
11  uchar type;
12  u32int fid;
13  ushort tag;
14  union {
15  struct {
16  u32int msize; /* Tversion, Rversion */
17  char *version; /* Tversion, Rversion */
18  };
19  struct {
20  ushort oldtag; /* Tflush */
21  };
22  struct {
23  char *ename; /* Rerror */
24  };
25  struct {
26  Qid qid; /* Rattach, Ropen, Rcreate */
27  u32int iounit; /* Ropen, Rcreate */
28  };
29  struct {
30  Qid aqid; /* Rauth */
31  };
32  struct {
33  u32int afid; /* Tauth, Tattach */
34  char *uname; /* Tauth, Tattach */
35  char *aname; /* Tauth, Tattach */
36  };
37  struct {
38  u32int perm; /* Tcreate */
39  char *name; /* Tcreate */
40  uchar mode; /* Tcreate, Topen */
41  };
42  struct {
43  u32int newfid; /* Twalk */
44  ushort nwname; /* Twalk */
45  char *wname[MAXWELEM]; /* Twalk */
46  };
47  struct {
48  ushort nwqid; /* Rwalk */
49  Qid wqid[MAXWELEM]; /* Rwalk */
50  };
51  struct {
52  vlong offset; /* Tread, Twrite */
53  u32int count; /* Tread, Twrite, Rread */
54  char *data; /* Twrite, Rread */
55  };
56  struct {
57  ushort nstat; /* Twstat, Rstat */
58  uchar *stat; /* Twstat, Rstat */
59  };
60  };
61 } Fcall;
62 
63 
64 #define GBIT8(p) (((uchar*)(p))[0])
65 #define GBIT16(p) (((uchar*)(p))[0]|(((uchar*)(p))[1]<<8))
66 #define GBIT32(p) (((uchar*)(p))[0]|(((uchar*)(p))[1]<<8)|\
67  (((uchar*)(p))[2]<<16)|(((uchar*)(p))[3]<<24))
68 #define GBIT64(p) ((u32int)(((uchar*)(p))[0]|(((uchar*)(p))[1]<<8)|\
69  (((uchar*)(p))[2]<<16)|(((uchar*)(p))[3]<<24)) |\
70  ((uvlong)(((uchar*)(p))[4]|(((uchar*)(p))[5]<<8)|\
71  (((uchar*)(p))[6]<<16)|(((uchar*)(p))[7]<<24)) << 32))
72 
73 #define PBIT8(p,v) do{(p)[0]=(v);}while(0)
74 #define PBIT16(p,v) do{(p)[0]=(v);(p)[1]=(v)>>8;}while(0)
75 #define PBIT32(p,v) do{(p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;}while(0)
76 #define PBIT64(p,v) do{(p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\
77  (p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(v)>>56;}while(0)
78 
79 #define BIT8SZ 1
80 #define BIT16SZ 2
81 #define BIT32SZ 4
82 #define BIT64SZ 8
83 #define QIDSZ (BIT8SZ+BIT32SZ+BIT64SZ)
84 
85 /* STATFIXLEN includes leading 16-bit count */
86 /* The count, however, excludes itself; total size is BIT16SZ+count */
87 #define STATFIXLEN (BIT16SZ+QIDSZ+5*BIT16SZ+4*BIT32SZ+1*BIT64SZ) /* amount of fixed length data in a stat buffer */
88 
89 #define NOTAG (ushort)~0U /* Dummy tag */
90 #define NOFID (u32int)~0U /* Dummy fid */
91 #define IOHDRSZ 24 /* ample room for Twrite/Rread header (iounit) */
92 
93 enum
94 {
95  Tversion = 100,
96  Rversion,
97  Tauth = 102,
98  Rauth,
99  Tattach = 104,
100  Rattach,
101  Terror = 106, /* illegal */
102  Rerror,
103  Tflush = 108,
104  Rflush,
105  Twalk = 110,
106  Rwalk,
107  Topen = 112,
108  Ropen,
109  Tcreate = 114,
110  Rcreate,
111  Tread = 116,
112  Rread,
113  Twrite = 118,
114  Rwrite,
115  Tclunk = 120,
116  Rclunk,
117  Tremove = 122,
118  Rremove,
119  Tstat = 124,
120  Rstat,
121  Twstat = 126,
122  Rwstat,
123  Tmax,
124 };
125 
126 uint convM2S(uchar*, uint, Fcall*);
127 uint convS2M(Fcall*, uchar*, uint);
128 uint sizeS2M(Fcall*);
129 
130 int statcheck(uchar *abuf, uint nbuf);
131 uint convM2D(uchar*, uint, Dir*, char*);
132 uint convD2M(Dir*, uchar*, uint);
133 uint sizeD2M(Dir*);
134 
135 int fcallfmt(Fmt*);
136 int dirfmt(Fmt*);
137 int dirmodefmt(Fmt*);
138 
139 int read9pmsg(int, void*, uint);
140 
141 #pragma varargck type "F" Fcall*
142 #pragma varargck type "M" ulong
143 #pragma varargck type "D" Dir*