wrong disk size resulting from off-by-one error in cylinder count detection via INT13,48
The disk size in LBA mode returned by FDISK is higher than the expected correct value leading to partitions exceeding the disk size.
My educated guess on what is happening:
The value stored in total_cylinders when using INT13,8 is not the total cylinder count but the highest possible cylinder number starting at 0. https://gitlab.com/FreeDOS/base/fdisk/-/blob/master/SOURCE/FDISK/FDISK/PDISKIO.C#L496
So the actual total cylinder count is total_cylinders+1, an expression which is used in many places in the source when doing calculations.
However that is not respected when working in LBA mode, because the value stored in total_cylinders in this situation is the REAL total cylinder count. The value should therefore be subtracted by -1. See the expression in: https://gitlab.com/FreeDOS/base/fdisk/-/blob/master/SOURCE/FDISK/FDISK/PDISKIO.C#L548
The correct calculation should be:
total_hs = total_sectors * (total_heads+1);
total_cylinders = number_of_physical_sectors / total_hs - 1;
After implementing some source changes the values returned are in sync with the values returned by other tools and the correct disk size is displayed. I may provide a merge request for this bug along with the fixes for #6 (closed)