Add back functions for converting M to kdirents.
authorRonald G. Minnich <rminnich@google.com>
Sun, 19 Jan 2014 04:11:21 +0000 (20:11 -0800)
committerRonald G. Minnich <rminnich@google.com>
Sun, 19 Jan 2014 04:11:21 +0000 (20:11 -0800)
This is probably wrong. Probably should convert D to kdirents.
But at least we have them.

Signed-off-by: Ronald G. Minnich <rminnich@google.com>
kern/include/ns.h
kern/src/ns/Kbuild
kern/src/ns/convM2kdirent.c [new file with mode: 0644]

index f24ee1c..69b534c 100644 (file)
@@ -248,6 +248,10 @@ unsigned int       convM2S( uint8_t *unused_uint8_p_t, unsigned int unused_int, struct
 unsigned int   convS2M(struct fcall*, uint8_t *unused_uint8_p_t, unsigned int);
 unsigned int   sizeS2M(struct fcall*);
 
+unsigned int convM2kdirent(uint8_t * buf, unsigned int nbuf, struct kdirent *kd);
+unsigned int convM2kstat(uint8_t * buf, unsigned int nbuf, struct kstat *ks);
+
+
 int    statcheck(uint8_t *abuf, unsigned int nbuf);
 unsigned int   convM2D( uint8_t *unused_uint8_p_t, unsigned int unused_int, struct dir*, char *unused_char_p_t);
 unsigned int   convD2M(struct dir*, uint8_t *unused_uint8_p_t, unsigned int);
index d2de60e..06a7b85 100644 (file)
@@ -4,6 +4,7 @@ obj-y                                           += chan.o
 obj-y                                          += cleanname.o
 obj-y                                          += convD2M.o
 obj-y                                          += convM2D.o
+obj-y                                          += convM2kdirent.o
 obj-y                                          += convM2S.o
 obj-y                                          += convS2M.o
 obj-y                                          += error.o
diff --git a/kern/src/ns/convM2kdirent.c b/kern/src/ns/convM2kdirent.c
new file mode 100644 (file)
index 0000000..249095a
--- /dev/null
@@ -0,0 +1,137 @@
+
+#include <vfs.h>
+#include <kfs.h>
+#include <slab.h>
+#include <kmalloc.h>
+#include <kref.h>
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <cpio.h>
+#include <pmap.h>
+#include <smp.h>
+#include <ip.h>
+
+/* Special akaros edition. */
+/* akaros does not (yet) pass as much info as plan 9 does,
+ * and it still has stuff I'm not happy about like an inode number.
+ */
+#if 0
+struct kdirent {
+       __ino64_t d_ino;                        /* inod
+                                                                  e number */
+       __off64_t d_off;                        /* offs
+                                                                  et to the next dirent */
+       unsigned short d_reclen;        /* length of th
+                                                                  is record */
+       unsigned char d_type;
+       char d_name[MAX_FILENAME_SZ + 1];       /* filename */
+} __attribute__ ((aligned(8)));
+
+#endif
+
+unsigned int convM2kdirent(uint8_t * buf, unsigned int nbuf, struct kdirent *kd)
+{
+       uint8_t *p, *ebuf;
+       char *sv[4];
+       int i, ns;
+       uint32_t junk;
+       printd("%s >>>>>>>>>nbuf %d STATFIXLEN %d\n", __func__, nbuf, STATFIXLEN);
+       if (nbuf < STATFIXLEN)
+               return 0;
+
+       p = buf;
+       ebuf = buf + nbuf;
+
+       p += BIT16SZ;   /* ignore size */
+       kd->d_type = GBIT16(p);
+       p += BIT16SZ;
+       junk = GBIT32(p);
+       p += BIT32SZ;
+       junk = GBIT8(p);
+       p += BIT8SZ;
+       junk = GBIT32(p);
+       p += BIT32SZ;
+       kd->d_ino = GBIT64(p);
+       p += BIT64SZ;
+       junk /* mode */  = GBIT32(p);
+       p += BIT32SZ;
+       junk /*d->atime */  = GBIT32(p);
+       p += BIT32SZ;
+       junk /*d->mtime */  = GBIT32(p);
+       p += BIT32SZ;
+       junk /*d->length */  = GBIT64(p);
+       p += BIT64SZ;
+
+       /* for now, uids in akaros are ints. Does not
+        * matter; kdirents are limited in what they tell you.
+        * get the name, ignore the rest. Maybe we can
+        * fix this later. 
+        */
+       for (i = 0; i < 4; i++) {
+               if (p + BIT16SZ > ebuf)
+                       return 0;
+               ns = GBIT16(p);
+               p += BIT16SZ;
+               if (p + ns > ebuf)
+                       return 0;
+               if (i == 0) {
+                       kd->d_reclen = ns;
+                       printd("memmove %p %p %d\n", kd->d_name, p, ns);
+                       memmove(kd->d_name, p, ns);
+                       kd->d_name[ns] = 0;
+               }
+               p += ns;
+       }
+
+       printd("%s returns %d %s\n", __func__, p - buf, kd->d_name);
+       return p - buf;
+}
+
+unsigned int convM2kstat(uint8_t * buf, unsigned int nbuf, struct kstat *ks)
+{
+       uint8_t *p, *ebuf;
+       char *sv[4];
+       int i, ns;
+       uint32_t junk;
+
+       if (nbuf < STATFIXLEN)
+               return 0;
+
+       p = buf;
+       ebuf = buf + nbuf;
+
+       p += BIT16SZ;   /* ignore size */
+       junk /*kd->d_type */  = GBIT16(p);
+       p += BIT16SZ;
+       ks->st_rdev = ks->st_dev = GBIT32(p);
+       p += BIT32SZ;
+       junk /*qid.type */  = GBIT8(p);
+       p += BIT8SZ;
+       junk /*qid.vers */  = GBIT32(p);
+       p += BIT32SZ;
+       ks->st_ino = GBIT64(p);
+       p += BIT64SZ;
+       ks->st_mode = GBIT32(p);
+       if (ks->st_mode & DMDIR) {
+               ks->st_mode &= ~DMDIR;
+               ks->st_mode |= __S_IFDIR;
+       } else {
+               ks->st_mode |= __S_IFREG;
+       }
+       p += BIT32SZ;
+       ks->st_atime.tv_sec = GBIT32(p);
+       p += BIT32SZ;
+       ks->st_mtime.tv_sec = GBIT32(p);
+       p += BIT32SZ;
+       ks->st_size = GBIT64(p);
+       p += BIT64SZ;
+       ks->st_blksize = 512;
+       ks->st_blocks = ROUNDUP(ks->st_size, ks->st_blksize) / ks->st_blksize;
+
+       ks->st_nlink = 2;       // links make no sense any more. 
+       ks->st_uid = ks->st_gid = 0;
+
+       return p - buf;
+ }