]> git.hungrycats.org Git - btrfs-progs/commitdiff
btrfs-progs: tests: add case for unexpected file extent items
authorQu Wenruo <wqu@suse.com>
Tue, 18 Aug 2026 06:04:07 +0000 (15:34 +0930)
committerDavid Sterba <dsterba@suse.com>
Tue, 8 Sep 2026 19:33:00 +0000 (21:33 +0200)
The image is created using btrfs-corrupt-block, the fs tree leaf looks
like this:

item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160
generation 3 transid 9 size 12 nbytes 16384
block group 0 mode 40755 links 1 uid 0 gid 0 rdev 0
sequence 1 flags 0x0(none)
item 1 key (256 INODE_REF 256) itemoff 16111 itemsize 12
index 0 namelen 2 name: ..
item 2 key (256 DIR_ITEM 496027801) itemoff 16075 itemsize 36
location key (257 INODE_ITEM 0) type BLKDEV <<<
transid 9 data_len 0 name_len 6
name: foobar
item 3 key (256 DIR_INDEX 2) itemoff 16039 itemsize 36
location key (257 INODE_ITEM 0) type BLKDEV <<<
transid 9 data_len 0 name_len 6
name: foobar
item 4 key (257 INODE_ITEM 0) itemoff 15879 itemsize 160
generation 9 transid 9 size 8192 nbytes 8192
block group 0 mode 60660 links 1 uid 0 gid 0 rdev 0 <<<
sequence 2 flags 0x0(none)
item 5 key (257 INODE_REF 256) itemoff 15863 itemsize 16
index 2 namelen 6 name: foobar
item 6 key (257 EXTENT_DATA 0) itemoff 15810 itemsize 53
generation 9 type 1 (regular)
extent data disk byte 13631488 nr 8192
extent data offset 0 nr 8192 ram 8192
extent compression 0 (none)

The image is generated by the following steps:

  # mkfs.btrfs -f $dev
  # mount $dev $mnt
  # xfs_io -f -c "pwrite 0 4k" $mnt/foobar
  # umount $mnt

  ## Change the inode's mode from REG to BLK
  # btrfs-corrupt-block -i 257 -f mode --value 25008 $dev

  ## Change the dir item's flag from REG to BLK
  # btrfs-corrupt-block -D 256,84,496027801 -f flags --value 4 $dev

  ## Change the dir index's flag from REG to BLK
  # btrfs-corrupt-block -D 256,96,2 -f flags --value 4 $dev

The inode's mode and dir flags all match, but there is one unexpected
file extent item there.

Both lowmem and original mode should detect such problem.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
tests/fsck-tests/075-blk-inode-with-data/default.img.xz [new file with mode: 0644]
tests/fsck-tests/075-blk-inode-with-data/test.sh [new file with mode: 0755]

diff --git a/tests/fsck-tests/075-blk-inode-with-data/default.img.xz b/tests/fsck-tests/075-blk-inode-with-data/default.img.xz
new file mode 100644 (file)
index 0000000..7fc1c58
Binary files /dev/null and b/tests/fsck-tests/075-blk-inode-with-data/default.img.xz differ
diff --git a/tests/fsck-tests/075-blk-inode-with-data/test.sh b/tests/fsck-tests/075-blk-inode-with-data/test.sh
new file mode 100755 (executable)
index 0000000..b72c03f
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+#
+# Verify that check can detect unexpected file extent items for special inodes
+# which should not have any file extent.
+
+source "$TEST_TOP/common" || exit
+
+check_prereq btrfs
+
+check_image() {
+       # The image contains a BLK inode, with a file extent.
+       # The check should report an error.
+       run_mustfail "unexpected file extent not detected" "$TOP/btrfs" check "$1"
+}
+
+check_all_images