Moves the 9ns conv functions to glibc (XCC)
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 15 Jul 2014 23:34:40 +0000 (16:34 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 16 Jul 2014 00:44:11 +0000 (17:44 -0700)
Glibc will need to use these to implement functions like chmod.

Reinstall your cross compiler.  Either copy over the changed -ros files, or
just make clean the whole thing.

20 files changed:
Documentation/plan9.txt
tests/cs.c
tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/Makefile
tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/Versions
tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/convD2M.c [new file with mode: 0644]
tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/convM2D.c [new file with mode: 0644]
tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/convM2S.c [new file with mode: 0644]
tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/convS2M.c [new file with mode: 0644]
tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/fcall.h [new file with mode: 0644]
user/ndblib/convD2M.c [deleted file]
user/ndblib/convM2D.c [deleted file]
user/ndblib/convM2S.c [deleted file]
user/ndblib/convS2M.c [deleted file]
user/ndblib/fcallfmt.c
user/ndblib/include/dir.h [deleted file]
user/ndblib/include/fcall.h [deleted file]
user/ndblib/include/fcallfmt.h [new file with mode: 0755]
user/ndblib/include/ndb.h
user/ndblib/ndbopen.c
user/ndblib/read9pmsg.c

index fc957ee..acf509b 100644 (file)
@@ -141,3 +141,6 @@ If you overflow or underflow the error stack the kernel will panic.
 The implementation is in kern/src/error.c, the macros are in
 kern/include/plan9.h.
 
+
+For info on the format of Ms (which are part of the kernel interface):
+       http://9p.cat-v.org/documentation/rfc/ 
index 1641c32..5e792e9 100644 (file)
@@ -19,7 +19,6 @@
 #include <ctype.h>
 #include <error.h>
 #include <iplib.h>
-#include <dir.h>
 #include <ndb.h>
 #include <fcall.h>
 
index 41874d5..1bbf3af 100644 (file)
@@ -9,3 +9,13 @@ ifeq ($(subdir),socket)
 sysdep_routines += sa_len
 endif
 sysdep_headers += sys/syscall.h sys/vcore-tls.h
+
+# plan 9 conversion routines.  all C files need to be in exactly one directory.
+# stdlib seems like a reasonable place. */
+ifeq ($(subdir),stdlib)
+sysdep_routines += convD2M
+sysdep_routines += convM2D
+sysdep_routines += convM2S
+sysdep_routines += convS2M
+endif
+sysdep_headers += fcall.h
index d11ba82..58de426 100644 (file)
@@ -18,5 +18,14 @@ libc {
     allocate_tls;
     free_tls;
     reinit_tls;
+
+    init_empty_dir;
+    convM2S;
+    convS2M;
+    sizeS2M;
+    statcheck;
+    convM2D;
+    convD2M;
+    sizeD2M;
   }
 }
