hopefully make writei more correct
This commit is contained in:
parent
147855e521
commit
d7c0a1b7a7
|
@ -166,10 +166,10 @@ filewrite(struct file *f, uint64 addr, int n)
|
||||||
iunlock(f->ip);
|
iunlock(f->ip);
|
||||||
end_op();
|
end_op();
|
||||||
|
|
||||||
if(r < 0)
|
if(r != n1){
|
||||||
|
// error from writei
|
||||||
break;
|
break;
|
||||||
if(r != n1)
|
}
|
||||||
panic("short filewrite");
|
|
||||||
i += r;
|
i += r;
|
||||||
}
|
}
|
||||||
ret = (i == n ? n : -1);
|
ret = (i == n ? n : -1);
|
||||||
|
|
21
kernel/fs.c
21
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.
|
// Caller must hold ip->lock.
|
||||||
// If user_src==1, then src is a user virtual address;
|
// If user_src==1, then src is a user virtual address;
|
||||||
// otherwise, src is a kernel 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
|
int
|
||||||
writei(struct inode *ip, int user_src, uint64 src, uint off, uint n)
|
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);
|
m = min(n - tot, BSIZE - off%BSIZE);
|
||||||
if(either_copyin(bp->data + (off % BSIZE), user_src, src, m) == -1) {
|
if(either_copyin(bp->data + (off % BSIZE), user_src, src, m) == -1) {
|
||||||
brelse(bp);
|
brelse(bp);
|
||||||
n = -1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
log_write(bp);
|
log_write(bp);
|
||||||
brelse(bp);
|
brelse(bp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(n > 0){
|
if(off > ip->size)
|
||||||
if(off > ip->size)
|
ip->size = off;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
// Directories
|
||||||
|
|
Loading…
Reference in a new issue