Only ilock in pwrite is there's a chance of growing the file

上级 08d9fdca
......@@ -126,12 +126,23 @@ ssize_t
file::pwrite(const char *addr, size_t n, off_t off)
{
if(type == file::FD_INODE){
bool unlock;
int r;
ilock(ip, 1);
if(ip->type == 0 || ip->type == T_DIR)
panic("filewrite but 0 or T_DIR");
unlock = false;
if (n+off > ip->size) {
ilock(ip, 1);
unlock = true;
}
r = writei(ip, addr, off, n);
iunlock(ip);
if (unlock)
iunlock(ip);
return r;
}
return -1;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论