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

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