diff --git a/tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/convD2M.c b/tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/convD2M.c
new file mode 100644 (file)
index 0000000..6d336c2
--- /dev/null
@@ -0,0 +1,101 @@
+/* 
+ * This file is part of the UCB release of Plan 9. It is subject to the license
+ * terms in the LICENSE file found in the top-level directory of this
+ * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
+ * part of the UCB release of Plan 9, including this file, may be copied,
+ * modified, propagated, or distributed except according to the terms contained
+ * in the LICENSE file.
+ */
+
+#include <string.h>
+#include <fcall.h>
+
+unsigned int sizeD2M(struct dir *d)
+{
+       char *sv[4];
+       int i, ns;
+
+       sv[0] = d->name;
+       sv[1] = d->uid;
+       sv[2] = d->gid;
+       sv[3] = d->muid;
+
+       ns = 0;
+       for (i = 0; i < 4; i++)
+               if (sv[i])
+                       ns += strlen(sv[i]);
+
+       return STATFIXLEN + ns;
+}
+
+unsigned int convD2M(struct dir *d, uint8_t * buf, unsigned int nbuf)
+{
+       uint8_t *p, *ebuf;
+       char *sv[4];
+       int i, ns, nsv[4], ss;
+
+       if (nbuf < BIT16SZ)
+               return 0;
+
+       p = buf;
+       ebuf = buf + nbuf;
+
+       sv[0] = d->name;
+       sv[1] = d->uid;
+       sv[2] = d->gid;
+       sv[3] = d->muid;
+
+       ns = 0;
+       for (i = 0; i < 4; i++) {
+               if (sv[i])
+                       nsv[i] = strlen(sv[i]);
+               else
+                       nsv[i] = 0;
+               ns += nsv[i];
+       }
+
+       ss = STATFIXLEN + ns;
+
+       /* set size before erroring, so user can know how much is needed */
+       /* note that length excludes count field itself */
+       PBIT16(p, ss - BIT16SZ);
+       p += BIT16SZ;
+
+       if (ss > nbuf)
+               return BIT16SZ;
+
+       PBIT16(p, d->type);
+       p += BIT16SZ;
+       PBIT32(p, d->dev);
+       p += BIT32SZ;
+       PBIT8(p, d->qid.type);
+       p += BIT8SZ;
+       PBIT32(p, d->qid.vers);
+       p += BIT32SZ;
+       PBIT64(p, d->qid.path);
+       p += BIT64SZ;
+       PBIT32(p, d->mode);
+       p += BIT32SZ;
+       PBIT32(p, d->atime);
+       p += BIT32SZ;
+       PBIT32(p, d->mtime);
+       p += BIT32SZ;
+       PBIT64(p, d->length);
+       p += BIT64SZ;
+
+       for (i = 0; i < 4; i++) {
+               ns = nsv[i];
+               if (p + ns + BIT16SZ > ebuf)
+                       return 0;
+               PBIT16(p, ns);
+               p += BIT16SZ;
+               if (ns)
+                       memmove(p, sv[i], ns);
+               p += ns;
+       }
+
+       if (ss != p - buf)
+               return 0;
+
+       return p - buf;
+}
diff --git a/tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/convM2D.c b/tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/convM2D.c
new file mode 100644 (file)
index 0000000..657e3b6
--- /dev/null
@@ -0,0 +1,101 @@
+/* 
+ * This file is part of the UCB release of Plan 9. It is subject to the license
+ * terms in the LICENSE file found in the top-level directory of this
+ * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
+ * part of the UCB release of Plan 9, including this file, may be copied,
+ * modified, propagated, or distributed except according to the terms contained
+ * in the LICENSE file.
+ */
+
+#include <fcall.h>
+#include <string.h>
+
+int statcheck(uint8_t * buf, unsigned int nbuf)
+{
+       uint8_t *ebuf;
+       int i;
+
+       ebuf = buf + nbuf;
+
+       if (nbuf < STATFIXLEN || nbuf != BIT16SZ + GBIT16(buf))
+               return -1;
+
+       buf += STATFIXLEN - 4 * BIT16SZ;
+
+       for (i = 0; i < 4; i++) {
+               if (buf + BIT16SZ > ebuf)
+                       return -1;
+               buf += BIT16SZ + GBIT16(buf);
+       }
+
+       if (buf != ebuf)
+               return -1;
+
+       return 0;
+}
+
+static char nullstring[] = "";
+
+unsigned int
+convM2D(uint8_t * buf, unsigned int nbuf, struct dir *d, char *strs)
+{
+       uint8_t *p, *ebuf;
+       char *sv[4];
+       int i, ns;
+
+       if (nbuf < STATFIXLEN)
+               return 0;
+
+       p = buf;
+       ebuf = buf + nbuf;
+
+       p += BIT16SZ;   /* ignore size */
+       d->type = GBIT16(p);
+       p += BIT16SZ;
+       d->dev = GBIT32(p);
+       p += BIT32SZ;
+       d->qid.type = GBIT8(p);
+       p += BIT8SZ;
+       d->qid.vers = GBIT32(p);
+       p += BIT32SZ;
+       d->qid.path = GBIT64(p);
+       p += BIT64SZ;
+       d->mode = GBIT32(p);
+       p += BIT32SZ;
+       d->atime = GBIT32(p);
+       p += BIT32SZ;
+       d->mtime = GBIT32(p);
+       p += BIT32SZ;
+       d->length = GBIT64(p);
+       p += BIT64SZ;
+
+       for (i = 0; i < 4; i++) {
+               if (p + BIT16SZ > ebuf)
+                       return 0;
+               ns = GBIT16(p);
+               p += BIT16SZ;
+               if (p + ns > ebuf)
+                       return 0;
+               if (strs) {
+                       sv[i] = strs;
+                       memmove(strs, p, ns);
+                       strs += ns;
+                       *strs++ = '\0';
+               }
+               p += ns;
+       }
+
+       if (strs) {
+               d->name = sv[0];
+               d->uid = sv[1];
+               d->gid = sv[2];
+               d->muid = sv[3];
+       } else {
+               d->name = nullstring;
+               d->uid = nullstring;
+               d->gid = nullstring;
+               d->muid = nullstring;
+       }
+
+       return p - buf;
+}
diff --git a/tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/convM2S.c b/tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/convM2S.c
new file mode 100644 (file)
index 0000000..fa72621
--- /dev/null
@@ -0,0 +1,336 @@
+/* 
+ * This file is part of the UCB release of Plan 9. It is subject to the license
+ * terms in the LICENSE file found in the top-level directory of this
+ * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
+ * part of the UCB release of Plan 9, including this file, may be copied,
+ * modified, propagated, or distributed except according to the terms contained
+ * in the LICENSE file.
+ */
+
+#include <string.h>
+#include <fcall.h>
+
+static
+uint8_t *gstring(uint8_t * p, uint8_t * ep, char **s)
+{
+       unsigned int n;
+
+       if (p + BIT16SZ > ep)
+               return NULL;
+       n = GBIT16(p);
+       p += BIT16SZ - 1;
+       if (p + n + 1 > ep)
+               return NULL;
+       /* move it down, on top of count, to make room for '\0' */
+       memmove(p, p + 1, n);
+       p[n] = '\0';
+       *s = (char *)p;
+       p += n + 1;
+       return p;
+}
+
+static
+uint8_t *gqid(uint8_t * p, uint8_t * ep, struct qid *q)
+{
+       if (p + QIDSZ > ep)
+               return NULL;
+       q->type = GBIT8(p);
+       p += BIT8SZ;
+       q->vers = GBIT32(p);
+       p += BIT32SZ;
+       q->path = GBIT64(p);
+       p += BIT64SZ;
+       return p;
+}
+
+void init_empty_dir(struct dir *d)
+{
+       d->type = ~0;
+       d->dev = ~0;
+       d->qid.path = ~0;
+       d->qid.vers = ~0;
+       d->qid.type = ~0;
+       d->mode = ~0;
+       d->atime = ~0;
+       d->mtime = ~0;
+       d->length = ~0;
+       d->name = "";
+       d->uid = "";
+       d->gid = "";
+       d->muid = "";
+}
+
+/*
+ * no syntactic checks.
+ * three causes for error:
+ *  1. message size field is incorrect
+ *  2. input buffer too short for its own data (counts too long, etc.)
+ *  3. too many names or qids
+ * gqid() and gstring() return NULL if they would reach beyond buffer.
+ * main switch statement checks range and also can fall through
+ * to test at end of routine.
+ */
+unsigned int convM2S(uint8_t * ap, unsigned int nap, struct fcall *f)
+{
+       uint8_t *p, *ep;
+       unsigned int i, size;
+
+       p = ap;
+       ep = p + nap;
+
+       if (p + BIT32SZ + BIT8SZ + BIT16SZ > ep)
+               return 0;
+       size = GBIT32(p);
+       p += BIT32SZ;
+
+       if (size < BIT32SZ + BIT8SZ + BIT16SZ)
+               return 0;
+
+       f->type = GBIT8(p);
+       p += BIT8SZ;
+       f->tag = GBIT16(p);
+       p += BIT16SZ;
+
+       switch (f->type) {
+               default:
+                       return 0;
+
+               case Tversion:
+                       if (p + BIT32SZ > ep)
+                               return 0;
+                       f->msize = GBIT32(p);
+                       p += BIT32SZ;
+                       p = gstring(p, ep, &f->version);
+                       break;
+
+               case Tflush:
+                       if (p + BIT16SZ > ep)
+                               return 0;
+                       f->oldtag = GBIT16(p);
+                       p += BIT16SZ;
+                       break;
+
+               case Tauth:
+                       if (p + BIT32SZ > ep)
+                               return 0;
+                       f->afid = GBIT32(p);
+                       p += BIT32SZ;
+                       p = gstring(p, ep, &f->uname);
+                       if (p == NULL)
+                               break;
+                       p = gstring(p, ep, &f->aname);
+                       if (p == NULL)
+                               break;
+                       break;
+
+               case Tattach:
+                       if (p + BIT32SZ > ep)
+                               return 0;
+                       f->fid = GBIT32(p);
+                       p += BIT32SZ;
+                       if (p + BIT32SZ > ep)
+                               return 0;
+                       f->afid = GBIT32(p);
+                       p += BIT32SZ;
+                       p = gstring(p, ep, &f->uname);
+                       if (p == NULL)
+                               break;
+                       p = gstring(p, ep, &f->aname);
+                       if (p == NULL)
+                               break;
+                       break;
+
+               case Twalk:
+                       if (p + BIT32SZ + BIT32SZ + BIT16SZ > ep)
+                               return 0;
+                       f->fid = GBIT32(p);
+                       p += BIT32SZ;
+                       f->newfid = GBIT32(p);
+                       p += BIT32SZ;
+                       f->nwname = GBIT16(p);
+                       p += BIT16SZ;
+                       if (f->nwname > MAXWELEM)
+                               return 0;
+                       for (i = 0; i < f->nwname; i++) {
+                               p = gstring(p, ep, &f->wname[i]);
+                               if (p == NULL)
+                                       break;
+                       }
+                       break;
+
+               case Topen:
+                       if (p + BIT32SZ + BIT8SZ > ep)
+                               return 0;
+                       f->fid = GBIT32(p);
+                       p += BIT32SZ;
+                       f->mode = GBIT8(p);
+                       p += BIT8SZ;
+                       break;
+
+               case Tcreate:
+                       if (p + BIT32SZ > ep)
+                               return 0;
+                       f->fid = GBIT32(p);
+                       p += BIT32SZ;
+                       p = gstring(p, ep, &f->name);
+                       if (p == NULL)
+                               break;
+                       if (p + BIT32SZ + BIT8SZ > ep)
+                               return 0;
+                       f->perm = GBIT32(p);
+                       p += BIT32SZ;
+                       f->mode = GBIT8(p);
+                       p += BIT8SZ;
+                       break;
+
+               case Tread:
+                       if (p + BIT32SZ + BIT64SZ + BIT32SZ > ep)
+                               return 0;
+                       f->fid = GBIT32(p);
+                       p += BIT32SZ;
+                       f->offset = GBIT64(p);
+                       p += BIT64SZ;
+                       f->count = GBIT32(p);
+                       p += BIT32SZ;
+                       break;
+
+               case Twrite:
+                       if (p + BIT32SZ + BIT64SZ + BIT32SZ > ep)
+                               return 0;
+                       f->fid = GBIT32(p);
+                       p += BIT32SZ;
+                       f->offset = GBIT64(p);
+                       p += BIT64SZ;
+                       f->count = GBIT32(p);
+                       p += BIT32SZ;
+                       if (p + f->count > ep)
+                               return 0;
+                       f->data = (char *)p;
+                       p += f->count;
+                       break;
+
+               case Tclunk:
+               case Tremove:
+                       if (p + BIT32SZ > ep)
+                               return 0;
+                       f->fid = GBIT32(p);
+                       p += BIT32SZ;
+                       break;
+
+               case Tstat:
+                       if (p + BIT32SZ > ep)
+                               return 0;
+                       f->fid = GBIT32(p);
+                       p += BIT32SZ;
+                       break;
+
+               case Twstat:
+                       if (p + BIT32SZ + BIT16SZ > ep)
+                               return 0;
+                       f->fid = GBIT32(p);
+                       p += BIT32SZ;
+                       f->nstat = GBIT16(p);
+                       p += BIT16SZ;
+                       if (p + f->nstat > ep)
+                               return 0;
+                       f->stat = p;
+                       p += f->nstat;
+                       break;
+
+/*
+ */
+               case Rversion:
+                       if (p + BIT32SZ > ep)
+                               return 0;
+                       f->msize = GBIT32(p);
+                       p += BIT32SZ;
+                       p = gstring(p, ep, &f->version);
+                       break;
+
+               case Rerror:
+                       p = gstring(p, ep, &f->ename);
+                       break;
+
+               case Rflush:
+                       break;
+
+               case Rauth:
+                       p = gqid(p, ep, &f->aqid);
+                       if (p == NULL)
+                               break;
+                       break;
+
+               case Rattach:
+                       p = gqid(p, ep, &f->qid);
+                       if (p == NULL)
+                               break;
+                       break;
+
+               case Rwalk:
+                       if (p + BIT16SZ > ep)
+                               return 0;
+                       f->nwqid = GBIT16(p);
+                       p += BIT16SZ;
+                       if (f->nwqid > MAXWELEM)
+                               return 0;
+                       for (i = 0; i < f->nwqid; i++) {
+                               p = gqid(p, ep, &f->wqid[i]);
+                               if (p == NULL)
+                                       break;
+                       }
+                       break;
+
+               case Ropen:
+               case Rcreate:
+                       p = gqid(p, ep, &f->qid);
+                       if (p == NULL)
+                               break;
+                       if (p + BIT32SZ > ep)
+                               return 0;
+                       f->iounit = GBIT32(p);
+                       p += BIT32SZ;
+                       break;
+
+               case Rread:
+                       if (p + BIT32SZ > ep)
+                               return 0;
+                       f->count = GBIT32(p);
+                       p += BIT32SZ;
+                       if (p + f->count > ep)
+                               return 0;
+                       f->data = (char *)p;
+                       p += f->count;
+                       break;
+
+               case Rwrite:
+                       if (p + BIT32SZ > ep)
+                               return 0;
+                       f->count = GBIT32(p);
+                       p += BIT32SZ;
+                       break;
+
+               case Rclunk:
+               case Rremove:
+                       break;
+
+               case Rstat:
+                       if (p + BIT16SZ > ep)
+                               return 0;
+                       f->nstat = GBIT16(p);
+                       p += BIT16SZ;
+                       if (p + f->nstat > ep)
+                               return 0;
+                       f->stat = p;
+                       p += f->nstat;
+                       break;
+
+               case Rwstat:
+                       break;
+       }
+
+       if (p == NULL || p > ep)
+               return 0;
+       if (ap + size == p)
+               return size;
+       return 0;
+}
diff --git a/tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/convS2M.c b/tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/convS2M.c
new file mode 100644 (file)
index 0000000..a1a0afa
--- /dev/null
@@ -0,0 +1,390 @@
+/* 
+ * This file is part of the UCB release of Plan 9. It is subject to the license
+ * terms in the LICENSE file found in the top-level directory of this
+ * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
+ * part of the UCB release of Plan 9, including this file, may be copied,
+ * modified, propagated, or distributed except according to the terms contained
+ * in the LICENSE file.
+ */
+
+#include <string.h>
+#include <fcall.h>
+
+static
+uint8_t *pstring(uint8_t * p, char *s)
+{
+       unsigned int n;
+
+       if (s == NULL) {
+               PBIT16(p, 0);
+               p += BIT16SZ;
+               return p;
+       }
+
+       n = strlen(s);
+       /*
+        * We are moving the string before the length,
+        * so you can S2M a struct into an existing message
+        */
+       memmove(p + BIT16SZ, s, n);
+       PBIT16(p, n);
+       p += n + BIT16SZ;
+       return p;
+}
+
+static
+uint8_t *pqid(uint8_t * p, struct qid *q)
+{
+       PBIT8(p, q->type);
+       p += BIT8SZ;
+       PBIT32(p, q->vers);
+       p += BIT32SZ;
+       PBIT64(p, q->path);
+       p += BIT64SZ;
+       return p;
+}
+
+static
+unsigned int stringsz(char *s)
+{
+       if (s == NULL)
+               return BIT16SZ;
+
+       return BIT16SZ + strlen(s);
+}
+
+unsigned int sizeS2M(struct fcall *f)
+{
+       unsigned int n;
+       int i;
+
+       n = 0;
+       n += BIT32SZ;   /* size */
+       n += BIT8SZ;    /* type */
+       n += BIT16SZ;   /* tag */
+
+       switch (f->type) {
+               default:
+                       return 0;
+
+               case Tversion:
+                       n += BIT32SZ;
+                       n += stringsz(f->version);
+                       break;
+
+               case Tflush:
+                       n += BIT16SZ;
+                       break;
+
+               case Tauth:
+                       n += BIT32SZ;
+                       n += stringsz(f->uname);
+                       n += stringsz(f->aname);
+                       break;
+
+               case Tattach:
+                       n += BIT32SZ;
+                       n += BIT32SZ;
+                       n += stringsz(f->uname);
+                       n += stringsz(f->aname);
+                       break;
+
+               case Twalk:
+                       n += BIT32SZ;
+                       n += BIT32SZ;
+                       n += BIT16SZ;
+                       for (i = 0; i < f->nwname; i++)
+                               n += stringsz(f->wname[i]);
+                       break;
+
+               case Topen:
+                       n += BIT32SZ;
+                       n += BIT8SZ;
+                       break;
+
+               case Tcreate:
+                       n += BIT32SZ;
+                       n += stringsz(f->name);
+                       n += BIT32SZ;
+                       n += BIT8SZ;
+                       break;
+
+               case Tread:
+                       n += BIT32SZ;
+                       n += BIT64SZ;
+                       n += BIT32SZ;
+                       break;
+
+               case Twrite:
+                       n += BIT32SZ;
+                       n += BIT64SZ;
+                       n += BIT32SZ;
+                       n += f->count;
+                       break;
+
+               case Tclunk:
+               case Tremove:
+                       n += BIT32SZ;
+                       break;
+
+               case Tstat:
+                       n += BIT32SZ;
+                       break;
+
+               case Twstat:
+                       n += BIT32SZ;
+                       n += BIT16SZ;
+                       n += f->nstat;
+                       break;
+/*
+ */
+
+               case Rversion:
+                       n += BIT32SZ;
+                       n += stringsz(f->version);
+                       break;
+
+               case Rerror:
+                       n += stringsz(f->ename);
+                       break;
+
+               case Rflush:
+                       break;
+
+               case Rauth:
+                       n += QIDSZ;
+                       break;
+
+               case Rattach:
+                       n += QIDSZ;
+                       break;
+
+               case Rwalk:
+                       n += BIT16SZ;
+                       n += f->nwqid * QIDSZ;
+                       break;
+
+               case Ropen:
+               case Rcreate:
+                       n += QIDSZ;
+                       n += BIT32SZ;
+                       break;
+
+               case Rread:
+                       n += BIT32SZ;
+                       n += f->count;
+                       break;
+
+               case Rwrite:
+                       n += BIT32SZ;
+                       break;
+
+               case Rclunk:
+                       break;
+
+               case Rremove:
+                       break;
+
+               case Rstat:
+                       n += BIT16SZ;
+                       n += f->nstat;
+                       break;
+
+               case Rwstat:
+                       break;
+       }
+       return n;
+}
+
+unsigned int convS2M(struct fcall *f, uint8_t * ap, unsigned int nap)
+{
+       uint8_t *p;
+       unsigned int i, size;
+
+       size = sizeS2M(f);
+       if (size == 0)
+               return 0;
+       if (size > nap)
+               return 0;
+
+       p = (uint8_t *) ap;
+
+       PBIT32(p, size);
+       p += BIT32SZ;
+       PBIT8(p, f->type);
+       p += BIT8SZ;
+       PBIT16(p, f->tag);
+       p += BIT16SZ;
+
+       switch (f->type) {
+               default:
+                       return 0;
+
+               case Tversion:
+                       PBIT32(p, f->msize);
+                       p += BIT32SZ;
+                       p = pstring(p, f->version);
+                       break;
+
+               case Tflush:
+                       PBIT16(p, f->oldtag);
+                       p += BIT16SZ;
+                       break;
+
+               case Tauth:
+                       PBIT32(p, f->afid);
+                       p += BIT32SZ;
+                       p = pstring(p, f->uname);
+                       p = pstring(p, f->aname);
+                       break;
+
+               case Tattach:
+                       PBIT32(p, f->fid);
+                       p += BIT32SZ;
+                       PBIT32(p, f->afid);
+                       p += BIT32SZ;
+                       p = pstring(p, f->uname);
+                       p = pstring(p, f->aname);
+                       break;
+
+               case Twalk:
+                       PBIT32(p, f->fid);
+                       p += BIT32SZ;
+                       PBIT32(p, f->newfid);
+                       p += BIT32SZ;
+                       PBIT16(p, f->nwname);
+                       p += BIT16SZ;
+                       if (f->nwname > MAXWELEM)
+                               return 0;
+                       for (i = 0; i < f->nwname; i++)
+                               p = pstring(p, f->wname[i]);
+                       break;
+
+               case Topen:
+                       PBIT32(p, f->fid);
+                       p += BIT32SZ;
+                       PBIT8(p, f->mode);
+                       p += BIT8SZ;
+                       break;
+
+               case Tcreate:
+                       PBIT32(p, f->fid);
+                       p += BIT32SZ;
+                       p = pstring(p, f->name);
+                       PBIT32(p, f->perm);
+                       p += BIT32SZ;
+                       PBIT8(p, f->mode);
+                       p += BIT8SZ;
+                       break;
+
+               case Tread:
+                       PBIT32(p, f->fid);
+                       p += BIT32SZ;
+                       PBIT64(p, f->offset);
+                       p += BIT64SZ;
+                       PBIT32(p, f->count);
+                       p += BIT32SZ;
+                       break;
+
+               case Twrite:
+                       PBIT32(p, f->fid);
+                       p += BIT32SZ;
+                       PBIT64(p, f->offset);
+                       p += BIT64SZ;
+                       PBIT32(p, f->count);
+                       p += BIT32SZ;
+                       memmove(p, f->data, f->count);
+                       p += f->count;
+                       break;
+
+               case Tclunk:
+               case Tremove:
+                       PBIT32(p, f->fid);
+                       p += BIT32SZ;
+                       break;
+
+               case Tstat:
+                       PBIT32(p, f->fid);
+                       p += BIT32SZ;
+                       break;
+
+               case Twstat:
+                       PBIT32(p, f->fid);
+                       p += BIT32SZ;
+                       PBIT16(p, f->nstat);
+                       p += BIT16SZ;
+                       memmove(p, f->stat, f->nstat);
+                       p += f->nstat;
+                       break;
+/*
+ */
+
+               case Rversion:
+                       PBIT32(p, f->msize);
+                       p += BIT32SZ;
+                       p = pstring(p, f->version);
+                       break;
+
+               case Rerror:
+                       p = pstring(p, f->ename);
+                       break;
+
+               case Rflush:
+                       break;
+
+               case Rauth:
+                       p = pqid(p, &f->aqid);
+                       break;
+
+               case Rattach:
+                       p = pqid(p, &f->qid);
+                       break;
+
+               case Rwalk:
+                       PBIT16(p, f->nwqid);
+                       p += BIT16SZ;
+                       if (f->nwqid > MAXWELEM)
+                               return 0;
+                       for (i = 0; i < f->nwqid; i++)
+                               p = pqid(p, &f->wqid[i]);
+                       break;
+
+               case Ropen:
+               case Rcreate:
+                       p = pqid(p, &f->qid);
+                       PBIT32(p, f->iounit);
+                       p += BIT32SZ;
+                       break;
+
+               case Rread:
+                       PBIT32(p, f->count);
+                       p += BIT32SZ;
+                       memmove(p, f->data, f->count);
+                       p += f->count;
+                       break;
+
+               case Rwrite:
+                       PBIT32(p, f->count);
+                       p += BIT32SZ;
+                       break;
+
+               case Rclunk:
+                       break;
+
+               case Rremove:
+                       break;
+
+               case Rstat:
+                       PBIT16(p, f->nstat);
+                       p += BIT16SZ;
+                       memmove(p, f->stat, f->nstat);
+                       p += f->nstat;
+                       break;
+
+               case Rwstat:
+                       break;
+       }
+       if (size != p - ap)
+               return 0;
+       return size;
+}
diff --git a/tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/fcall.h b/tools/compilers/gcc-glibc/glibc-2.14.1-ros/sysdeps/ros/fcall.h
new file mode 100644 (file)
index 0000000..5069132
--- /dev/null
@@ -0,0 +1,173 @@
+/* 
+ * This file is part of the UCB release of Plan 9. It is subject to the license
+ * terms in the LICENSE file found in the top-level directory of this
+ * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
+ * part of the UCB release of Plan 9, including this file, may be copied,
+ * modified, propagated, or distributed except according to the terms contained
+ * in the LICENSE file.
+ */
+/*
+ * Copyright 2013 Google Inc.
+ * Copyright (c) 1989-2003 by Lucent Technologies, Bell Laboratories.
+ */
+
+#ifndef _GLIBC_ROS_FCALL_H
+#define _GLIBC_ROS_FCALL_H
+
+#include <ros/common.h>
+
+/* There are a bunch of structs and macros in there that the kernel also uses,
+ * though none of this is part of the actual kernel interface (I think) */
+
+/* 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 */
+
+struct qid {
+       uint64_t path;
+       uint32_t vers;
+       uint8_t type;
+};
+
+struct dir {
+       /* system-modified data */
+       uint16_t type;                          /* server type */
+       unsigned int dev;                       /* server subtype */
+       /* file data */
+       struct qid qid;                         /* unique id from server */
+       uint32_t mode;                          /* permissions */
+       uint32_t atime;                         /* last read time */
+       uint32_t mtime;                         /* last write time */
+       int64_t length;                         /* file length: see <u.h> */
+       char *name;                                     /* last element of path */
+       char *uid;                                      /* owner name */
+       char *gid;                                      /* group name */
+       char *muid;                                     /* last modifier name */
+};
+
+#define        VERSION9P       "9P2000"
+
+#define        MAXWELEM        16
+
+struct fcall {
+       uint8_t type;
+       uint32_t fid;
+       uint16_t tag;
+       union {
+               struct {
+                       uint32_t msize;         /* Tversion, Rversion */
+                       char *version;          /* Tversion, Rversion */
+               };
+               struct {
+                       uint16_t oldtag;        /* Tflush */
+               };
+               struct {
+                       char *ename;            /* Rerror */
+               };
+               struct {
+                       struct qid qid;         /* Rattach, Ropen, Rcreate */
+                       uint32_t iounit;        /* Ropen, Rcreate */
+               };
+               struct {
+                       struct qid aqid;        /* Rauth */
+               };
+               struct {
+                       uint32_t afid;          /* Tauth, Tattach */
+                       char *uname;            /* Tauth, Tattach */
+                       char *aname;            /* Tauth, Tattach */
+               };
+               struct {
+                       uint32_t perm;          /* Tcreate */
+                       char *name;                     /* Tcreate */
+                       uint8_t mode;           /* Tcreate, Topen */
+               };
+               struct {
+                       uint32_t newfid;        /* Twalk */
+                       uint16_t nwname;        /* Twalk */
+                       char *wname[MAXWELEM];  /* Twalk */
+               };
+               struct {
+                       uint16_t nwqid;         /* Rwalk */
+                       struct qid wqid[MAXWELEM];      /* Rwalk */
+               };
+               struct {
+                       int64_t offset;         /* Tread, Twrite */
+                       uint32_t count;         /* Tread, Twrite, Rread */
+                       char *data;                     /* Twrite, Rread */
+               };
+               struct {
+                       uint16_t nstat;         /* Twstat, Rstat */
+                       uint8_t *stat;          /* Twstat, Rstat */
+               };
+       };
+};
+
+#define        GBIT8(p)        ((p)[0])
+#define        GBIT16(p)       ((p)[0]|((p)[1]<<8))
+#define        GBIT32(p)       ((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
+#define        GBIT64(p)       ((uint32_t)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
+                               ((int64_t)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32))
+
+#define        PBIT8(p,v)      (p)[0]=(v)
+#define        PBIT16(p,v)     (p)[0]=(v);(p)[1]=(v)>>8
+#define        PBIT32(p,v)     (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24
+#define        PBIT64(p,v)     (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\
+                       (p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(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        NOTAG           (uint16_t)~0U   /* Dummy tag */
+#define        NOFID           (uint32_t)~0U   /* Dummy fid */
+#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,
+};
+
+void init_empty_dir(struct dir *d);
+unsigned int convM2S(uint8_t *, unsigned int, struct fcall *);
+unsigned int convS2M(struct fcall *, uint8_t *, unsigned int);
+unsigned int sizeS2M(struct fcall *);
+
+int statcheck(uint8_t * abuf, unsigned int nbuf);
+unsigned int convM2D(uint8_t *, unsigned int, struct dir *, char *);
+unsigned int convD2M(struct dir *, uint8_t *, unsigned int);
+unsigned int sizeD2M(struct dir *);
+
+#endif /* _GLIBC_ROS_FCALL_H */
diff --git a/user/ndblib/convD2M.c b/user/ndblib/convD2M.c
deleted file mode 100644 (file)
index 425294d..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/* 
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-#include <stdlib.h>
-
-#include <stdio.h>
-#include <parlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <iplib.h>
-#include <dir.h>
-#include <ndb.h>
-#include <fcall.h>
-
-unsigned int
-sizeD2M(struct dir *d)
-{
-       char *sv[4];
-       int i, ns;
-
-       sv[0] = d->name;
-       sv[1] = d->uid;
-       sv[2] = d->gid;
-       sv[3] = d->muid;
-
-       ns = 0;
-       for(i = 0; i < 4; i++)
-               if(sv[i])
-                       ns += strlen(sv[i]);
-
-       return STATFIXLEN + ns;
-}
-
-unsigned int
-convD2M(struct dir *d, uint8_t *buf, unsigned int nbuf)
-{
-       uint8_t *p, *ebuf;
-       char *sv[4];
-       int i, ns, nsv[4], ss;
-
-       if(nbuf < BIT16SZ)
-               return 0;
-
-       p = buf;
-       ebuf = buf + nbuf;
-
-       sv[0] = d->name;
-       sv[1] = d->uid;
-       sv[2] = d->gid;
-       sv[3] = d->muid;
-
-       ns = 0;
-       for(i = 0; i < 4; i++){
-               if(sv[i])
-                       nsv[i] = strlen(sv[i]);
-               else
-                       nsv[i] = 0;
-               ns += nsv[i];
-       }
-
-       ss = STATFIXLEN + ns;
-
-       /* set size before erroring, so user can know how much is needed */
-       /* note that length excludes count field itself */
-       PBIT16(p, ss-BIT16SZ);
-       p += BIT16SZ;
-
-       if(ss > nbuf)
-               return BIT16SZ;
-
-       PBIT16(p, d->type);
-       p += BIT16SZ;
-       PBIT32(p, d->dev);
-       p += BIT32SZ;
-       PBIT8(p, d->qid.type);
-       p += BIT8SZ;
-       PBIT32(p, d->qid.vers);
-       p += BIT32SZ;
-       PBIT64(p, d->qid.path);
-       p += BIT64SZ;
-       PBIT32(p, d->mode);
-       p += BIT32SZ;
-       PBIT32(p, d->atime);
-       p += BIT32SZ;
-       PBIT32(p, d->mtime);
-       p += BIT32SZ;
-       PBIT64(p, d->length);
-       p += BIT64SZ;
-
-       for(i = 0; i < 4; i++){
-               ns = nsv[i];
-               if(p + ns + BIT16SZ > ebuf)
-                       return 0;
-               PBIT16(p, ns);
-               p += BIT16SZ;
-               if(ns)
-                       memmove(p, sv[i], ns);
-               p += ns;
-       }
-
-       if(ss != p - buf)
-               return 0;
-
-       return p - buf;
-}
diff --git a/user/ndblib/convM2D.c b/user/ndblib/convM2D.c
deleted file mode 100644 (file)
index b90a9cd..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-/* 
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-#include <stdlib.h>
-
-#include <stdio.h>
-#include <parlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <iplib.h>
-#include <dir.h>
-#include <ndb.h>
-#include <fcall.h>
-
-int
-statcheck(uint8_t *buf, unsigned int nbuf)
-{
-       uint8_t *ebuf;
-       int i;
-
-       ebuf = buf + nbuf;
-
-       if(nbuf < STATFIXLEN || nbuf != BIT16SZ + GBIT16(buf))
-               return -1;
-
-       buf += STATFIXLEN - 4 * BIT16SZ;
-
-       for(i = 0; i < 4; i++){
-               if(buf + BIT16SZ > ebuf)
-                       return -1;
-               buf += BIT16SZ + GBIT16(buf);
-       }
-
-       if(buf != ebuf)
-               return -1;
-
-       return 0;
-}
-
-static char nullstring[] = "";
-
-unsigned int
-convM2D(uint8_t *buf, unsigned int nbuf, struct dir *d, char *strs)
-{
-       uint8_t *p, *ebuf;
-       char *sv[4];
-       int i, ns;
-
-       if(nbuf < STATFIXLEN)
-               return 0; 
-
-       p = buf;
-       ebuf = buf + nbuf;
-
-       p += BIT16SZ;   /* ignore size */
-       d->type = GBIT16(p);
-       p += BIT16SZ;
-       d->dev = GBIT32(p);
-       p += BIT32SZ;
-       d->qid.type = GBIT8(p);
-       p += BIT8SZ;
-       d->qid.vers = GBIT32(p);
-       p += BIT32SZ;
-       d->qid.path = GBIT64(p);
-       p += BIT64SZ;
-       d->mode = GBIT32(p);
-       p += BIT32SZ;
-       d->atime = GBIT32(p);
-       p += BIT32SZ;
-       d->mtime = GBIT32(p);
-       p += BIT32SZ;
-       d->length = GBIT64(p);
-       p += BIT64SZ;
-
-       for(i = 0; i < 4; i++){
-               if(p + BIT16SZ > ebuf)
-                       return 0;
-               ns = GBIT16(p);
-               p += BIT16SZ;
-               if(p + ns > ebuf)
-                       return 0;
-               if(strs){
-                       sv[i] = strs;
-                       memmove(strs, p, ns);
-                       strs += ns;
-                       *strs++ = '\0';
-               }
-               p += ns;
-       }
-
-       if(strs){
-               d->name = sv[0];
-               d->uid = sv[1];
-               d->gid = sv[2];
-               d->muid = sv[3];
-       }else{
-               d->name = nullstring;
-               d->uid = nullstring;
-               d->gid = nullstring;
-               d->muid = nullstring;
-       }
-       
-       return p - buf;
-}
diff --git a/user/ndblib/convM2S.c b/user/ndblib/convM2S.c
deleted file mode 100755 (executable)
index 3400fcf..0000000
+++ /dev/null
@@ -1,331 +0,0 @@
-/* 
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-#include <stdlib.h>
-
-#include <stdio.h>
-#include <parlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <iplib.h>
-#include <dir.h>
-#include <ndb.h>
-#include <fcall.h>
-
-static
-uint8_t*
-gstring(uint8_t *p, uint8_t *ep, char **s)
-{
-       unsigned int n;
-
-       if(p+BIT16SZ > ep)
-               return NULL;
-       n = GBIT16(p);
-       p += BIT16SZ - 1;
-       if(p+n+1 > ep)
-               return NULL;
-       /* move it down, on top of count, to make room for '\0' */
-       memmove(p, p + 1, n);
-       p[n] = '\0';
-       *s = (char*)p;
-       p += n+1;
-       return p;
-}
-
-static
-uint8_t*
-gqid(uint8_t *p, uint8_t *ep, struct qid *q)
-{
-       if(p+QIDSZ > ep)
-               return NULL;
-       q->type = GBIT8(p);
-       p += BIT8SZ;
-       q->vers = GBIT32(p);
-       p += BIT32SZ;
-       q->path = GBIT64(p);
-       p += BIT64SZ;
-       return p;
-}
-
-/*
- * no syntactic checks.
- * three causes for error:
- *  1. message size field is incorrect
- *  2. input buffer too short for its own data (counts too long, etc.)
- *  3. too many names or qids
- * gqid() and gstring() return NULL if they would reach beyond buffer.
- * main switch statement checks range and also can fall through
- * to test at end of routine.
- */
-unsigned int
-convM2S(uint8_t *ap, unsigned int nap, struct fcall *f)
-{
-       uint8_t *p, *ep;
-       unsigned int i, size;
-
-       p = ap;
-       ep = p + nap;
-
-       if(p+BIT32SZ+BIT8SZ+BIT16SZ > ep)
-               return 0;
-       size = GBIT32(p);
-       p += BIT32SZ;
-
-       if(size < BIT32SZ+BIT8SZ+BIT16SZ)
-               return 0;
-
-       f->type = GBIT8(p);
-       p += BIT8SZ;
-       f->tag = GBIT16(p);
-       p += BIT16SZ;
-
-       switch(f->type)
-       {
-       default:
-               return 0;
-
-       case Tversion:
-               if(p+BIT32SZ > ep)
-                       return 0;
-               f->msize = GBIT32(p);
-               p += BIT32SZ;
-               p = gstring(p, ep, &f->version);
-               break;
-
-       case Tflush:
-               if(p+BIT16SZ > ep)
-                       return 0;
-               f->oldtag = GBIT16(p);
-               p += BIT16SZ;
-               break;
-
-       case Tauth:
-               if(p+BIT32SZ > ep)
-                       return 0;
-               f->afid = GBIT32(p);
-               p += BIT32SZ;
-               p = gstring(p, ep, &f->uname);
-               if(p == NULL)
-                       break;
-               p = gstring(p, ep, &f->aname);
-               if(p == NULL)
-                       break;
-               break;
-
-       case Tattach:
-               if(p+BIT32SZ > ep)
-                       return 0;
-               f->fid = GBIT32(p);
-               p += BIT32SZ;
-               if(p+BIT32SZ > ep)
-                       return 0;
-               f->afid = GBIT32(p);
-               p += BIT32SZ;
-               p = gstring(p, ep, &f->uname);
-               if(p == NULL)
-                       break;
-               p = gstring(p, ep, &f->aname);
-               if(p == NULL)
-                       break;
-               break;
-
-       case Twalk:
-               if(p+BIT32SZ+BIT32SZ+BIT16SZ > ep)
-                       return 0;
-               f->fid = GBIT32(p);
-               p += BIT32SZ;
-               f->newfid = GBIT32(p);
-               p += BIT32SZ;
-               f->nwname = GBIT16(p);
-               p += BIT16SZ;
-               if(f->nwname > MAXWELEM)
-                       return 0;
-               for(i=0; i<f->nwname; i++){
-                       p = gstring(p, ep, &f->wname[i]);
-                       if(p == NULL)
-                               break;
-               }
-               break;
-
-       case Topen:
-               if(p+BIT32SZ+BIT8SZ > ep)
-                       return 0;
-               f->fid = GBIT32(p);
-               p += BIT32SZ;
-               f->mode = GBIT8(p);
-               p += BIT8SZ;
-               break;
-
-       case Tcreate:
-               if(p+BIT32SZ > ep)
-                       return 0;
-               f->fid = GBIT32(p);
-               p += BIT32SZ;
-               p = gstring(p, ep, &f->name);
-               if(p == NULL)
-                       break;
-               if(p+BIT32SZ+BIT8SZ > ep)
-                       return 0;
-               f->perm = GBIT32(p);
-               p += BIT32SZ;
-               f->mode = GBIT8(p);
-               p += BIT8SZ;
-               break;
-
-       case Tread:
-               if(p+BIT32SZ+BIT64SZ+BIT32SZ > ep)
-                       return 0;
-               f->fid = GBIT32(p);
-               p += BIT32SZ;
-               f->offset = GBIT64(p);
-               p += BIT64SZ;
-               f->count = GBIT32(p);
-               p += BIT32SZ;
-               break;
-
-       case Twrite:
-               if(p+BIT32SZ+BIT64SZ+BIT32SZ > ep)
-                       return 0;
-               f->fid = GBIT32(p);
-               p += BIT32SZ;
-               f->offset = GBIT64(p);
-               p += BIT64SZ;
-               f->count = GBIT32(p);
-               p += BIT32SZ;
-               if(p+f->count > ep)
-                       return 0;
-               f->data = (char*)p;
-               p += f->count;
-               break;
-
-       case Tclunk:
-       case Tremove:
-               if(p+BIT32SZ > ep)
-                       return 0;
-               f->fid = GBIT32(p);
-               p += BIT32SZ;
-               break;
-
-       case Tstat:
-               if(p+BIT32SZ > ep)
-                       return 0;
-               f->fid = GBIT32(p);
-               p += BIT32SZ;
-               break;
-
-       case Twstat:
-               if(p+BIT32SZ+BIT16SZ > ep)
-                       return 0;
-               f->fid = GBIT32(p);
-               p += BIT32SZ;
-               f->nstat = GBIT16(p);
-               p += BIT16SZ;
-               if(p+f->nstat > ep)
-                       return 0;
-               f->stat = p;
-               p += f->nstat;
-               break;
-
-/*
- */
-       case Rversion:
-               if(p+BIT32SZ > ep)
-                       return 0;
-               f->msize = GBIT32(p);
-               p += BIT32SZ;
-               p = gstring(p, ep, &f->version);
-               break;
-
-       case Rerror:
-               p = gstring(p, ep, &f->ename);
-               break;
-
-       case Rflush:
-               break;
-
-       case Rauth:
-               p = gqid(p, ep, &f->aqid);
-               if(p == NULL)
-                       break;
-               break;
-
-       case Rattach:
-               p = gqid(p, ep, &f->qid);
-               if(p == NULL)
-                       break;
-               break;
-
-       case Rwalk:
-               if(p+BIT16SZ > ep)
-                       return 0;
-               f->nwqid = GBIT16(p);
-               p += BIT16SZ;
-               if(f->nwqid > MAXWELEM)
-                       return 0;
-               for(i=0; i<f->nwqid; i++){
-                       p = gqid(p, ep, &f->wqid[i]);
-                       if(p == NULL)
-                               break;
-               }
-               break;
-
-       case Ropen:
-       case Rcreate:
-               p = gqid(p, ep, &f->qid);
-               if(p == NULL)
-                       break;
-               if(p+BIT32SZ > ep)
-                       return 0;
-               f->iounit = GBIT32(p);
-               p += BIT32SZ;
-               break;
-
-       case Rread:
-               if(p+BIT32SZ > ep)
-                       return 0;
-               f->count = GBIT32(p);
-               p += BIT32SZ;
-               if(p+f->count > ep)
-                       return 0;
-               f->data = (char*)p;
-               p += f->count;
-               break;
-
-       case Rwrite:
-               if(p+BIT32SZ > ep)
-                       return 0;
-               f->count = GBIT32(p);
-               p += BIT32SZ;
-               break;
-
-       case Rclunk:
-       case Rremove:
-               break;
-
-       case Rstat:
-               if(p+BIT16SZ > ep)
-                       return 0;
-               f->nstat = GBIT16(p);
-               p += BIT16SZ;
-               if(p+f->nstat > ep)
-                       return 0;
-               f->stat = p;
-               p += f->nstat;
-               break;
-
-       case Rwstat:
-               break;
-       }
-
-       if(p==NULL || p>ep)
-               return 0;
-       if(ap+size == p)
-               return size;
-       return 0;
-}
diff --git a/user/ndblib/convS2M.c b/user/ndblib/convS2M.c
deleted file mode 100755 (executable)
index bc6aef5..0000000
+++ /dev/null
@@ -1,405 +0,0 @@
-/* 
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-#include <stdlib.h>
-
-#include <stdio.h>
-#include <parlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <iplib.h>
-#include <dir.h>
-#include <ndb.h>
-#include <fcall.h>
-
-static
-uint8_t*
-pstring(uint8_t *p, char *s)
-{
-       unsigned int n;
-
-       if(s == NULL){
-               PBIT16(p, 0);
-               p += BIT16SZ;
-               return p;
-       }
-
-       n = strlen(s);
-       /*
-        * We are moving the string before the length,
-        * so you can S2M a struct into an existing message
-        */
-       memmove(p + BIT16SZ, s, n);
-       PBIT16(p, n);
-       p += n + BIT16SZ;
-       return p;
-}
-
-static
-uint8_t*
-pqid(uint8_t *p, struct qid *q)
-{
-       PBIT8(p, q->type);
-       p += BIT8SZ;
-       PBIT32(p, q->vers);
-       p += BIT32SZ;
-       PBIT64(p, q->path);
-       p += BIT64SZ;
-       return p;
-}
-
-static
-unsigned int
-stringsz(char *s)
-{
-       if(s == NULL)
-               return BIT16SZ;
-
-       return BIT16SZ+strlen(s);
-}
-
-unsigned int
-sizeS2M(struct fcall *f)
-{
-       unsigned int n;
-       int i;
-
-       n = 0;
-       n += BIT32SZ;   /* size */
-       n += BIT8SZ;    /* type */
-       n += BIT16SZ;   /* tag */
-
-       switch(f->type)
-       {
-       default:
-               return 0;
-
-       case Tversion:
-               n += BIT32SZ;
-               n += stringsz(f->version);
-               break;
-
-       case Tflush:
-               n += BIT16SZ;
-               break;
-
-       case Tauth:
-               n += BIT32SZ;
-               n += stringsz(f->uname);
-               n += stringsz(f->aname);
-               break;
-
-       case Tattach:
-               n += BIT32SZ;
-               n += BIT32SZ;
-               n += stringsz(f->uname);
-               n += stringsz(f->aname);
-               break;
-
-       case Twalk:
-               n += BIT32SZ;
-               n += BIT32SZ;
-               n += BIT16SZ;
-               for(i=0; i<f->nwname; i++)
-                       n += stringsz(f->wname[i]);
-               break;
-
-       case Topen:
-               n += BIT32SZ;
-               n += BIT8SZ;
-               break;
-
-       case Tcreate:
-               n += BIT32SZ;
-               n += stringsz(f->name);
-               n += BIT32SZ;
-               n += BIT8SZ;
-               break;
-
-       case Tread:
-               n += BIT32SZ;
-               n += BIT64SZ;
-               n += BIT32SZ;
-               break;
-
-       case Twrite:
-               n += BIT32SZ;
-               n += BIT64SZ;
-               n += BIT32SZ;
-               n += f->count;
-               break;
-
-       case Tclunk:
-       case Tremove:
-               n += BIT32SZ;
-               break;
-
-       case Tstat:
-               n += BIT32SZ;
-               break;
-
-       case Twstat:
-               n += BIT32SZ;
-               n += BIT16SZ;
-               n += f->nstat;
-               break;
-/*
- */
-
-       case Rversion:
-               n += BIT32SZ;
-               n += stringsz(f->version);
-               break;
-
-       case Rerror:
-               n += stringsz(f->ename);
-               break;
-
-       case Rflush:
-               break;
-
-       case Rauth:
-               n += QIDSZ;
-               break;
-
-       case Rattach:
-               n += QIDSZ;
-               break;
-
-       case Rwalk:
-               n += BIT16SZ;
-               n += f->nwqid*QIDSZ;
-               break;
-
-       case Ropen:
-       case Rcreate:
-               n += QIDSZ;
-               n += BIT32SZ;
-               break;
-
-       case Rread:
-               n += BIT32SZ;
-               n += f->count;
-               break;
-
-       case Rwrite:
-               n += BIT32SZ;
-               break;
-
-       case Rclunk:
-               break;
-
-       case Rremove:
-               break;
-
-       case Rstat:
-               n += BIT16SZ;
-               n += f->nstat;
-               break;
-
-       case Rwstat:
-               break;
-       }
-       return n;
-}
-
-unsigned int
-convS2M(struct fcall *f, uint8_t *ap, unsigned int nap)
-{
-       uint8_t *p;
-       unsigned int i, size;
-
-       size = sizeS2M(f);
-       if(size == 0)
-               return 0;
-       if(size > nap)
-               return 0;
-
-       p = (uint8_t*)ap;
-
-       PBIT32(p, size);
-       p += BIT32SZ;
-       PBIT8(p, f->type);
-       p += BIT8SZ;
-       PBIT16(p, f->tag);
-       p += BIT16SZ;
-
-       switch(f->type)
-       {
-       default:
-               return 0;
-
-       case Tversion:
-               PBIT32(p, f->msize);
-               p += BIT32SZ;
-               p = pstring(p, f->version);
-               break;
-
-       case Tflush:
-               PBIT16(p, f->oldtag);
-               p += BIT16SZ;
-               break;
-
-       case Tauth:
-               PBIT32(p, f->afid);
-               p += BIT32SZ;
-               p  = pstring(p, f->uname);
-               p  = pstring(p, f->aname);
-               break;
-
-       case Tattach:
-               PBIT32(p, f->fid);
-               p += BIT32SZ;
-               PBIT32(p, f->afid);
-               p += BIT32SZ;
-               p  = pstring(p, f->uname);
-               p  = pstring(p, f->aname);
-               break;
-
-       case Twalk:
-               PBIT32(p, f->fid);
-               p += BIT32SZ;
-               PBIT32(p, f->newfid);
-               p += BIT32SZ;
-               PBIT16(p, f->nwname);
-               p += BIT16SZ;
-               if(f->nwname > MAXWELEM)
-                       return 0;
-               for(i=0; i<f->nwname; i++)
-                       p = pstring(p, f->wname[i]);
-               break;
-
-       case Topen:
-               PBIT32(p, f->fid);
-               p += BIT32SZ;
-               PBIT8(p, f->mode);
-               p += BIT8SZ;
-               break;
-
-       case Tcreate:
-               PBIT32(p, f->fid);
-               p += BIT32SZ;
-               p = pstring(p, f->name);
-               PBIT32(p, f->perm);
-               p += BIT32SZ;
-               PBIT8(p, f->mode);
-               p += BIT8SZ;
-               break;
-
-       case Tread:
-               PBIT32(p, f->fid);
-               p += BIT32SZ;
-               PBIT64(p, f->offset);
-               p += BIT64SZ;
-               PBIT32(p, f->count);
-               p += BIT32SZ;
-               break;
-
-       case Twrite:
-               PBIT32(p, f->fid);
-               p += BIT32SZ;
-               PBIT64(p, f->offset);
-               p += BIT64SZ;
-               PBIT32(p, f->count);
-               p += BIT32SZ;
-               memmove(p, f->data, f->count);
-               p += f->count;
-               break;
-
-       case Tclunk:
-       case Tremove:
-               PBIT32(p, f->fid);
-               p += BIT32SZ;
-               break;
-
-       case Tstat:
-               PBIT32(p, f->fid);
-               p += BIT32SZ;
-               break;
-
-       case Twstat:
-               PBIT32(p, f->fid);
-               p += BIT32SZ;
-               PBIT16(p, f->nstat);
-               p += BIT16SZ;
-               memmove(p, f->stat, f->nstat);
-               p += f->nstat;
-               break;
-/*
- */
-
-       case Rversion:
-               PBIT32(p, f->msize);
-               p += BIT32SZ;
-               p = pstring(p, f->version);
-               break;
-
-       case Rerror:
-               p = pstring(p, f->ename);
-               break;
-
-       case Rflush:
-               break;
-
-       case Rauth:
-               p = pqid(p, &f->aqid);
-               break;
-
-       case Rattach:
-               p = pqid(p, &f->qid);
-               break;
-
-       case Rwalk:
-               PBIT16(p, f->nwqid);
-               p += BIT16SZ;
-               if(f->nwqid > MAXWELEM)
-                       return 0;
-               for(i=0; i<f->nwqid; i++)
-                       p = pqid(p, &f->wqid[i]);
-               break;
-
-       case Ropen:
-       case Rcreate:
-               p = pqid(p, &f->qid);
-               PBIT32(p, f->iounit);
-               p += BIT32SZ;
-               break;
-
-       case Rread:
-               PBIT32(p, f->count);
-               p += BIT32SZ;
-               memmove(p, f->data, f->count);
-               p += f->count;
-               break;
-
-       case Rwrite:
-               PBIT32(p, f->count);
-               p += BIT32SZ;
-               break;
-
-       case Rclunk:
-               break;
-
-       case Rremove:
-               break;
-
-       case Rstat:
-               PBIT16(p, f->nstat);
-               p += BIT16SZ;
-               memmove(p, f->stat, f->nstat);
-               p += f->nstat;
-               break;
-
-       case Rwstat:
-               break;
-       }
-       if(size != p-ap)
-               return 0;
-       return size;
-}
index 83da189..3744bae 100755 (executable)
@@ -20,9 +20,9 @@
 #include <ctype.h>
 #include <error.h>
 #include <iplib.h>
