Draft: FreeBSD: fix 'Invalid argument' error enforcing 512B aligned I/O #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here is draft patch to fix fatal error
Invalid argumentwhen accessing any block device (USB stick, disk drive, ...) on FreeBSD. It is caused by FreeBSD requirement that block device I/O must be aligned to sector size. So I simply copied Windows code part using 512 bytes to FreeBSD part.Warning
Proper patch should somehow detect used sector size, but I don't have 4K sectors USB stick to verify that.
Existing references:
Details: here is what happens when unpatched libcfile is used:
$ ./bdetools/bdeinfo -v /dev/da0 bdeinfo 20240625 Unable to open: /dev/da0. libcfile_file_read_buffer_with_error_code: unable to read from file with error: Invalid argument libcfile_file_read_buffer: unable to read from file. libbfio_file_io_handle_read_buffer: unable to read from file: /dev/da0. libbfio_file_range_io_handle_read_buffer: unable to read from file IO handle. libbfio_internal_handle_read_buffer: unable to read from handle. libbfio_handle_read_buffer_at_offset: unable to read buffer. libbde_metadata_block_header_read_file_io_handle: unable to read FVE metadata block header data at offset: 2472767488 (0x93637000). libbde_metadata_read_block: unable to read metadata block header. libbde_internal_volume_open_read: unable to read primary metadata block. libbde_volume_open_file_io_handle: unable to read from file IO handle. info_handle_open: unable to open volume.Truss command reveals what's the problem:
Notice that first read (512 bytes) finishes without error, while seconds read (64 bytes) fails with
Invalid argument. Also seek is OK (I use 4GB USB stick so it is in allowed range).Tested FreeBSD version:
Note: I tested my patch in quirky way:
synclibs.shinlibbdeproject to excludelibcfilefrom list:synclib-hp.shand hacked URLs and branch for it:libbdeproject):That did trick for me to use my own
libcfileproject and branch.