summaryrefslogtreecommitdiff
path: root/kernel/fs.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2020-10-23 10:18:30 -0400
committerFrans Kaashoek <[email protected]>2020-11-05 06:56:51 -0500
commit5e392531c07966fd8a6bee50e3e357c553fb2a2f (patch)
treed58c45f27ef9431f277fc1b4cd411a13fb128fe3 /kernel/fs.c
parente1bb4c74346bc439e8c0cd93750f90bb82c537c8 (diff)
downloadxv6-labs-5e392531c07966fd8a6bee50e3e357c553fb2a2f.tar.gz
xv6-labs-5e392531c07966fd8a6bee50e3e357c553fb2a2f.tar.bz2
xv6-labs-5e392531c07966fd8a6bee50e3e357c553fb2a2f.zip
hopefully make writei more correct
Diffstat (limited to 'kernel/fs.c')
-rw-r--r--kernel/fs.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/kernel/fs.c b/kernel/fs.c
index 848b2c9..f33553a 100644
--- a/kernel/fs.c
+++ b/kernel/fs.c
@@ -480,6 +480,9 @@ readi(struct inode *ip, int user_dst, uint64 dst, uint off, uint n)
// Caller must hold ip->lock.
// If user_src==1, then src is a user virtual address;
// otherwise, src is a kernel address.
+// Returns the number of bytes successfully written.
+// If the return value is less than the requested n,
+// there was an error of some kind.
int
writei(struct inode *ip, int user_src, uint64 src, uint off, uint n)
{
@@ -496,23 +499,21 @@ writei(struct inode *ip, int user_src, uint64 src, uint off, uint n)
m = min(n - tot, BSIZE - off%BSIZE);
if(either_copyin(bp->data + (off % BSIZE), user_src, src, m) == -1) {
brelse(bp);
- n = -1;
break;
}
log_write(bp);
brelse(bp);
}
- if(n > 0){
- if(off > ip->size)
- ip->size = off;
- // write the i-node back to disk even if the size didn't change
- // because the loop above might have called bmap() and added a new
- // block to ip->addrs[].
- iupdate(ip);
- }
+ if(off > ip->size)
+ ip->size = off;
- return n;
+ // write the i-node back to disk even if the size didn't change
+ // because the loop above might have called bmap() and added a new
+ // block to ip->addrs[].
+ iupdate(ip);
+
+ return tot;
}
// Directories