-#include <dir.h>
-#include <ndb.h>
 #include <fcall.h>
+#include <ndb.h>
+#include <fcallfmt.h>
 
 static int dumpsome(FILE *, char *, long);
 static int fdirconv(FILE *, struct dir *);
diff --git a/user/ndblib/include/dir.h b/user/ndblib/include/dir.h
deleted file mode 100755 (executable)
index 7d8b37e..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/* 
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-#ifndef ROS_INC_DIR_H
-
-#define ROS_INC_DIR_H
-
-/* 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 */
-
-struct qid
-{
-       uint64_t        path;
-       uint32_t        vers;
-       uint8_t type;
-};
-
-struct dir {
-       /* system-modified data */
-       uint16_t        type;   /* server type */
-       unsigned int    dev;    /* server subtype */
-       /* file data */
-       struct qid      qid;    /* unique id from server */
-       uint32_t        mode;   /* permissions */
-       uint32_t        atime;  /* last read time */
-       uint32_t        mtime;  /* last write time */
-       int64_t length; /* file length: see <u.h> */
-       char    *name;  /* last element of path */
-       char    *uid;   /* owner name */
-       char    *gid;   /* group name */
-       char    *muid;  /* last modifier name */
-};
-
-#endif /* ROS_INC_DIR_H */
diff --git a/user/ndblib/include/fcall.h b/user/ndblib/include/fcall.h
deleted file mode 100755 (executable)
index 2cf49a4..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-/* 
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-/*
-
- * Copyright 2013 Google Inc.
- * Copyright (c) 1989-2003 by Lucent Technologies, Bell Laboratories.
- */
-
-#ifndef ROS_INC_FCALL_H
-#define ROS_INC_FCALL_H
-
-#include <printf-ext.h>
-
-#define        VERSION9P       "9P2000"
-
-#define        MAXWELEM        16
-
-       struct fcall {
-       uint8_t type;
-       uint32_t fid;
-       uint16_t tag;
-       union {
-               struct {
-                       uint32_t msize;         /* Tversion, Rversion */
-                       char *version;          /* Tversion, Rversion */
-               };
-               struct {
-                       uint16_t oldtag;        /* Tflush */
-               };
-               struct {
-                       char *ename;            /* Rerror */
-               };
-               struct {
-                       struct qid qid;         /* Rattach, Ropen, Rcreate */
-                       uint32_t iounit;        /* Ropen, Rcreate */
-               };
-               struct {
-                       struct qid aqid;        /* Rauth */
-               };
-               struct {
-                       uint32_t afid;          /* Tauth, Tattach */
-                       char *uname;            /* Tauth, Tattach */
-                       char *aname;            /* Tauth, Tattach */
-               };
-               struct {
-                       uint32_t perm;          /* Tcreate */
-                       char *name;                     /* Tcreate */
-                       uint8_t mode;           /* Tcreate, Topen */
-               };
-               struct {
-                       uint32_t newfid;        /* Twalk */
-                       uint16_t nwname;        /* Twalk */
-                       char *wname[MAXWELEM];  /* Twalk */
-               };
-               struct {
-                       uint16_t nwqid;         /* Rwalk */
-                       struct qid wqid[MAXWELEM];      /* Rwalk */
-               };
-               struct {
-                       int64_t offset;         /* Tread, Twrite */
-                       uint32_t count;         /* Tread, Twrite, Rread */
-                       char *data;                     /* Twrite, Rread */
-               };
-               struct {
-                       uint16_t nstat;         /* Twstat, Rstat */
-                       uint8_t *stat;          /* Twstat, Rstat */
-               };
-       };
-} fcall;
-
-#define        GBIT8(p)        ((p)[0])
-#define        GBIT16(p)       ((p)[0]|((p)[1]<<8))
-#define        GBIT32(p)       ((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
-#define        GBIT64(p)       ((uint32_t)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
-                               ((int64_t)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32))
-
-#define        PBIT8(p,v)      (p)[0]=(v)
-#define        PBIT16(p,v)     (p)[0]=(v);(p)[1]=(v)>>8
-#define        PBIT32(p,v)     (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24
-#define        PBIT64(p,v)     (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\
-                       (p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(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        NOTAG           (uint16_t)~0U   /* Dummy tag */
-#define        NOFID           (uint32_t)~0U   /* Dummy fid */
-#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,
-};
-
-unsigned int convM2S(uint8_t *, unsigned int, struct fcall *);
-unsigned int convS2M(struct fcall *, uint8_t *, unsigned int);
-unsigned int sizeS2M(struct fcall *);
-
-int statcheck(uint8_t * abuf, unsigned int nbuf);
-unsigned int convM2D(uint8_t *, unsigned int, struct dir *, char *);
-unsigned int convD2M(struct dir *, uint8_t *, unsigned int);
-unsigned int sizeD2M(struct dir *);
-
-int printf_fcall(FILE *stream, const struct printf_info *info,
-                 const void *const *args);
-int printf_fcall_info(const struct printf_info* info, size_t n, int *argtypes,
-                      int *size);
-int printf_dir(FILE *stream, const struct printf_info *info,
-               const void *const *args);
-int printf_dir_info(const struct printf_info* info, size_t n, int *argtypes,
-                    int *size);
-
-int read9pmsg(int, void *, unsigned int);
-
-#endif /* ROS_INC_FCALL_H */
diff --git a/user/ndblib/include/fcallfmt.h b/user/ndblib/include/fcallfmt.h
new file mode 100755 (executable)
index 0000000..7a7e59a
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef _NDB_FCALLFMT_H
+#define _NDB_FCALLFMT_H
+
+#include <printf-ext.h>
+#include <fcall.h>
+
+int printf_fcall(FILE *stream, const struct printf_info *info,
+                 const void *const *args);
+int printf_fcall_info(const struct printf_info* info, size_t n, int *argtypes,
+                      int *size);
+int printf_dir(FILE *stream, const struct printf_info *info,
+               const void *const *args);
+int printf_dir_info(const struct printf_info* info, size_t n, int *argtypes,
+                    int *size);
+
+int read9pmsg(int, void *, unsigned int);
+
+#endif /* _NDB_FCALLFMT_H */
index 65d5ab8..636d3c8 100755 (executable)
@@ -10,7 +10,7 @@
 
 #define ROS_INC_NDB_H
 
-#include <dir.h>
+#include <fcall.h>
 
 enum
 {
index ee2dbd3..a006012 100755 (executable)
@@ -16,7 +16,6 @@
 #include <signal.h>
 #include <fcntl.h>
 #include <iplib.h>
-#include <dir.h>
 #include <ndb.h>
 #include "ndbhf.h"
 
index 24f290e..a9b1052 100644 (file)
@@ -14,8 +14,8 @@
 #include <signal.h>
 #include <fcntl.h>
 #include <iplib.h>
-#include <dir.h>
 #include <fcall.h>
+#include <fcallfmt.h>
 #include <ndb.h>
 
 long