]> git.ipfire.org Git - thirdparty/linux.git/commit
fat: Fix persisting directory entries on fsync(2) of the root directory
authorChristian Brauner <brauner@kernel.org>
Mon, 27 Jul 2026 15:16:43 +0000 (17:16 +0200)
committerChristian Brauner <brauner@kernel.org>
Mon, 27 Jul 2026 15:16:43 +0000 (17:16 +0200)
commit28cb64a67b8ff2785fc85249ae74ff475fd2ca99
treea56095aff88fee7feed11e9515026ef50d881b9b
parenta50587bbf30b04c1c643ecff1efd27acf6b933ec
fat: Fix persisting directory entries on fsync(2) of the root directory

Buffers containing the directory entries of a directory's children are
tracked in the directory inode's metadata bh list. Before commit
525da4f40a7c ("fat: Fix missed inode writeback during fsync(2)")
fsync(2) of a directory wrote that list out unconditionally via
mmb_fsync_noflush(). Now the list is written by
fat_sync_inode_metadata() which __writeback_single_inode() only
invokes when the inode has I_METADATA_WRITEBACK set. The root inode
never gets I_METADATA_WRITEBACK - __fat_write_inode() returns early
for it since the root directory has no directory entry of its own -
and fat_sync_inode_metadata() returns early for it as well. Hence
fsync(2) on the root directory returns success without writing out the
directory entries of its children.

Set I_METADATA_WRITEBACK for the root inode in __fat_write_inode() and
make fat_sync_inode_metadata() only skip the nonexistent directory
entry for the root inode but still sync the metadata bh list.

Fixes: 525da4f40a7c ("fat: Fix missed inode writeback during fsync(2)")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
fs/fat/inode.c