disk images: fix some corner-cases in MBR calculation#318
disk images: fix some corner-cases in MBR calculation#318nrclark wants to merge 1 commit intopengutronix:masterfrom
Conversation
Fix some corner-cases with CHS calculation when filling out MBR partition tables. Make sure that CHS values are correctly clamped the requested LBA is too big to be representable as a CHS, and fix the calculation when LBA=0. When creating a hybrid GPT/MBR, change the GPT protective partition size from (hd->gpt_location / 512 + GPT_SECTORS - 2) to GPT_SECTORS, which is more generally correct (and evaluates to the same value in the hybrid case). Signed-off-by: Nicholas Clark <nicholas.clark@gmail.com>
|
@michaelolbrich some context on this: I'm working on a PR that will add support for 4kB block sizes (or 2^N, (N>=9) more generally). While doing that work, I came across a couple of smaller items that I also wanted to fix. I thought that it would make sense to split them out from my other branch, so that they can be evaluated separately. The change to
Feel free to take or close this PR as you see fit, since I'd be especially grateful if you could check out the change to |
| entry->partition_type = 0xee; | ||
| entry->relative_sectors = 1; | ||
| entry->total_sectors = hd->gpt_location / 512 + GPT_SECTORS - 2; | ||
| entry->total_sectors = GPT_SECTORS; |
There was a problem hiding this comment.
gpt_location is configurable. It doesn't have start at LBA2. We specifically use this on some i.MX SoCs where the
ROM expects a i.MX specific boot header at LBA2, so we move the gpt partition entries somewhere else using gpt_location.
|
|
||
| chs[0] = head & 0xFF; | ||
| chs[1] = (sector & 0x3F) + ((cylinder & 0x300) >> 2); | ||
| chs[2] = cylinder & 0xFF; |
There was a problem hiding this comment.
This might be better readable if you moved the variable renaming to a separate patch so the actual changes in functionality are better visible
Fix some corner-cases with CHS calculation when filling out MBR partition tables. Make sure that CHS values are correctly clamped the requested LBA is too big to be representable as a CHS, and fix the calculation when LBA=0.
When creating a hybrid GPT/MBR, change the GPT protective partition size from (
hd->gpt_location / 512 + GPT_SECTORS - 2) toGPT_SECTORS, which should be more generally correct (and evaluates to the same value in the hybrid case).