Exception with disks with many cylinders

May 12, 2010 at 7:17 AM

Hey,

when a partition with to many cylinders is to be created, I get an exception that the first sector needs to be before the last.
This is due to an integer overflow in the LBA calculation in ToLogicalBlockAddress. In this case the return value of the
last sector is negativ so before the first sector.

long size = (long)1300 * 1024 * 1024 * 1024;
using (VirtualDisk d = VirtualDisk.CreateDisk("VHD", "DYNAMIC", @"C:\Temp.vhd", size, null, new Dictionary<string, string>()))
{
    BiosPartitionTable pt = BiosPartitionTable.Initialize(d);

    // exception occurs here
    int i = pt.CreatePrimaryByCylinder(0, 150000, (byte)WellKnownPartitionType.WindowsNtfs, true);
}

Converting the return of Geometry.ToLogicalBlockAddress from int to long and all corresponding integers fixes this.
Patch: http://thilo.cestona.ro/public/trunk_rev522.patch.gz

Ciao Ephraim

Coordinator
May 29, 2010 at 7:45 AM

Thanks for reporting - I've uploaded the fix.

Cheers,

Ken