[syslinux] [PATCH 5/5] utils/mkdiskimage.in: Without option -s: Zeroize past-partition space if it is known by c == 0 or option -M.

Thomas Schmitt scdbackup at gmx.net
Thu Jul 10 12:21:26 PDT 2014


---
 utils/mkdiskimage.in | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/utils/mkdiskimage.in b/utils/mkdiskimage.in
index 9d4e887..adc73bb 100644
--- a/utils/mkdiskimage.in
+++ b/utils/mkdiskimage.in
@@ -95,6 +95,7 @@ while (defined($a = shift(@ARGV))) {
 
 ($file,$c,$h,$s) = @args;
 $c += 0;  $h += 0;  $s += 0;
+$zero_tail = 0;
 
 $pentry = 1;
 $pentry = 2 if ( $opt{'2'} );
@@ -108,7 +109,9 @@ if ( $opt{'z'} ) {
 
 if ( $opt{'M'} && $h && $s ) {
     # Specify size in megabytes, not in cylinders
+    $mb = $c;
     $c = ($c*1024*2)/($h*$s);
+    $zero_tail = ($mb * 1024 * 2 - $c * $h * $s);
 }
 
 $is_open = 0;
@@ -127,6 +130,7 @@ if ( $c == 0 && $file ne '' ) {
     }
 
     $c = $len/($h*$s);
+    $zero_tail = ($len - $c * $h * $s);
 }
 
 if ( $file eq '' || $c < 1 || $h < 1 || $h > 256 || $s < 1 || $s > 63 ) {
@@ -215,7 +219,7 @@ $tracks    = $c*$h;
 # If -s is given, simply use truncate. Do not care for success. Failure is
 # normal with Linux block devices.
 if ($opt{'s'}) {
-    truncate(OUTPUT, $totalsize * 512);
+    truncate(OUTPUT, ($totalsize + $zero_tail) * 512);
 } else {
     $track = "\0" x (512*$s);
 
@@ -232,6 +236,16 @@ if ($opt{'s'}) {
 	}
 	print OUTPUT $track;
     }
+    if ( $zero_tail > 0 ) {
+	if ( $show_pacifier ) {
+	    IO::Handle::sync(OUTPUT);
+	    print STDERR " zeroizing $zero_tail unclaimed blocks\r";
+	}
+	$block = "\0" x 512;
+	for ( $i = 0 ; $i < $zero_tail ; $i++ ) {
+	    print OUTPUT $block;
+	}
+    } 
     if ( $show_pacifier ) {
 	IO::Handle::sync(OUTPUT);
 	$zeroized = $totalsize + $zero_tail - 1;
-- 
2.0.0



More information about the Syslinux mailing list