Skip to content

daxfs: Fix truncate not updating VFS i_size in setattr#9

Merged
congwang-mk merged 1 commit into
multikernel:mainfrom
amlalabs:issue_8_overlay_modify
Mar 17, 2026
Merged

daxfs: Fix truncate not updating VFS i_size in setattr#9
congwang-mk merged 1 commit into
multikernel:mainfrom
amlalabs:issue_8_overlay_modify

Conversation

@souvik1997
Copy link
Copy Markdown
Contributor

daxfs_setattr() relied on setattr_copy() to update i_size when handling ATTR_SIZE (e.g. O_TRUNC). However, setattr_copy() does not handle ATTR_SIZE — the filesystem must update i_size itself.

This caused a bug where overwriting an existing file via shell redirect (echo "..." > file) would produce empty reads:

  1. O_TRUNC triggers setattr(ATTR_SIZE=0) which creates an overlay inode entry with size=0, but VFS i_size stays at the original base image size (e.g. 23 bytes)
  2. The subsequent write (21 bytes) sees pos(21) <= i_size(23), so the "update size if extending" check is skipped — the overlay inode size is never updated from 0
  3. On read, daxfs_refresh_isize() reads overlay size=0 and clobbers VFS i_size to 0, causing the read to return empty

Fix by calling truncate_setsize() before setattr_copy() when ATTR_SIZE is set. This is the standard pattern used by other Linux filesystems (ramfs, tmpfs, etc.).

Fixes: #8

daxfs_setattr() relied on setattr_copy() to update i_size when
handling ATTR_SIZE (e.g. O_TRUNC). However, setattr_copy() does not
handle ATTR_SIZE — the filesystem must update i_size itself.

This caused a bug where overwriting an existing file via shell redirect
(echo "..." > file) would produce empty reads:

1. O_TRUNC triggers setattr(ATTR_SIZE=0) which creates an overlay
   inode entry with size=0, but VFS i_size stays at the original
   base image size (e.g. 23 bytes)
2. The subsequent write (21 bytes) sees pos(21) <= i_size(23), so
   the "update size if extending" check is skipped — the overlay
   inode size is never updated from 0
3. On read, daxfs_refresh_isize() reads overlay size=0 and clobbers
   VFS i_size to 0, causing the read to return empty

Fix by calling truncate_setsize() before setattr_copy() when
ATTR_SIZE is set. This is the standard pattern used by other Linux
filesystems (ramfs, tmpfs, etc.).
@congwang-mk congwang-mk merged commit 49ff92b into multikernel:main Mar 17, 2026
@congwang-mk
Copy link
Copy Markdown
Contributor

For long term, we may need to restructure daxfs_setattr().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The test_overlay_modify_file test in tests/test_overlay.sh fails with Content mismatch: ''

2 participants