u-boot/fs
Dominique Martinet b1d3013d02 btrfs: fix offset when reading compressed extents
btrfs_read_extent_reg correctly computed the extent offset in the
BTRFS_COMPRESS_NONE case, but did not account for the 'offset - key.offset'
part correctly in the compressed case, making the function read
incorrect data.

In the case I examined, the last 4k of a file was corrupted and
contained data from a few blocks prior, e.g. reading a 10k file with a
single extent:
btrfs_file_read()
 -> btrfs_read_extent_reg
    (aligned part loop, until 8k)
 -> read_and_truncate_page
   -> btrfs_read_extent_reg
      (re-reads the last extent from 8k to the end,
      incorrectly reading the first 2k of data)

This can be reproduced as follow:
$ truncate -s 200M btr
$ mount btr -o compress /mnt
$ pat() { dd if=/dev/zero bs=1M count=$1 iflag=count_bytes status=none | tr '\0' "\\$2"; }
$ { pat 4K 1; pat 4K 2; pat 2K 3; }  > /mnt/file
$ sync
$ filefrag -v /mnt/file
File size of /mnt/file is 10240 (3 blocks of 4096 bytes)
 ext:     logical_offset:        physical_offset: length:   expected: flags:
   0:        0..       2:       3328..      3330:      3:             last,encoded,eof
$ umount /mnt

Then in u-boot:
=> load scsi 0 2000000 file
10240 bytes read in 3 ms (3.3 MiB/s)
=> md 2001ff0
02001ff0: 02020202 02020202 02020202 02020202  ................
02002000: 01010101 01010101 01010101 01010101  ................
02002010: 01010101 01010101 01010101 01010101  ................

(02002000 onwards should contain '03' pattern but went back to 01,
start of the extent)

After patch, data is read properly:
=> md 2001ff0
02001ff0: 02020202 02020202 02020202 02020202  ................
02002000: 03030303 03030303 03030303 03030303  ................
02002010: 03030303 03030303 03030303 03030303  ................

Note that the code previously (before commit e3427184f3 ("fs: btrfs:
Implement btrfs_file_read()")) did not split that read in two, so
this is a regression even if the previous code might not have been
handling offsets correctly either (something that booted now fails to
boot)

Fixes: a26a6bedaf ("fs: btrfs: Introduce btrfs_read_extent_inline() and btrfs_read_extent_reg()")
Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
2023-05-08 09:23:53 -04:00
..
btrfs btrfs: fix offset when reading compressed extents 2023-05-08 09:23:53 -04:00
cbfs spl: Ensure all SPL symbols in Kconfig have some SPL dependency 2022-07-07 09:29:08 -04:00
cramfs cyclic: Use schedule() instead of WATCHDOG_RESET() 2022-09-18 10:26:33 +02:00
erofs Correct SPL use of FS_EROFS 2023-02-10 07:41:39 -05:00
ext4 fs: ext4: fix files seen as symlink during deletion 2023-03-30 15:09:59 -04:00
fat fs: fat: do not mangle short filenames 2023-03-30 15:09:59 -04:00
jffs2 fs: jffs2: Move SYS_JFFS2_SORT_FRAGMENTS to Kconfig 2022-11-10 09:45:54 -05:00
reiserfs common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
sandbox bootstd: sandbox: Add a hostfs bootdev 2022-04-25 10:00:04 -04:00
squashfs lib: zstd: update to latest Linux zstd 1.5.2 2023-01-18 19:04:17 -05:00
ubifs ubifs: Allow to silence debug dumps 2022-11-23 13:06:12 -05:00
yaffs2 fs: yaffs2: Make yaffsfs_deviceList static 2023-04-25 15:31:27 -04:00
zfs common: Drop log.h from common header 2020-05-18 21:19:18 -04:00
fs.c common: Drop display_options.h from common header 2022-08-10 13:46:55 -04:00
fs_internal.c fs: Quieten down the filesystems more 2022-10-17 21:17:12 -06:00
Kconfig bootstd: sandbox: Add a hostfs bootdev 2022-04-25 10:00:04 -04:00
Makefile fs: Add semihosting filesystem 2022-04-01 15:03:13 -04:00
semihostingfs.c fs: Add semihosting filesystem 2022-04-01 15:03:13 -04:00