From 8baac760500980d4b83e8de2e90265bfaa19df13 Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Tue, 4 Jun 2019 05:57:47 -0400 Subject: support read() and write() bigger than one page --- pipe.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'pipe.c') diff --git a/pipe.c b/pipe.c index 1274a3a..31bf0cc 100644 --- a/pipe.c +++ b/pipe.c @@ -76,9 +76,11 @@ pipeclose(struct pipe *p, int writable) //PAGEBREAK: 40 int -pipewrite(struct pipe *p, char *addr, int n) +pipewrite(struct pipe *p, uint64 addr, int n) { int i; + char ch; + struct proc *pr = myproc(); acquire(&p->lock); for(i = 0; i < n; i++){ @@ -90,7 +92,9 @@ pipewrite(struct pipe *p, char *addr, int n) wakeup(&p->nread); sleep(&p->nwrite, &p->lock); //DOC: pipewrite-sleep } - p->data[p->nwrite++ % PIPESIZE] = addr[i]; + if(copyin(pr->pagetable, &ch, addr + i, 1) == -1) + break; + p->data[p->nwrite++ % PIPESIZE] = ch; } wakeup(&p->nread); //DOC: pipewrite-wakeup1 release(&p->lock); @@ -98,9 +102,11 @@ pipewrite(struct pipe *p, char *addr, int n) } int -piperead(struct pipe *p, char *addr, int n) +piperead(struct pipe *p, uint64 addr, int n) { int i; + struct proc *pr = myproc(); + char ch; acquire(&p->lock); while(p->nread == p->nwrite && p->writeopen){ //DOC: pipe-empty @@ -113,7 +119,9 @@ piperead(struct pipe *p, char *addr, int n) for(i = 0; i < n; i++){ //DOC: piperead-copy if(p->nread == p->nwrite) break; - addr[i] = p->data[p->nread++ % PIPESIZE]; + ch = p->data[p->nread++ % PIPESIZE]; + if(copyout(pr->pagetable, addr + i, &ch, 1) == -1) + break; } wakeup(&p->nwrite); //DOC: piperead-wakeup release(&p->lock); -- cgit v1.2.3