summaryrefslogtreecommitdiff
path: root/pipe.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2019-06-04 05:57:47 -0400
committerRobert Morris <[email protected]>2019-06-04 05:57:47 -0400
commit8baac760500980d4b83e8de2e90265bfaa19df13 (patch)
treeceb59412ec44ff98c1281627fb648deaeedb0d04 /pipe.c
parentcefe223bf5e4b68e5c1202f2f089a164ad656621 (diff)
downloadxv6-labs-8baac760500980d4b83e8de2e90265bfaa19df13.tar.gz
xv6-labs-8baac760500980d4b83e8de2e90265bfaa19df13.tar.bz2
xv6-labs-8baac760500980d4b83e8de2e90265bfaa19df13.zip
support read() and write() bigger than one page
Diffstat (limited to 'pipe.c')
-rw-r--r--pipe.c16
1 files changed, 12 insertions, 4 deletions
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);