wok diff syslinux/stuff/iso2exe/iso2exe.c @ rev 16022

syslinux/iso2exe: add zimage support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Mar 06 19:57:41 2014 +0000 (2014-03-06)
parents ada914860f33
children 9c889f88b9fd
line diff
     1.1 --- a/syslinux/stuff/iso2exe/iso2exe.c	Tue Apr 02 08:37:23 2013 +0200
     1.2 +++ b/syslinux/stuff/iso2exe/iso2exe.c	Thu Mar 06 19:57:41 2014 +0000
     1.3 @@ -1,27 +1,26 @@
     1.4  #include <sys/types.h>
     1.5  #include <fcntl.h>
     1.6  #include <stdio.h>
     1.7 +#ifdef WIN32
     1.8 +#include <windows.h>
     1.9 +#endif
    1.10  #include "iso2exe.h"
    1.11  
    1.12 -static int fd;
    1.13 +static int fd, status = 1;
    1.14  static char tazlitoinfo[10*1024];
    1.15  #define buffer tazlitoinfo
    1.16  #define BUFFERSZ 2048
    1.17  
    1.18 -static void quit(char *msg)
    1.19 -{
    1.20 -	fprintf(stderr,"%s.\n", msg);
    1.21 -	exit(1);
    1.22 -}
    1.23 -
    1.24  static void readsector(unsigned long sector)
    1.25  {
    1.26  	if (lseek(fd, sector * BUFFERSZ, SEEK_SET) == -1 ||
    1.27 -	    read(fd, buffer, BUFFERSZ) != BUFFERSZ)
    1.28 -		quit("read sector failure");
    1.29 +	    read(fd, buffer, BUFFERSZ) != BUFFERSZ) {
    1.30 +		puts("Read sector failure.\n");
    1.31 +		exit(1);
    1.32 +	}
    1.33  }
    1.34  
    1.35 -int main(int argc, char *argv[])
    1.36 +static char *install(char *filename)
    1.37  {
    1.38  #define heads 64
    1.39  #define sectors 32
    1.40 @@ -32,29 +31,29 @@
    1.41  	unsigned n;
    1.42  #ifndef WIN32
    1.43  	char *bootiso;
    1.44 -	for (bootiso = (char *) main;
    1.45 +	for (bootiso = (char *) install;
    1.46  	     bootiso[0] != 'M' || bootiso[1] != 'Z' || bootiso[2] != 0xEB;
    1.47 -	     bootiso++) if (bootiso < (char *) main) quit("bootiso not found");
    1.48 +	     bootiso++) if (bootiso < (char *) install) return "No bootiso data.\n";
    1.49  #endif
    1.50 -	if (argc < 2)
    1.51 -		quit("Usage : isohybrid.exe file.iso");
    1.52 -	fd = open(argv[1],O_RDWR|O_BINARY);
    1.53 +	if (!filename)
    1.54 +		return "Usage: isohybrid.exe file.iso\n";
    1.55 +	fd = open(filename,O_RDWR|O_BINARY);
    1.56  	if (fd == -1)
    1.57 -		quit("Can't open rw");
    1.58 +		return "Can't open rw the iso file.\n";
    1.59  
    1.60  	// Install hybridiso boot sector
    1.61  	readsector(17UL);
    1.62  	if (strncmp(buffer+7, "EL TORITO SPECIFICATION", 23))
    1.63 -		quit("No EL TORITO boot record found");
    1.64 +		return "No EL TORITO signature.\n";
    1.65  	catalog = * (unsigned long *) (buffer + 71);
    1.66  	readsector(catalog);
    1.67  	if (* (unsigned long *) buffer != 1 || 
    1.68  	    * (unsigned long *) (buffer + 30) != 0x88AA55)
    1.69 -	    	quit("invalid boot catalog.");
    1.70 +	    	return "Invalid boot catalog.\n";
    1.71  	lba = * (unsigned long *) (buffer + 40);
    1.72  	readsector(lba);
    1.73  	if (* (unsigned long *) (buffer + 64) != 1886961915)
    1.74 -		quit("no isolinux.bin hybrid signature in bootloader");
    1.75 +		return "No isolinux.bin hybrid signature.\n";
    1.76  	isohybrid = bootiso[69] * 512;
    1.77  	* (unsigned long *)  &bootiso[isohybrid + 432] = lba * 4;
    1.78  	* (unsigned long *)  &bootiso[isohybrid + 440] = rand();
    1.79 @@ -100,6 +99,16 @@
    1.80  	write(fd, bootiso, 512);
    1.81  nochksum:
    1.82  	close(fd);
    1.83 -	printf("Note you can create a USB key with %s.\n"
    1.84 -	       "Simply rename it to a .exe file and run it.\n", argv[1]);
    1.85 +	status = 0;
    1.86 +	return "Now you can create a USB key with your .iso file.\n"
    1.87 +	       "Simply rename it to a .exe file and run it.\n";
    1.88  }
    1.89 +
    1.90 +int main(int argc, char *argv[])
    1.91 +{
    1.92 +	puts(install(argv[1]));
    1.93 +#ifdef WIN32
    1.94 +	Sleep(2000);
    1.95 +#endif
    1.96 +	return status;
    1.97 +}