u-boot/fs
Qu Wenruo b941d1cd16 fs: btrfs: Fix LZO false decompression error caused by pending zero
For certain btrfs files with compressed file extent, uboot will fail to
load it:

  btrfs_read_extent_reg: disk_bytenr=14229504 disk_len=73728 offset=0 nr_bytes=131
  072
  decompress_lzo: tot_len=70770
  decompress_lzo: in_len=1389
  decompress_lzo: in_len=2400
  decompress_lzo: in_len=3002
  decompress_lzo: in_len=1379
  decompress_lzo: in_len=88539136
  decompress_lzo: header error, in_len=88539136 clen=65534 tot_len=62580

NOTE: except the last line, all other lines are debug output.

Btrfs lzo compression uses its own format to record compressed size
(segment header, LE32).

However to make decompression easier, we never put such segment header
across page boundary.

In above case, the xxd dump of the lzo compressed data looks like this:

00001fe0: 4cdc 02fc 0bfd 02c0 dc02 0d13 0100 0001  L...............
00001ff0: 0000 0008 0300 0000 0000 0011 0000|0000  ................
00002000: 4705 0000 0001 cc02 0000 0000 0000 1e01  G...............

'|' is the "expected" segment header start position.

But in that page, there are only 2 bytes left, can't contain the 4 bytes
segment header.

So btrfs compression will skip that 2 bytes, put the segment header in
next page directly.

Uboot doesn't have such check, and read the header with 2 bytes offset,
result 0x05470000 (88539136), other than the expected result
0x00000547 (1351), resulting above error.

Follow the btrfs-progs restore implementation, by introducing tot_in to
record total processed bytes (including headers), and do proper page
boundary skip to fix it.

Please note that, current code base doesn't parse fs_info thus we can't
grab sector size easily, so it uses PAGE_SIZE, and relying on fs open
time check to exclude unsupported sector size.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Cc: Marek Behun <marek.behun@nic.cz>
Reviewed-by: Marek Behún <marek.behun@nic.cz>
2020-04-16 22:13:50 -04:00
..
btrfs fs: btrfs: Fix LZO false decompression error caused by pending zero 2020-04-16 22:13:50 -04:00
cbfs cbfs: Rename camel-case variables 2019-08-18 21:54:10 +08:00
cramfs SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
ext4 fs: ext4: Fix alignment of cache buffers 2020-03-27 15:42:04 -04:00
fat sandbox conversion to SDL2 2020-02-11 10:58:41 -05:00
jffs2 crc32: Use the crc.h header for crc functions 2019-12-02 18:23:08 -05:00
reiserfs SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
sandbox dm: core: Create a new header file for 'compat' features 2020-02-05 19:33:46 -07:00
ubifs dm: core: Create a new header file for 'compat' features 2020-02-05 19:33:46 -07:00
yaffs2 dm: core: Create a new header file for 'compat' features 2020-02-05 19:33:46 -07:00
zfs SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
fs.c fs: add fs_get_type() for current filesystem type 2019-10-17 19:19:56 +02:00
fs_internal.c SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
Kconfig fs: btrfs: Add U-Boot fs handlers. 2017-10-02 21:52:18 -04:00
Makefile cbfs: Allow CBFS to be used in SPL 2019-08-18 21:54:10 +08:00