gpt
gpt copied to clipboard
Rounding issue of `size` in `add_partition`
The add_partition
method takes the partition size
in bytes as argument. It then divides this size by the block size, which effectively rounds it down to the the next lower block size:
https://github.com/Quyzi/gpt/blob/894899bf756df3427487cff4a744c188d86fb3a0/src/lib.rs#L231-L242
Later, the last_lba
of the partition is then created through first_lba + size_lba - 1
:
https://github.com/Quyzi/gpt/blob/894899bf756df3427487cff4a744c188d86fb3a0/src/lib.rs#L257-L264
So if the given partition size is not aligned to the block size, it is silently rounded down. I would instead expect that it is rounded up, or alternatively an error message.
A side note about the checked_div
usage above: The error message doesn't fit the error cause. The checked_div
call returns None
if a division by zero is attempted, which means that the None
branch is only entered if self.config.lb_size
is zero. From the error message it seems like you wanted to guard against a size < block_size
instead.
Fairly confident this was addressed in #74 as well (https://github.com/Quyzi/gpt/blob/9b6d725106ddd8962a4a8b1bb192455b841a9883/src/lib.rs#L234). Looks to me like it should be fine. Let me know if I'm missing anything!
In case the rounding-down issue had to do with partitions that were one block long, I think I fixed that in #82
Feel free to reopen if this issues isn't resolved