[akaros] [PATCH 3/4] capability: run scripts/PLAN9 on capability device

2016-10-14 Thread Ronald G. Minnich
Change-Id: I55dbed3e636730c4768c61168f22c61c9e2c82fb
Signed-off-by: Ronald G. Minnich 
---
 kern/drivers/dev/capability.c | 108 +-
 1 file changed, 64 insertions(+), 44 deletions(-)

diff --git a/kern/drivers/dev/capability.c b/kern/drivers/dev/capability.c
index a3bafd7..9bd487c 100644
--- a/kern/drivers/dev/capability.c
+++ b/kern/drivers/dev/capability.c
@@ -7,14 +7,33 @@
  * in the LICENSE file.
  */
 
-#include "../port/error.h"
-#include "../port/lib.h"
-#include "dat.h"
-#include "fns.h"
-#include "mem.h"
-#include "u.h"
-
-#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 enum {
Hashlen = SHA1dlen,
@@ -32,7 +51,7 @@ struct Caphash {
 };
 
 struct {
-   QLock QLock;
+   qlock_t qlock_t qlock;
Caphash *first;
int nhash;
 } capalloc;
@@ -44,31 +63,32 @@ enum {
 };
 
 /* caphash must be last */
-Dirtab capdir[] = {
+struct dirtab capdir[] = {
 ".",   {Qdir, 0, QTDIR}, 0, DMDIR | 0500, "capuse", {Quse}, 0, 0222,
 "caphash", {Qhash},  0, 0200,
 };
-int ncapdir = nelem(capdir);
+int ncapdir = ARRAY_SIZE(capdir);
 
-static Chan *capattach(char *spec)
+static struct chan *capattach(char *spec)
 {
return devattach(L'¤', spec);
 }
 
-static Walkqid *capwalk(Chan *c, Chan *nc, char **name, int nname)
+static struct walkqid *capwalk(struct chan *c, struct chan *nc, char **name,
+   int nname)
 {
return devwalk(c, nc, name, nname, capdir, ncapdir, devgen);
 }
 
-static void capremove(Chan *c)
+static void capremove(struct chan *c)
 {
if (iseve() && c->qid.path == Qhash)
-   ncapdir = nelem(capdir) - 1;
+   ncapdir = ARRAY_SIZE(capdir) - 1;
else
error(Eperm);
 }
 
-static int32_t capstat(Chan *c, uint8_t *db, int32_t n)
+static int32_t capstat(struct chan *c, uint8_t *db, int32_t n)
 {
return devstat(c, db, n, capdir, ncapdir, devgen);
 }
@@ -76,7 +96,7 @@ static int32_t capstat(Chan *c, uint8_t *db, int32_t n)
 /*
  *  if the stream doesn't exist, create it
  */
-static Chan *capopen(Chan *c, int omode)
+static struct chan *capopen(struct chan *c, int omode)
 {
if (c->qid.type & QTDIR) {
if (omode != OREAD)
@@ -102,7 +122,7 @@ static Chan *capopen(Chan *c, int omode)
 
 /*
 static char*
-hashstr(uchar *hash)
+hashstr(uint8_t *hash)
 {
 static char buf[2*Hashlen+1];
 int i;
@@ -118,21 +138,21 @@ static Caphash *remcap(uint8_t *hash)
 {
Caphash *t, **l;
 
-   qlock();
+   qlock(&()->qlock);
 
/* find the matching capability */
-   for (l =  *l != nil;) {
+   for (l =  *l != NULL;) {
t = *l;
if (memcmp(hash, t->hash, Hashlen) == 0)
break;
l = >next;
}
t = *l;
-   if (t != nil) {
+   if (t != NULL) {
capalloc.nhash--;
*l = t->next;
}
-   qunlock();
+   qunlock(&()->qlock);
 
return t;
 }
@@ -142,36 +162,36 @@ static void addcap(uint8_t *hash)
 {
Caphash *p, *t, **l;
 
-   p = smalloc(sizeof *p);
+   p = kzmalloc(sizeof *p, 0);
memmove(p->hash, hash, Hashlen);
-   p->next = nil;
+   p->next = NULL;
 
-   qlock();
+   qlock(&()->qlock);
 
/* trim extras */
while (capalloc.nhash >= Maxhash) {
t = capalloc.first;
-   if (t == nil)
+   if (t == NULL)
panic("addcap");
capalloc.first = t->next;
-   free(t);
+   kfree(t);
capalloc.nhash--;
}
 
/* add new one */
-   for (l =  *l != nil; l = &(*l)->next)
+   for (l =  *l != NULL; l = &(*l)->next)
;
*l = p;
capalloc.nhash++;
 
-   qunlock();
+   qunlock(&()->qlock);
 }
 
-static void capclose(Chan *c)
+static void capclose(struct chan *c)
 {
 }
 
-static int32_t capread(Chan *c, void *va, int32_t n, int64_t m)
+static int32_t capread(struct chan *c, void *va, int32_t n, int64_t m)
 {
switch ((uint32_t)c->qid.path) {
case Qdir:
@@ -184,14 +204,14 @@ static int32_t capread(Chan *c, void *va, int32_t n, 
int64_t m)
return n;
 }
 
-static int32_t capwrite(Chan *c, void *va, int32_t n, int64_t m)
+static int32_t capwrite(struct chan *c, void *va, int32_t n, int64_t m)
 {
Caphash *p;
char *cp;
uint8_t hash[Hashlen];
char *key, *from, *to;
char err[256];
-   Proc *up = externup();
+   struct proc *up = externup();
 
switch ((uint32_t)c->qid.path) {
case Qhash:
@@ -205,33 +225,33 @@ static 

[akaros] [PATCH 3/4] capability: run scripts/PLAN9 on capability device

2016-10-13 Thread Ronald G. Minnich
Change-Id: I55dbed3e636730c4768c61168f22c61c9e2c82fb
Signed-off-by: Ronald G. Minnich 
---
 kern/drivers/dev/capability.c | 108 +-
 1 file changed, 64 insertions(+), 44 deletions(-)

diff --git a/kern/drivers/dev/capability.c b/kern/drivers/dev/capability.c
index a3bafd7..9bd487c 100644
--- a/kern/drivers/dev/capability.c
+++ b/kern/drivers/dev/capability.c
@@ -7,14 +7,33 @@
  * in the LICENSE file.
  */
 
-#include "../port/error.h"
-#include "../port/lib.h"
-#include "dat.h"
-#include "fns.h"
-#include "mem.h"
-#include "u.h"
-
-#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 enum {
Hashlen = SHA1dlen,
@@ -32,7 +51,7 @@ struct Caphash {
 };
 
 struct {
-   QLock QLock;
+   qlock_t qlock_t qlock;
Caphash *first;
int nhash;
 } capalloc;
@@ -44,31 +63,32 @@ enum {
 };
 
 /* caphash must be last */
-Dirtab capdir[] = {
+struct dirtab capdir[] = {
 ".",   {Qdir, 0, QTDIR}, 0, DMDIR | 0500, "capuse", {Quse}, 0, 0222,
 "caphash", {Qhash},  0, 0200,
 };
-int ncapdir = nelem(capdir);
+int ncapdir = ARRAY_SIZE(capdir);
 
-static Chan *capattach(char *spec)
+static struct chan *capattach(char *spec)
 {
return devattach(L'¤', spec);
 }
 
-static Walkqid *capwalk(Chan *c, Chan *nc, char **name, int nname)
+static struct walkqid *capwalk(struct chan *c, struct chan *nc, char **name,
+   int nname)
 {
return devwalk(c, nc, name, nname, capdir, ncapdir, devgen);
 }
 
-static void capremove(Chan *c)
+static void capremove(struct chan *c)
 {
if (iseve() && c->qid.path == Qhash)
-   ncapdir = nelem(capdir) - 1;
+   ncapdir = ARRAY_SIZE(capdir) - 1;
else
error(Eperm);
 }
 
-static int32_t capstat(Chan *c, uint8_t *db, int32_t n)
+static int32_t capstat(struct chan *c, uint8_t *db, int32_t n)
 {
return devstat(c, db, n, capdir, ncapdir, devgen);
 }
@@ -76,7 +96,7 @@ static int32_t capstat(Chan *c, uint8_t *db, int32_t n)
 /*
  *  if the stream doesn't exist, create it
  */
-static Chan *capopen(Chan *c, int omode)
+static struct chan *capopen(struct chan *c, int omode)
 {
if (c->qid.type & QTDIR) {
if (omode != OREAD)
@@ -102,7 +122,7 @@ static Chan *capopen(Chan *c, int omode)
 
 /*
 static char*
-hashstr(uchar *hash)
+hashstr(uint8_t *hash)
 {
 static char buf[2*Hashlen+1];
 int i;
@@ -118,21 +138,21 @@ static Caphash *remcap(uint8_t *hash)
 {
Caphash *t, **l;
 
-   qlock();
+   qlock(&()->qlock);
 
/* find the matching capability */
-   for (l =  *l != nil;) {
+   for (l =  *l != NULL;) {
t = *l;
if (memcmp(hash, t->hash, Hashlen) == 0)
break;
l = >next;
}
t = *l;
-   if (t != nil) {
+   if (t != NULL) {
capalloc.nhash--;
*l = t->next;
}
-   qunlock();
+   qunlock(&()->qlock);
 
return t;
 }
@@ -142,36 +162,36 @@ static void addcap(uint8_t *hash)
 {
Caphash *p, *t, **l;
 
-   p = smalloc(sizeof *p);
+   p = kzmalloc(sizeof *p, 0);
memmove(p->hash, hash, Hashlen);
-   p->next = nil;
+   p->next = NULL;
 
-   qlock();
+   qlock(&()->qlock);
 
/* trim extras */
while (capalloc.nhash >= Maxhash) {
t = capalloc.first;
-   if (t == nil)
+   if (t == NULL)
panic("addcap");
capalloc.first = t->next;
-   free(t);
+   kfree(t);
capalloc.nhash--;
}
 
/* add new one */
-   for (l =  *l != nil; l = &(*l)->next)
+   for (l =  *l != NULL; l = &(*l)->next)
;
*l = p;
capalloc.nhash++;
 
-   qunlock();
+   qunlock(&()->qlock);
 }
 
-static void capclose(Chan *c)
+static void capclose(struct chan *c)
 {
 }
 
-static int32_t capread(Chan *c, void *va, int32_t n, int64_t m)
+static int32_t capread(struct chan *c, void *va, int32_t n, int64_t m)
 {
switch ((uint32_t)c->qid.path) {
case Qdir:
@@ -184,14 +204,14 @@ static int32_t capread(Chan *c, void *va, int32_t n, 
int64_t m)
return n;
 }
 
-static int32_t capwrite(Chan *c, void *va, int32_t n, int64_t m)
+static int32_t capwrite(struct chan *c, void *va, int32_t n, int64_t m)
 {
Caphash *p;
char *cp;
uint8_t hash[Hashlen];
char *key, *from, *to;
char err[256];
-   Proc *up = externup();
+   struct proc *up = externup();
 
switch ((uint32_t)c->qid.path) {
case Qhash:
@@ -205,33 +225,33 @@ static