Properly report readable/writable in pipestat()
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 1 Dec 2016 18:29:05 +0000 (13:29 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 7 Dec 2016 22:46:48 +0000 (14:46 -0800)
This caused select() (which calls fstat()) to think that some files were
writable when they weren't.  If the pipe had a lot of bidirection space,
you won't notice.  We'd only notice the problem if one side was clogged.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/drivers/dev/pipe.c

index 9fb5d01..697e033 100644 (file)
@@ -230,13 +230,13 @@ static int pipestat(struct chan *c, uint8_t * db, int n)
                case Qdata0:
                        perm = tab[1].perm;
                        perm |= qreadable(p->q[0]) ? DMREADABLE : 0;
-                       perm |= qwritable(p->q[0]) ? DMWRITABLE : 0;
+                       perm |= qwritable(p->q[1]) ? DMWRITABLE : 0;
                        devdir(c, c->qid, tab[1].name, qlen(p->q[0]), eve, perm, &dir);
                        break;
                case Qdata1:
                        perm = tab[2].perm;
                        perm |= qreadable(p->q[1]) ? DMREADABLE : 0;
-                       perm |= qwritable(p->q[1]) ? DMWRITABLE : 0;
+                       perm |= qwritable(p->q[0]) ? DMWRITABLE : 0;
                        devdir(c, c->qid, tab[2].name, qlen(p->q[1]), eve, perm, &dir);
                        break;
                default: