Thomas Schmitt
2014-Jan-30 20:59 UTC
[syslinux] [PATCH 02/05] utils/mkdiskimage.in: With option -s: Avoid zeroizing the partition even if truncate() failed
utils/mkdiskimage.in: With option -s: Avoid zeroizing the partition even if truncate() failed. --- utils/mkdiskimage_patched_01.in 2014-01-30 20:43:02.000000000 +0100 +++ utils/mkdiskimage.in 2014-01-30 20:45:09.000000000 +0100 @@ -217,8 +217,11 @@ print OUTPUT "\x55\xaa"; $totalsize = $c*$h*$s; $tracks = $c*$h; -# If -s is given, try to simply use truncate... -unless ($opt{'s'} && truncate(OUTPUT, $totalsize * 512)) { +# 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); +} else { $track = "\0" x (512*$s); # Print fractional track
Thomas Schmitt
2014-Jan-30 21:00 UTC
[syslinux] [PATCH 03/05] utils/mkdiskimage.in: Replaced the partly linux-specific file size determination by a sysseek() experiment
utils/mkdiskimage.in: Replaced the partly linux-specific file size determination by a sysseek() experiment. --- utils/mkdiskimage_patched_02.in 2014-01-30 20:49:46.000000000 +0100 +++ utils/mkdiskimage.in 2014-01-30 20:50:59.000000000 +0100 @@ -19,6 +19,7 @@ use bytes; use integer; use Fcntl; +use Fcntl qw(:seek); use Errno; use Cwd; use IO::Handle; # For flush() @@ -116,15 +117,8 @@ if ( $c == 0 && $file ne '' ) { $len = 0; if ( sysopen(OUTPUT, $file, O_RDWR, 0666) ) { $is_open = 1; - - if ( (@filestat = stat(OUTPUT)) && S_ISREG($filestat[2]) ) { - $len = $filestat[7] >> 9; - } elsif ( $is_linux && S_ISBLK($filestat[2]) ) { - $blksize = pack("L!", 0); - if ( ioctl(OUTPUT, $BLKGETSIZE, $blksize) == 0 ) { - $len = unpack("L!", $blksize); # In 512-byte sectors! - } - } + $len = sysseek(OUTPUT, 0, SEEK_END) >> 9; + sysseek(OUTPUT, 0, SEEK_SET); } if ( !$len ) {
Thomas Schmitt
2014-Jan-30 21:01 UTC
[syslinux] [PATCH 04/05] utils/mkdiskimage.in: New option -S to sync zeroizing after each cylinder and to issue pacifier messages
utils/mkdiskimage.in: New option -S to sync zeroizing after each cylinder and to issue pacifier messages. --- utils/mkdiskimage_patched_03.in 2014-01-30 20:54:27.000000000 +0100 +++ utils/mkdiskimage.in 2014-01-30 20:59:19.000000000 +0100 @@ -139,6 +139,7 @@ if ( $file eq '' || $c < 1 || $h < 1 || print STDERR " -4 use partition entry 4 (standard for zipdisks)\n"; print STDERR " -i specify the MBR ID\n"; print STDERR " -s output a sparse file (don't allocate all blocks)\n"; + print STDERR " -S sync after each zeroized cylinder and show count\n"; exit 1; } @@ -218,12 +219,24 @@ if ($opt{'s'}) { } else { $track = "\0" x (512*$s); + $show_pacifier = $opt{'S'}; + # Print fractional track print OUTPUT "\0" x (512 * ($s-1)); for ( $i = 1 ; $i < $tracks ; $i++ ) { + if ( $show_pacifier && ( $i - 1 ) % $h == 0 ) { + $cyl_to_write = ( $i - 1 ) / $h + 1; + IO::Handle::sync(OUTPUT); + print STDERR " zeroizing cylinder $cyl_to_write of $c\r"; + } print OUTPUT $track; } + if ( $show_pacifier ) { + IO::Handle::sync(OUTPUT); + $zeroized = $totalsize + $zero_tail - 1; + print STDERR " $zeroized blocks zeroized. \n"; + } } # Print mtools temp file
Apparently Analagous Threads
- [PATCH] Mending proposals for mkdiskimage
- [PATCH 02/05] utils/mkdiskimage.in: With option -s: Avoid zeroizing the partition even if truncate() failed
- [PATCH 1/5] utils/mkdiskimage.in: Option -s caused freshly created image files to be too small by a factor of 512.
- [PATCH 00/05] Mending for mkdiskimage
- [PATCH 00/05] Mending for mkdiskimage