Skip to content

Commit d5ca0eb

Browse files
committed
Fix incorrect block count calculation
For a 4MiB file, inode->i_blocks returned 1026, but the maximum block count should be 1025 (including the index block). This commit rounds up i_blocks precisely in simplefs_write_end.
1 parent d852783 commit d5ca0eb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static int simplefs_write_end(struct file *file,
190190
nr_blocks_old = inode->i_blocks;
191191

192192
/* Update inode metadata */
193-
inode->i_blocks = inode->i_size / SIMPLEFS_BLOCK_SIZE + 2;
193+
inode->i_blocks = DIV_ROUND_UP(inode->i_size, SIMPLEFS_BLOCK_SIZE) + 1;
194194

195195
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
196196
cur_time = current_time(inode);

0 commit comments

Comments
 (0)