diff options
author | Robert Morris <[email protected]> | 2019-06-04 05:57:47 -0400 |
---|---|---|
committer | Robert Morris <[email protected]> | 2019-06-04 05:57:47 -0400 |
commit | 8baac760500980d4b83e8de2e90265bfaa19df13 (patch) | |
tree | ceb59412ec44ff98c1281627fb648deaeedb0d04 /file.c | |
parent | cefe223bf5e4b68e5c1202f2f089a164ad656621 (diff) | |
download | xv6-labs-8baac760500980d4b83e8de2e90265bfaa19df13.tar.gz xv6-labs-8baac760500980d4b83e8de2e90265bfaa19df13.tar.bz2 xv6-labs-8baac760500980d4b83e8de2e90265bfaa19df13.zip |
support read() and write() bigger than one page
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 36 |
1 files changed, 4 insertions, 32 deletions
@@ -113,33 +113,17 @@ fileread(struct file *f, uint64 addr, int n) if(f->readable == 0) return -1; - // XXX break into page-size pieces. - if(n > PGSIZE) - panic("fileread PGSIZE"); - - buf = kalloc(); - if(buf == 0) - panic("fileread kalloc"); - if(f->type == FD_PIPE){ - r = piperead(f->pipe, buf, n); + r = piperead(f->pipe, addr, n); } else if(f->type == FD_INODE){ ilock(f->ip); - if((r = readi(f->ip, buf, f->off, n)) > 0) + if((r = readi(f->ip, 1, addr, f->off, n)) > 0) f->off += r; iunlock(f->ip); } else { panic("fileread"); } - if(r > 0){ - if(copyout(p->pagetable, addr, buf, n) < 0){ - r = -1; - } - } - - kfree(buf); - return r; } @@ -156,18 +140,8 @@ filewrite(struct file *f, uint64 addr, int n) if(f->writable == 0) return -1; - // XXX break into pieces - if(n > PGSIZE) - panic("filewrite PGSIZE"); - - buf = kalloc(); - if(copyin(p->pagetable, buf, addr, n) < 0){ - kfree(buf); - return -1; - } - if(f->type == FD_PIPE){ - ret = pipewrite(f->pipe, buf, n); + ret = pipewrite(f->pipe, addr, n); } else if(f->type == FD_INODE){ // write a few blocks at a time to avoid exceeding // the maximum log transaction size, including @@ -184,7 +158,7 @@ filewrite(struct file *f, uint64 addr, int n) begin_op(); ilock(f->ip); - if ((r = writei(f->ip, buf + i, f->off, n1)) > 0) + if ((r = writei(f->ip, 1, addr + i, f->off, n1)) > 0) f->off += r; iunlock(f->ip); end_op(); @@ -200,8 +174,6 @@ filewrite(struct file *f, uint64 addr, int n) panic("filewrite"); } - kfree(buf); - return ret; } |