hfsplus: fix volume corruption issue for generic/101
Subsystems (2)
Viacheslav Dubeyko
maintainerPATCH 1/1 hfsplus: fix volume corruption issue for generic/101
The xfstests' test-case generic/101 leaves HFS+ volume in corrupted state:
sudo ./check generic/101
FSTYP -- hfsplus
PLATFORM -- Linux/x86_64 hfsplus-testing-0001 6.17.0-rc1+ #4 SMP PREEMPT_DYNAMIC Wed Oct 1 15:02:44 PDT 2025 MKFS_OPTIONS -- /dev/loop51MOUNT_OPTIONS -- /dev/loop51 /mnt/scratch
generic/101 _check_generic_filesystem: filesystem on /dev/loop51 is inconsistent (see XFSTESTS-2/xfstests-dev/results//generic/101.full for details)
Ran: generic/101
Failures: generic/101
Failed 1 of 1 tests
sudo fsck.hfsplus -d /dev/loop51
** /dev/loop51
Using cacheBlockSize=32K cacheTotalBlock=1024 cacheSize=32768K. Executing fsck_hfs (version 540.1-Linux).
** Checking non-journaled HFS Plus Volume.
The volume name is untitled
** Checking extents overflow file.
** Checking catalog file.
** Checking multi-linked files.
** Checking catalog hierarchy.
** Checking extended attributes file.
** Checking volume bitmap.
** Checking volume information.
Invalid volume free block count
(It should be 2614350 instead of 2614382)
Verify Status: VIStat = 0x8000, ABTStat = 0x0000 EBTStat = 0x0000 CBTStat = 0x0000 CatStat = 0x00000000
** Repairing volume.
** Rechecking volume.
** Checking non-journaled HFS Plus Volume.
The volume name is untitled
** Checking extents overflow file.
** Checking catalog file.
** Checking multi-linked files.
** Checking catalog hierarchy.
** Checking extended attributes file.
** Checking volume bitmap.
** Checking volume information.
** The volume untitled was repaired successfully.
This test executes such steps: "Test that if we truncate a file to a smaller size, then truncate it to its original size or a larger size, then fsyncing it and a power failure happens, the file will have the range [first_truncate_size, last_size[ with all bytes having a value of 0x00 if we read it the next time the filesystem is mounted.".
HFS+ keeps volume's free block count in the superblock. However, hfsplus_file_fsync() doesn't store superblock's content. As a result, superblock contains not correct value of free blocks if a power failure happens.
This patch adds functionality of saving superblock's content during hfsplus_file_fsync() call.
sudo ./check generic/101
FSTYP -- hfsplus PLATFORM -- Linux/x86_64 hfsplus-testing-0001 6.18.0-rc3+ #96 SMP PREEMPT_DYNAMIC Wed Nov 19 12:47:37 PST 2025 MKFS_OPTIONS -- /dev/loop51
MOUNT_OPTIONS -- /dev/loop51 /mnt/scratch
generic/101 32s ... 30s
Ran: generic/101
Passed all 1 tests
sudo fsck.hfsplus -d /dev/loop51
** /dev/loop51
Using cacheBlockSize=32K cacheTotalBlock=1024 cacheSize=32768K.
Executing fsck_hfs (version 540.1-Linux).
** Checking non-journaled HFS Plus Volume.
The volume name is untitled
** Checking extents overflow file.
** Checking catalog file.
** Checking multi-linked files.
** Checking catalog hierarchy.
** Checking extended attributes file.
** Checking volume bitmap.
** Checking volume information.
** The volume untitled appears to be OK.
--- fs/hfsplus/hfsplus_fs.h | 2 + fs/hfsplus/inode.c | 9 +++++ fs/hfsplus/super.c | 87 +++++++++++++++++++++++++---------------- 3 files changed, 65 insertions(+), 33 deletions(-)
fs/hfsplus/hfsplus_fs.h +2 -0
@@ -477,6 +477,8 @@ int hfs_part_find(struct super_block *sb, sector_t *part_start,/* super.c */ struct inode *hfsplus_iget (struct super_block *sb,unsigned long ino);void hfsplus_mark_mdb_dirty (struct super_block *sb); +void hfsplus_prepare_volume_header_for_commit (struct hfsplus_vh *vhdr); +int hfsplus_commit_superblock (struct super_block *sb);/* tables.c */ extern u16 hfsplus_case_fold_table[];
fs/hfsplus/inode.c +9 -0
@@ -305,6 +305,7 @@ int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,struct inode *inode = file->f_mapping->host;struct hfsplus_inode_info *hip =HFSPLUS_I (inode);struct hfsplus_sb_info *sbi =HFSPLUS_SB (inode->i_sb); +struct hfsplus_vh *vhdr = sbi->s_vhdr;int error =0 , error2; error =file_write_and_wait_range (file, start, end);
@@ -348,6 +349,14 @@ int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end, error = error2; } +mutex_lock (&sbi->vh_mutex); +hfsplus_prepare_volume_header_for_commit (vhdr); +mutex_unlock (&sbi->vh_mutex); + + error2 =hfsplus_commit_superblock (inode->i_sb); +if (!error) + error = error2; +if (!test_bit (HFSPLUS_SB_NOBARRIER , &sbi->flags))blkdev_issue_flush (inode->i_sb->s_bdev);
fs/hfsplus/super.c +54 -33
122 lines not on this page · raw message
Signature · 1 line
2.43.0