ext2: write the inode back if its size is updated
If there is enough space in an inode but the file grows the
inode is never written back to the device and thus the new size is
not persisted.
int fd = creat("foo", 660);
write(fd, "foo", 3); // New blocks are allocated and inode written back
write(fd, "\n", 1); // size is adapted but not written back
close(fd);
// Reading the file afterwards will only return "foo".
The code snippet reproduces the bug.
This is fixed by always writing the inode back to the device if
the size is updated.
This commit is contained in:
@@ -1555,6 +1555,10 @@ static ssize_t ext2_write_inode_data(ext2_filesystem_t *fs, ext2_inode_t *inode,
|
||||
uint32_t end = offset + nbyte;
|
||||
if (end > inode->size) {
|
||||
inode->size = end;
|
||||
if (ext2_write_inode(fs, inode, inode_index) == -1) {
|
||||
pr_err("Failed to write the inode `%d`\n", inode_index);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
uint32_t start_block = offset / fs->block_size;
|
||||
uint32_t end_block = end / fs->block_size;
|
||||
|
||||
Reference in New Issue
Block a user