Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image-hd: fix CHS addresses in EBR #249

Merged

Conversation

sairon
Copy link
Contributor

@sairon sairon commented May 30, 2024

All CHS addresses in the EBR should point to absolute address in the image instead of the relative addresses, currently they are only LBA-to-CHS conversion of the relative offsets. If correct, output of sfdisk -d of the genimage-produced disk image piped back to sfdisk file.img should produce binary identical (see note below) output. However, it is not true, because the CHS addresses differ. Even though the extended partition uses the 0xf type (LBA addressing) and CHS addressing is limited to 1023 sectors, the generated output should be comparable to other tools for easier debugging.

With this change the calculation of CHS addresses of the next EBRs and logical partitions within the extended partition adds the proper offset, so the addresses are absolute within the image.

Note: At least with the version of sfdisk I have tested with (from util-linux 2.37.2), the image is not completely identical - there are one byte differences in the MBR and each MBR. This is because even if the partition type is set as 0xf, sfdisk produces the extended partition and all the logical partition with 0x5 type.

Copy link
Member

@michaelolbrich michaelolbrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good. Just a small nitpick.

image-hd.c Outdated Show resolved Hide resolved
@sairon sairon force-pushed the hdimage-fix-extended-partition-chs branch from e512007 to 0f5eb81 Compare June 3, 2024 09:02
@michaelolbrich michaelolbrich force-pushed the hdimage-fix-extended-partition-chs branch from 0f5eb81 to 1e4a0a0 Compare June 21, 2024 15:02
Copy link
Member

@michaelolbrich michaelolbrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've force-pushed a new version to squash the two commits. In the future, don't stack changes as new commits but squash the changes into the existing commits.

All CHS addresses in the EBR should point to absolute address in the
image instead of the relative addresses, currently they are only
LBA-to-CHS conversion of the relative offsets. If correct, output of
`sfdisk -d` of the genimage-produced disk image piped back to `sfdisk
file.img` should produce binary identical (see note below) output.
However, it is not true, because the CHS addresses differ. Even though
the extended partition uses the 0xf type (LBA addressing) and CHS
addressing is limited to 1023 sectors, the generated output should be
comparable to other tools for easier debugging.

With this change the calculation of CHS addresses of the next EBRs and
logical partitions within the extended partition adds the proper offset,
so the addresses are absolute within the image.

Note: At least with the version of sfdisk I have tested with (from
util-linux 2.37.2), the image is not completely identical - there are
one byte differences in the MBR and each MBR. This is because even if
the partition type is set as 0xf, sfdisk produces the extended partition
and all the logical partition with 0x5 type.

Signed-off-by: Jan Čermák <[email protected]>
@michaelolbrich michaelolbrich force-pushed the hdimage-fix-extended-partition-chs branch from 1e4a0a0 to 86d9a34 Compare June 21, 2024 15:07
@michaelolbrich michaelolbrich merged commit df4923c into pengutronix:master Jun 21, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants