- include patch from Tal Benavidor :

this little patch brings a significant speed improvement to
  the bximage utility. when bximage creates a disk image, it writes
  a lot of zeros. actually as much zeros as the size of the image file.
  this takes quite a while for large images (at least in my win98/cygwin box).
  a faster way to create the image file is to seek to its end and write a
  single byte.
  to see the speed improvement, create a 100mb image with the old bximge.
  then apply this patch and do the same.
This commit is contained in:
Christophe Bothamy 2002-05-21 07:23:09 +00:00
parent e92fb8deff
commit d1fbbd6f5c
1 changed files with 25 additions and 17 deletions

View File

@ -1,6 +1,6 @@
/* /*
* misc/bximage.c * misc/bximage.c
* $Id: bximage.c,v 1.6 2001-12-08 17:46:02 bdenney Exp $ * $Id: bximage.c,v 1.7 2002-05-21 07:23:09 cbothamy Exp $
* *
* Create empty hard disk or floppy disk images for bochs. * Create empty hard disk or floppy disk images for bochs.
* *
@ -14,7 +14,7 @@
#include "config.h" #include "config.h"
char *EOF_ERR = "ERROR: End of input"; char *EOF_ERR = "ERROR: End of input";
char *rcsid = "$Id: bximage.c,v 1.6 2001-12-08 17:46:02 bdenney Exp $"; char *rcsid = "$Id: bximage.c,v 1.7 2002-05-21 07:23:09 cbothamy Exp $";
char *divider = "========================================================================"; char *divider = "========================================================================";
/* menu data for choosing floppy/hard disk */ /* menu data for choosing floppy/hard disk */
@ -208,23 +208,31 @@ int make_image (int sec, char *filename)
#endif #endif
fatal ("ERROR: Could not write disk image"); fatal ("ERROR: Could not write disk image");
} }
// clear the buffer
for (i=0; i<512; i++)
buffer[i] = 0;
// write it however many times
printf ("\nWriting: ["); printf ("\nWriting: [");
for (i=0; i<sec; i++) {
n = (unsigned int) fwrite (buffer, 512, 1, fp); /*
if (n != 1) { * seek to sec*512-1 and write a signle character.
printf ("\nWrite failed with %d sectors written\n", i); * can't just do: fseek(fp, 512*sec-1, SEEK_SET)
* because 512*sec may be too large for signed int.
*/
while (sec > 0)
{
/* temp <-- min(sec, 4194303)
* 4194303 is (int)(0x7FFFFFFF/512)
*/
int temp = ((sec < 4194303) ? sec : 4194303);
fseek(fp, 512*temp, SEEK_CUR);
sec -= temp;
}
fseek(fp, -1, SEEK_CUR);
if (fputc('\0', fp) == EOF)
{
fclose (fp); fclose (fp);
fatal ("ERROR: The disk image is not complete!"); fatal ("ERROR: The disk image is not complete!");
} }
if ((i%2048) == 0) {
printf (".");
fflush (stdout);
}
}
printf ("] Done.\n"); printf ("] Done.\n");
fclose (fp); fclose (fp);
return 0; return 0;