On 6/28/22 3:28 AM, Qu Wenruo wrote:
[BACKGROUND]
Unlike FUSE/Kernel which always pass aligned read range, U-boot fs code
just pass the request range to underlying fses.
Under most case, this works fine, as U-boot only really needs to read
the whole file (aka, 0 for both offset and len, len will be later
determined using file size).
But if some advanced user/script wants to extract kernel/initramfs from
combined image, we may need to do unaligned read in that case.
[ADVANTAGE]
This patchset will handle unaligned read range in _fs_read():
- Get blocksize of the underlying fs
- Read the leading block contianing the unaligned range
The full block will be stored in a local buffer, then only copy
the bytes in the unaligned range into the destination buffer.
If the first block covers the whole range, we just call it aday.
- Read the aligned range if there is any
- Read the tailing block containing the unaligned range
And copy the covered range into the destination.
[DISADVANTAGE]
There are mainly two problems:
- Extra memory allocation for every _fs_read() call
For the leading and tailing block.
- Extra path resolving
All those supported fs will have to do extra path resolving up to 2
times (one for the leading block, one for the tailing block).
This may slow down the read.
[SUPPORTED FSES]
- Btrfs (manually tested*)
- Ext4 (manually tested)
- FAT (manually tested)
- Erofs
- sandboxfs
- ubifs
*: Failed to get the test cases run, thus have to go sandbox mode, and
attach an image with target fs, load the target file (with unaligned
range) and compare the result using md5sum.
For EXT4/FAT, they may need extra cleanup, as their existing unaligned
range handling is no longer needed anymore, cleaning them up should free
more code lines than the added one.
Just not confident enough to modify them all by myself.
[UNSUPPORTED FSES]
- Squashfs
They don't support non-zero offset, thus it can not handle the tailing
block reading.
Need extra help to add block aligned offset support.
- Semihostfs
It's using hardcoded trap to do system calls, not sure how it would
work for stat() call.
There are no alignment requirements for semihosted FSs. So you can pass in
an unaligned offset and it will work fine. This is because typically the
host will call read() and the host OS will do the aligning.
--Sean