Repository navigation
image-hd: fix endianness of MBR and EBR partition entries on big-endian hosts - #347
pranavkaruvally wants to merge 2 commits into
Conversation
|
Hi @michaelolbrich |
giritrivedi
left a comment
There was a problem hiding this comment.
Check other code paths that read relative_sectors/total_sectors from an in-memory MBR struct that originated from disk.
|
|
||
| memset(&mbr, 0, sizeof(mbr)); | ||
| memcpy(&mbr.disk_signature, &hd->disksig, sizeof(hd->disksig)); | ||
| uint32_t tmp_disksig = htole32(hd->disksig); |
There was a problem hiding this comment.
sizeof(hd->disksig) lets memcpy know how many bytes to copy.
No endianness conversion is needed.
There was a problem hiding this comment.
hd->disksig is also being used as the source argument in that memcpy. Without the endianness conversion, this will lead to failure in big endian machines as the MBR entries are supposed to be in little-endian format.
| lba_to_chs(le32toh(entry->relative_sectors) + offset_sectors, | ||
| entry->first_chs); | ||
| lba_to_chs(entry->relative_sectors + entry->total_sectors - 1 + offset_sectors, | ||
| lba_to_chs(le32toh(entry->relative_sectors) + le32toh(entry->total_sectors) - 1 + offset_sectors, |
There was a problem hiding this comment.
le32toh is called on entry->relative_sectors twice in two separate expressions. Looks to be slightly wasteful and inconsistent, instead use a local variable
There was a problem hiding this comment.
Actually, I would expect the compiler to optimize this anyway. And I don't think another variable will make the code cleaner in this case.
So I don't mind either way.
| entry->partition_type = 0xee; | ||
| entry->relative_sectors = 1; | ||
| entry->total_sectors = hd->gpt_location / 512 + GPT_SECTORS - 2; | ||
| entry->relative_sectors = htole32(1); |
There was a problem hiding this comment.
This is not needed. htole32(1) is 1 on all platforms.
There was a problem hiding this comment.
htole32(1) is not 1 on big endian platforms
There was a problem hiding this comment.
The point i wanted to make was, we need to keep the constant 1 as is on all platforms so that relative_sectors will remain 1 on all platforms.
With htole32(1) relative_sectors will have some other values stored in it.
There was a problem hiding this comment.
htole32(1) is correct here.
960eb35 to
ec5d1fd
Compare
|
Hi @sudipm-mukherjee Thanks |
michaelolbrich
left a comment
There was a problem hiding this comment.
Looks mostly good. Take a look at the failing test. It's a formatting issue.
And we really need a CI check for this. Maybe an action that builds and runs the whole thing in an x390 qemu? It would be fine if some of the tests fail for now, but I want to see it if we break things.
| lba_to_chs(le32toh(entry->relative_sectors) + offset_sectors, | ||
| entry->first_chs); | ||
| lba_to_chs(entry->relative_sectors + entry->total_sectors - 1 + offset_sectors, | ||
| lba_to_chs(le32toh(entry->relative_sectors) + le32toh(entry->total_sectors) - 1 + offset_sectors, |
There was a problem hiding this comment.
Actually, I would expect the compiler to optimize this anyway. And I don't think another variable will make the code cleaner in this case.
So I don't mind either way.
| entry->partition_type = 0xee; | ||
| entry->relative_sectors = 1; | ||
| entry->total_sectors = hd->gpt_location / 512 + GPT_SECTORS - 2; | ||
| entry->relative_sectors = htole32(1); |
There was a problem hiding this comment.
htole32(1) is correct here.
…an hosts Signed-off-by: Pranav P <pranavsdreams@gmail.com>
ec5d1fd to
24b3862
Compare
|
Thanks for the reviews @michaelolbrich |
Write MBR/EBR partition entries in little-endian byte order. It was being written in native byteorder in big endian machines.
Fixes s390x in #335
Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1149583