Upgrade to gcc-4.9.2
[akaros.git] / tools / compilers / gcc-glibc / glibc-2.14.1-ros / sysdeps / akaros / fcall.h
1 /* 
2  * This file is part of the UCB release of Plan 9. It is subject to the license
3  * terms in the LICENSE file found in the top-level directory of this
4  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
5  * part of the UCB release of Plan 9, including this file, may be copied,
6  * modified, propagated, or distributed except according to the terms contained
7  * in the LICENSE file.
8  */
9 /*
10  * Copyright 2013 Google Inc.
11  * Copyright (c) 1989-2003 by Lucent Technologies, Bell Laboratories.
12  */
13
14 #ifndef _GLIBC_AKAROS_FCALL_H
15 #define _GLIBC_AKAROS_FCALL_H
16
17 #include <ros/common.h>
18
19 /* There are a bunch of structs and macros in there that the kernel also uses,
20  * though none of this is part of the actual kernel interface (I think) */
21
22 /* STATFIXLEN includes leading 16-bit count */
23 /* The count, however, excludes itself; total size is BIT16SZ+count */
24 #define STATFIXLEN      (BIT16SZ+QIDSZ+5*BIT16SZ+4*BIT32SZ+1*BIT64SZ)   /* amount of fixed length data in a stat buffer */
25
26 struct qid {
27         uint64_t path;
28         uint32_t vers;
29         uint8_t type;
30 };
31
32 struct dir {
33         /* system-modified data */
34         uint16_t type;                          /* server type */
35         unsigned int dev;                       /* server subtype */
36         /* file data */
37         struct qid qid;                         /* unique id from server */
38         uint32_t mode;                          /* permissions */
39         uint32_t atime;                         /* last read time */
40         uint32_t mtime;                         /* last write time */
41         int64_t length;                         /* file length: see <u.h> */
42         char *name;                                     /* last element of path */
43         char *uid;                                      /* owner name */
44         char *gid;                                      /* group name */
45         char *muid;                                     /* last modifier name */
46 };
47
48 #define VERSION9P       "9P2000"
49
50 #define MAXWELEM        16
51
52 struct fcall {
53         uint8_t type;
54         uint32_t fid;
55         uint16_t tag;
56         union {
57                 struct {
58                         uint32_t msize;         /* Tversion, Rversion */
59                         char *version;          /* Tversion, Rversion */
60                 };
61                 struct {
62                         uint16_t oldtag;        /* Tflush */
63                 };
64                 struct {
65                         char *ename;            /* Rerror */
66                 };
67                 struct {
68                         struct qid qid;         /* Rattach, Ropen, Rcreate */
69                         uint32_t iounit;        /* Ropen, Rcreate */
70                 };
71                 struct {
72                         struct qid aqid;        /* Rauth */
73                 };
74                 struct {
75                         uint32_t afid;          /* Tauth, Tattach */
76                         char *uname;            /* Tauth, Tattach */
77                         char *aname;            /* Tauth, Tattach */
78                 };
79                 struct {
80                         uint32_t perm;          /* Tcreate */
81                         char *name;                     /* Tcreate */
82                         uint8_t mode;           /* Tcreate, Topen */
83                 };
84                 struct {
85                         uint32_t newfid;        /* Twalk */
86                         uint16_t nwname;        /* Twalk */
87                         char *wname[MAXWELEM];  /* Twalk */
88                 };
89                 struct {
90                         uint16_t nwqid;         /* Rwalk */
91                         struct qid wqid[MAXWELEM];      /* Rwalk */
92                 };
93                 struct {
94                         int64_t offset;         /* Tread, Twrite */
95                         uint32_t count;         /* Tread, Twrite, Rread */
96                         char *data;                     /* Twrite, Rread */
97                 };
98                 struct {
99                         uint16_t nstat;         /* Twstat, Rstat */
100                         uint8_t *stat;          /* Twstat, Rstat */
101                 };
102         };
103 };
104
105 #define GBIT8(p)        ((p)[0])
106 #define GBIT16(p)       ((p)[0]|((p)[1]<<8))
107 #define GBIT32(p)       ((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
108 #define GBIT64(p)       ((uint32_t)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
109                                 ((int64_t)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32))
110
111 #define PBIT8(p,v)      (p)[0]=(v)
112 #define PBIT16(p,v)     (p)[0]=(v);(p)[1]=(v)>>8
113 #define PBIT32(p,v)     (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24
114 #define PBIT64(p,v)     (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\
115                         (p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(v)>>56
116
117 #define BIT8SZ          1
118 #define BIT16SZ         2
119 #define BIT32SZ         4
120 #define BIT64SZ         8
121 #define QIDSZ   (BIT8SZ+BIT32SZ+BIT64SZ)
122
123 /* STATFIXLEN includes leading 16-bit count */
124 /* The count, however, excludes itself; total size is BIT16SZ+count */
125 #define STATFIXLEN      (BIT16SZ+QIDSZ+5*BIT16SZ+4*BIT32SZ+1*BIT64SZ)   /* amount of fixed length data in a stat buffer */
126
127 #define NOTAG           (uint16_t)~0U   /* Dummy tag */
128 #define NOFID           (uint32_t)~0U   /* Dummy fid */
129 #define IOHDRSZ         24      /* ample room for Twrite/Rread header (iounit) */
130
131 enum {
132         Tversion = 100,
133         Rversion,
134         Tauth = 102,
135         Rauth,
136         Tattach = 104,
137         Rattach,
138         Terror = 106,   /* illegal */
139         Rerror,
140         Tflush = 108,
141         Rflush,
142         Twalk = 110,
143         Rwalk,
144         Topen = 112,
145         Ropen,
146         Tcreate = 114,
147         Rcreate,
148         Tread = 116,
149         Rread,
150         Twrite = 118,
151         Rwrite,
152         Tclunk = 120,
153         Rclunk,
154         Tremove = 122,
155         Rremove,
156         Tstat = 124,
157         Rstat,
158         Twstat = 126,
159         Rwstat,
160         Tmax,
161 };
162
163 void init_empty_dir(struct dir *d);
164 unsigned int convM2S(uint8_t *, unsigned int, struct fcall *);
165 unsigned int convS2M(struct fcall *, uint8_t *, unsigned int);
166 unsigned int sizeS2M(struct fcall *);
167
168 int statcheck(uint8_t * abuf, unsigned int nbuf);
169 unsigned int convM2D(uint8_t *, unsigned int, struct dir *, char *);
170 unsigned int convD2M(struct dir *, uint8_t *, unsigned int);
171 unsigned int sizeD2M(struct dir *);
172
173 #endif /* _GLIBC_AKAROS_FCALL_H */