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.
May 29, 2010 at 7:45 AM
Thanks for reporting - I've uploaded the fix.