Fix a bug in disklabel enlarge code
authorNikos Skalkotos <skalkoto@grnet.gr>
Thu, 30 Jan 2014 11:53:10 +0000 (13:53 +0200)
committerNikos Skalkotos <skalkoto@grnet.gr>
Thu, 30 Jan 2014 11:53:10 +0000 (13:53 +0200)
If the disk size is greater that 8G then the CHS value of the MBR
will overflow. We should assign a fixed CHS value for this case.

snf-image-helper/disklabel.py

index f119192..527d01c 100755 (executable)
@@ -94,8 +94,15 @@ class MBR(object):
             """Packs a CHS tuple to an address string."""
 
             assert 1 <= sector <= 63
-            assert 0 <= cylinder <= 1023
             assert 0 <= head <= 255
+            assert 0 <= cylinder
+
+            # If the cylinders overflow then put the value (1023, 254, 63) to
+            # the tuple. At least this is what OpenBSD does.
+            if cylinder > 1023:
+                cylinder = 1023
+                head = 254
+                sector = 63
 
             byte0 = head
             byte1 = (cylinder >> 2) & 0xC0 | sector