Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Galfurian committed Feb 28, 2024
2 parents 189f2ce + ee2f95e commit bc0c921
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions mentos/src/fs/ext2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1413,8 +1413,6 @@ static int ext2_allocate_inode_block(ext2_filesystem_t *fs, ext2_inode_t *inode,
if (inode->blocks_count < blocks_count) {
// Set the blocks count.
inode->blocks_count = blocks_count;
// Update the size.
inode->size = (blocks_count / fs->blocks_per_block_count) * fs->block_size;
pr_debug("Setting the block count for inode `%d` to `%d` blocks.\n", inode_index, blocks_count / fs->blocks_per_block_count);
}
// Update the inode.
Expand Down Expand Up @@ -1557,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;
Expand Down Expand Up @@ -2587,7 +2589,10 @@ static ssize_t ext2_write(vfs_file_t *file, const void *buffer, off_t offset, si
pr_err("Failed to read the inode `%s`.\n", file->name);
return -1;
}
return ext2_write_inode_data(fs, &inode, file->ino, offset, nbyte, (char *)buffer);
ssize_t written = ext2_write_inode_data(fs, &inode, file->ino, offset, nbyte, (char *)buffer);
// Update the file length
file->length = inode.size;
return written;
}

/// @brief Repositions the file offset inside a file.
Expand Down

0 comments on commit bc0c921

Please sign in to comment.