Add a devstat helper
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 6 Oct 2016 18:44:37 +0000 (14:44 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 6 Oct 2016 19:41:48 +0000 (15:41 -0400)
Devices can use this if they want to do build their own stat functions,
given a dir.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/include/ns.h
kern/src/ns/dev.c

index 9e44780..9566d1d 100644 (file)
@@ -715,6 +715,7 @@ void devpermcheck(char *unused_char_p_t, uint32_t, int);
 void devremove(struct chan *);
 void devreset(void);
 void devshutdown(void);
+size_t dev_make_stat(struct chan *c, struct dir *dir, uint8_t *dp, size_t n);
 int devstat(struct chan *, uint8_t * unused_uint8_p_t, int unused_int,
                        struct dirtab *, int unused_int2, Devgen *);
 struct walkqid *devwalk(struct chan *,
index c651c1a..496cf94 100644 (file)
@@ -289,6 +289,18 @@ Done:
        return wq;
 }
 
+/* Helper, makes a stat in @dp, given @n bytes, from chan @c's contents in @dir.
+ * Throws on error, returns the size used on success. */
+size_t dev_make_stat(struct chan *c, struct dir *dir, uint8_t *dp, size_t n)
+{
+       if (c->flag & CMSG)
+               dir->mode |= DMMOUNT;
+       n = convD2M(dir, dp, n);
+       if (n == 0)
+               error(EINVAL, ERROR_FIXME);
+       return n;
+}
+
 int
 devstat(struct chan *c, uint8_t * db, int n,
                struct dirtab *tab, int ntab, Devgen * gen)
@@ -326,14 +338,8 @@ devstat(struct chan *c, uint8_t * db, int n,
                        case 1:
                                printd("DEVSTAT gen returns path %p name %s, want path %p\n",
                                           dir.qid.path, dir.name, c->qid.path);
-                               if (c->qid.path == dir.qid.path) {
-                                       if (c->flag & CMSG)
-                                               dir.mode |= DMMOUNT;
-                                       n = convD2M(&dir, db, n);
-                                       if (n == 0)
-                                               error(EINVAL, ERROR_FIXME);
-                                       return n;
-                               }
+                               if (c->qid.path == dir.qid.path)
+                                       return dev_make_stat(c, &dir, db, n);
                                break;
                }
 }