hfs: fix not erasing deleted b-tree node issue
Subsystems (2)
Viacheslav Dubeyko
maintainerPATCH v2 1/1 hfs: fix not erasing deleted b-tree node issue
The generic/001 test of xfstests suite fails and corrupts the HFS volume:
sudo ./check generic/001
FSTYP -- hfs PLATFORM -- Linux/x86_64 hfsplus-testing-0001 6.15.0-rc2+ #3 SMP PREEMPT_DYNAMIC Fri Apr 25 17:13:00 PDT 2> MKFS_OPTIONS -- /dev/loop51
MOUNT_OPTIONS -- /dev/loop51 /mnt/scratch
generic/001 32s ... _check_generic_filesystem: filesystem on /dev/loop50 is inconsistent (see /home/slavad/XFSTESTS-2/xfstests-dev/results//generic/001.full for details)
Ran: generic/001
Failures: generic/001
Failed 1 of 1 tests
fsck.hfs -d -n ./test-image.bin
** ./test-image.bin (NO WRITE)
Using cacheBlockSize=32K cacheTotalBlock=1024 cacheSize=32768K.
Executing fsck_hfs (version 540.1-Linux).
** Checking HFS volume.
The volume name is untitled
** Checking extents overflow file.
** Checking catalog file.
Unused node is not erased (node = 2)
Unused node is not erased (node = 4)
<skipped>
Unused node is not erased (node = 253)
Unused node is not erased (node = 254)
Unused node is not erased (node = 255)
Unused node is not erased (node = 256)
** Checking catalog hierarchy.
** Checking volume bitmap.
** Checking volume information.
Verify Status: VIStat = 0x0000, ABTStat = 0x0000 EBTStat = 0x0000
CBTStat = 0x0004 CatStat = 0x00000000 ** The volume untitled was found corrupt and needs to be repaired. volume type is HFS primary MDB is at block 2 0x02 alternate MDB is at block 20971518 0x13ffffe primary VHB is at block 0 0x00 alternate VHB is at block 0 0x00 sector size = 512 0x200 VolumeObject flags = 0x19 total sectors for volume = 20971520 0x1400000 total sectors for embedded volume = 0 0x00
This patch adds logic of clearing the deleted b-tree node.
sudo ./check generic/001
FSTYP -- hfs PLATFORM -- Linux/x86_64 hfsplus-testing-0001 6.15.0-rc2+ #3 SMP PREEMPT_DYNAMIC Fri Apr 25 17:13:00 PDT 2025 MKFS_OPTIONS -- /dev/loop51
MOUNT_OPTIONS -- /dev/loop51 /mnt/scratch
generic/001 9s ... 32s
Ran: generic/001
Passed all 1 tests
fsck.hfs -d -n ./test-image.bin
** ./test-image.bin (NO WRITE)
Using cacheBlockSize=32K cacheTotalBlock=1024 cacheSize=32768K.
Executing fsck_hfs (version 540.1-Linux).
** Checking HFS volume.
The volume name is untitled
** Checking extents overflow file.
** Checking catalog file.
** Checking catalog hierarchy.
** Checking volume bitmap.
** Checking volume information.
** The volume untitled appears to be OK.
--- fs/hfs/bnode.c | 1 + 1 file changed, 1 insertion(+)
fs/hfs/bnode.c +1 -0
@@ -482,6 +482,7 @@ void hfs_bnode_put(struct hfs_bnode *node)if (test_bit (HFS_BNODE_DELETED , &node->flags)) {hfs_bnode_unhash (node);spin_unlock (&tree->hash_lock); +hfs_bnode_clear (node,0 , tree->node_size);hfs_bmap_free (node);hfs_bnode_free (node);return ;
Signature · 1 line
2.34.1
Looks good,
李扬韬
maintainerHi Slava,
In hfsplus, there are:
if (hfs_bnode_need_zeroout(tree))
hfs_bnode_clear(node, 0, tree->node_size);bool hfs_bnode_need_zeroout(struct hfs_btree *tree)
{
struct super_block *sb = tree->inode->i_sb;
struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
const u32 volume_attr = be32_to_cpu(sbi->s_vhdr->attributes);
return tree->cnid == HFSPLUS_CAT_CNID &&
volume_attr & HFSPLUS_VOL_UNUSED_NODE_FIX;
} So do we need to change it to
if (tree->cnid == HFS_CAT_CNID) hfs_bnode_clear(node, 0, tree->node_size);
or something else?
Thx,
Yangtao
Hi Yangtao,
Quoted 17 lines · 李扬韬
Hi Slava,
In hfsplus, there are:
if (hfs_bnode_need_zeroout(tree)) hfs_bnode_clear(node, 0, tree->node_size);bool
hfs_bnode_need_zeroout(struct hfs_btree *tree){ struct super_block *sb = tree->inode->i_sb; struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb); const u32 volume_attr = be32_to_cpu(sbi->s_vhdr->attributes); return tree->cnid == HFSPLUS_CAT_CNID && volume_attr & HFSPLUS_VOL_UNUSED_NODE_FIX; }
Quoted 7 lines
So do we need to change it to
if (tree->cnid == HFS_CAT_CNID) hfs_bnode_clear(node, 0, tree->node_size);or something else?
As far as I can see, it's not well documented feature. So, from one point of view, it's make sense to check what fsck.hfs expects to see. Adrian, could we check the fsck.hfs code? Maybe, we can find the answer there. From another point of view, we have two key b-trees in HFS (Catalog file and Extents Overflow file). And, I believe that it's good to zeroout the deleted nodes as for Catalog File as for Extents Overflow file. Because, it could guarantee that "garbage" from previous/deleted b-tree node state will not effect the operation with current state of b-tree node.
Thanks,
Slava.
Viacheslav Dubeyko
maintainerHi Christian,
Could you please pick up the patch?
Thanks,
Slava.
Quoted 95 lines · Viacheslav Dubeyko
The generic/001 test of xfstests suite fails and corrupts the HFS volume:
sudo ./check generic/001
FSTYP -- hfs
PLATFORM -- Linux/x86_64 hfsplus-testing-0001 6.15.0-rc2+ #3 SMPPREEMPT_DYNAMICFri Apr 25 17:13:00 PDT 2>
MKFS_OPTIONS --/dev/loop51MOUNT_OPTIONS--/dev/loop51/mnt/scratchgeneric/001 32s ...
_check_generic_filesystem: filesystem on/dev/loop50is inconsistent
(see/home/slavad/XFSTESTS-2/xfstests-dev/results//generic/001.fullfor details)Ran: generic/001
Failures: generic/001
Failed 1 of 1 testsfsck.hfs -d -n ./test-image.bin
** ./test-image.bin (NO WRITE)
Using cacheBlockSize=32K cacheTotalBlock=1024
cacheSize=32768K.
Executingfsck_hfs(version 540.1-Linux).
** Checking HFS volume.
The volume name is untitled
** Checking extents overflow file.
** Checking catalog file.
Unused node is not erased (node = 2)
Unused node is not erased (node = 4)
<skipped>
Unused node is not erased (node = 253)
Unused node is not erased (node = 254)
Unused node is not erased (node = 255)
Unused node is not erased (node = 256)
** Checking catalog hierarchy.
** Checking volume bitmap.
** Checking volume information.
Verify Status: VIStat =0x0000, ABTStat =0x0000EBTStat =0x0000CBTStat =0x0004CatStat =0x00000000** The volume untitled was found corrupt and needs to be repaired.volume type is HFS primary MDB is at block 2 0x02 alternate MDB is at block 20971518 0x13ffffe primary VHB is at block 0 0x00 alternate VHB is at block 0 0x00 sector size = 512 0x200 VolumeObject flags = 0x19 total sectors for volume = 20971520 0x1400000 total sectors for embedded volume = 0 0x00This patch adds logic of clearing the deleted b-tree node.
sudo ./check generic/001
FSTYP -- hfs
PLATFORM -- Linux/x86_64 hfsplus-testing-0001 6.15.0-rc2+ #3 SMPPREEMPT_DYNAMICFri Apr 25 17:13:00 PDT 2025
MKFS_OPTIONS --/dev/loop51MOUNT_OPTIONS--/dev/loop51/mnt/scratchgeneric/001 9s ... 32s
Ran: generic/001
Passed all 1 testsfsck.hfs -d -n ./test-image.bin
** ./test-image.bin (NO WRITE)
Using cacheBlockSize=32K cacheTotalBlock=1024
cacheSize=32768K.
Executingfsck_hfs(version 540.1-Linux). ** Checking HFS volume.
The volume name is untitled
** Checking extents overflow file.
** Checking catalog file.
** Checking catalog hierarchy.
** Checking volume bitmap.
** Checking volume information.
** The volume untitled appears to be OK.Signed-off-by Viacheslav Dubeyko <[email protected]>---
fs/hfs/bnode.c | 1 +1 file changed, 1 insertion(+)fs/hfs/bnode.c +1
-0@@ -482,6 +482,7 @@ void hfs_bnode_put(struct hfs_bnode *node) if (test_bit(HFS_BNODE_DELETED, &node->flags)) { hfs_bnode_unhash(node); spin_unlock(&tree->hash_lock); +hfs_bnode_clear (node,0 , tree->node_size); hfs_bmap_free(node); hfs_bnode_free(node); return;