Thomas Schmitt
2014-Jan-23 16:47 UTC
[syslinux] [PATCH] Proposal for a pacifier option with mkdiskimage
Hi, i too played with mkdiskimage in order to get more Linux examples. When i applied it to a real 2 GB stick with write speed 4 MB/s i had enough time to add some pacifier code to the big zeroizer loop. (-s does not prevent zeroizing on block device. Probably because truncate() fails.) My pacifier is combined with what Perl advised me when i tried "fsync(OUTPUT);". Of course this slows down operation on regular files substantially. But otherwise there is on USB sticks a super fast pacifier at the start and a long time of no visible progress at the end. So the pacifier is disabled unless option -S is given. Other than regular files, USB sticks get really synced at the end of the program in exit(0). At least on my Linux 2.6. So syncing them intermediately does not impose an overall time penalty. (And they don't rattle like synced hard disks.) Would this patch have a chance to be accepted ? It is based on http://git.kernel.org/cgit/boot/syslinux/syslinux.git/tree/utils/mkdiskimage.in?id=syslinux-6.03-pre1 ------------------------------------------------------------------- --- mkdiskimage.in 2014-01-23 12:23:34.000000000 +0100 +++ mkdiskimage_ts.in 2014-01-23 17:00:59.000000000 +0100 @@ -145,6 +145,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; } @@ -221,12 +222,23 @@ $tracks = $c*$h; unless ($opt{'s'} && truncate(OUTPUT, $totalsize)) { $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); + print STDERR " $totalsize blocks zeroized. \n"; + } } # Print mtools temp file -------------------------------------------------------------------- Disclaimer: I am not really a Perl programmer. Double disclaimer: I have never prepared a git-ish patch but i would obey instructions. Have a nice day :) Thomas
Ady
2014-Jan-23 17:36 UTC
[syslinux] [PATCH] Proposal for a pacifier option with mkdiskimage
> It is based on > http://git.kernel.org/cgit/boot/syslinux/syslinux.git/tree/utils/mkdiskimage.in?id=syslinux-6.03-pre1Just a thought (FWIW). Perhaps it could be useful to base it on the syslinux4-xx branch: http://git.zytor.com/?p=syslinux/syslinux.git;a=tree;h=refs/heads/sysl inux-4.xx;hb=syslinux-4.xx http://git.zytor.com/?p=syslinux/syslinux.git;a=blob_plain;f=utils/mkd iskimage.in;hb=syslinux-4.xx http://git.zytor.com/?p=syslinux/syslinux.git;a=blob_plain;f=utils/mem diskfind.c;hb=syslinux-4.xx http://git.zytor.com/?p=syslinux/syslinux.git;a=blob;f=utils/mkdiskima ge.in;h=533193a1c301d249a89a63fa81dbf081df0bca6c;hb=syslinux-4.xx http://git.zytor.com/?p=syslinux/syslinux.git;a=blob;f=utils/memdiskfi nd.c;h=815f8bc1c1b1aad6cdb52ef1dd400983fe2a8ee0;hb=syslinux-4.xx Regards, Ady.
Thomas Schmitt
2014-Jan-23 18:01 UTC
[syslinux] [PATCH] Proposal for a pacifier option with mkdiskimage
Hi, Ady wrote:> Perhaps it could be useful to base it on the syslinux4-xx branch: > http://git.zytor.com/?p=syslinux/syslinux.git;a=blob_plain;f=utils/mkdiskimage.in;hb=syslinux-4.xxThe mkdiskimage.in in git.kernel.org/.../syslinux-6.03-pre1 is identical with this. I came to git.kernel.org via http://www.syslinux.org/wiki/index.php/Development#Browse_the_SYSLINUX_source_code Is 4.xx the recommended branch for changes ? (Is there an automated migration path to higher versions ?) Have a nice day :) Thomas
H. Peter Anvin
2014-Jan-27 21:30 UTC
[syslinux] [PATCH] Proposal for a pacifier option with mkdiskimage
On 01/23/2014 08:47 AM, Thomas Schmitt wrote:> Hi, > > i too played with mkdiskimage in order to get more Linux examples. > > When i applied it to a real 2 GB stick with write speed 4 MB/s > i had enough time to add some pacifier code to the big zeroizer > loop. (-s does not prevent zeroizing on block device. Probably > because truncate() fails.) >Yes, we should probably fix that. The tool was originally designed for images, not for hardware devices, and it doesn't make much sense to zero the whole hardware device like that. -hpa
Thomas Schmitt
2014-Jan-28 07:44 UTC
[syslinux] [PATCH] Proposal for a pacifier option with mkdiskimage
Hi, me:> > [mkdiskimage] -s does not prevent zeroizing on block device. Probably > > because truncate() fails.hpa:> Yes, we should probably fix that. The tool was originally designed for > images, not for hardware devices, and it doesn't make much sense to zero > the whole hardware device like that.Maybe for privacy reasons ? But indeed: -s should skip zeroizing, regardless of truncate. Additionally the argument of truncate is currently wrong by a factor of 512: $ mkdiskimage_orig.in -s image.img 250 64 32 $ ls -l image.img -rw-r--r-- 1 xyz xyz 512000 2014-01-28 08:33 image.img How about this ? Tested with USB stick and image file, with and without -s: ------------------------------------------------------------------------- --- mkdiskimage_orig.in 2014-01-23 12:23:34.000000000 +0100 +++ mkdiskimage_with_lower_s.in 2014-01-28 08:25:02.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)) { +# 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 ------------------------------------------------------------------------- One could test for regular file and issue a warning message. But i assume that access problems would already show up when the MBR is written. Is there the risk of 32 bit rollover with "$totalsize * 512" with Perl on 32 bit machines ? (My amd64 can handle -M 6000 255 63.) After my wiki activities i still wonder: Is mkdiskimage supposed to work on NT/2K/XP/DOS systems ? Perl plus MS goes quite beyond my horizon. Have a nice day :) Thomas
Apparently Analagous Threads
- [PATCH 04/05] utils/mkdiskimage.in: New option -S to sync zeroizing after each cylinder and to issue pacifier messages
- [PATCH] Mending proposals for mkdiskimage
- [PATCH 02/05] utils/mkdiskimage.in: With option -s: Avoid zeroizing the partition even if truncate() failed
- [PATCH] Proposal for a pacifier option with mkdiskimage
- [PATCH 1/5] utils/mkdiskimage.in: Option -s caused freshly created image files to be too small by a factor of 512.