wok-6.x rev 18775
syslinux/isohybrid.exe: add -a & -i support
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Jan 01 10:53:50 2016 +0100 (2016-01-01) |
parents | 816d2bd9090b |
children | c46b11485c8b |
files | syslinux/stuff/iso2exe/iso2exe.c syslinux/stuff/iso2exe/iso2exe.sh |
line diff
1.1 --- a/syslinux/stuff/iso2exe/iso2exe.c Fri Jan 01 10:37:57 2016 +0100 1.2 +++ b/syslinux/stuff/iso2exe/iso2exe.c Fri Jan 01 10:53:50 2016 +0100 1.3 @@ -9,11 +9,21 @@ 1.4 #ifdef WIN32 1.5 #include <windows.h> 1.6 #endif 1.7 +#ifdef __MSDOS__ 1.8 +#define ftruncate(a,b) 1.9 +#endif 1.10 +#ifdef __MINGW32__ 1.11 +#define ftruncate chsize 1.12 +#endif 1.13 +#if !defined(__MSDOS__) && !defined(WIN32) 1.14 +#define O_BINARY 0 1.15 +#endif 1.16 typedef unsigned char uint8_t; 1.17 typedef unsigned long uint32_t; 1.18 #include "iso2exe.h" 1.19 1.20 static int fd, forced, uninstall, status = 1; 1.21 +static char *append, *initrd; 1.22 static char tazlitoinfo[0x8000U - BOOTISOSZ]; 1.23 #define buffer tazlitoinfo 1.24 #define BUFFERSZ 2048 1.25 @@ -29,6 +39,12 @@ 1.26 } 1.27 } 1.28 1.29 +static unsigned long getcustomsector(void) 1.30 +{ 1.31 + readsector(16UL); 1.32 + return 16UL + LONG(buffer + 80); 1.33 +} 1.34 + 1.35 static int skipmd5 = 0; 1.36 #define ALIGN1 1.37 1.38 @@ -198,6 +214,12 @@ 1.39 */ 1.40 #define md5_end common64_end 1.41 1.42 +static int writenhash(void *buffer, size_t len) 1.43 +{ 1.44 + md5_hash(buffer, len); 1.45 + return write(fd, buffer, len); 1.46 +} 1.47 + 1.48 static void md5sum(void) 1.49 { 1.50 unsigned long sectors = 0; 1.51 @@ -249,7 +271,7 @@ 1.52 unsigned long size, catalog, lba; 1.53 int cylinders, i, j, isohybrid; 1.54 unsigned n; 1.55 -#ifndef WIN32 1.56 +#ifdef __MSDOS__ 1.57 for (bootiso = (char *) install; 1.58 bootiso[0] != 'M' || bootiso[1] != 'Z' || bootiso[2] != '\xEB'; 1.59 bootiso++) if (bootiso < (char *) install) { 1.60 @@ -266,20 +288,87 @@ 1.61 if (uninstall) { 1.62 struct { char check[sizeof(tazlitoinfo) - BUFFERSZ - 1024]; }; 1.63 readsector(0UL); 1.64 - n = BUFFERSZ; 1.65 + n = BUFFERSZ; /* fill with zeros */ 1.66 if (WORD(buffer) == 23117) { 1.67 + /* restore isolinux hybrid boot */ 1.68 readsector((unsigned long) buffer[417]); 1.69 - n = 0; 1.70 + n = 0; /* fill with hybrid boot */ 1.71 } 1.72 lseek(fd, 0UL, SEEK_SET); 1.73 for (i = 0; i < 32; i++, n = BUFFERSZ) { 1.74 write(fd, buffer + n, 1024); 1.75 } 1.76 + i = getcustomsector(); 1.77 + lseek(fd, i * 2048UL, SEEK_SET); 1.78 + for (;i % 512; i++) { 1.79 + /* clear custom config */ 1.80 + write(fd, buffer + 2048, 2048); 1.81 + } 1.82 + ftruncate(fd, i * 2048UL); 1.83 close(fd); 1.84 status = 0; 1.85 return UNINSTALLMSG; 1.86 } 1.87 1.88 + if (append || initrd) { 1.89 + unsigned long pos = getcustomsector() * 2048UL; 1.90 + lseek(fd, pos, SEEK_SET); 1.91 + write(fd, "#!boot 00000000000000000000000000000000\n", 40); 1.92 + md5_begin(); 1.93 + if (append) { 1.94 + writenhash("append=", 7); 1.95 + writenhash(append, strlen(append)); 1.96 + writenhash("\n", 1); 1.97 + } 1.98 + if (initrd) { 1.99 + char number[16], *p; 1.100 + unsigned long end, x; 1.101 + int data = open(initrd,O_RDONLY|O_BINARY); 1.102 + if (data == -1) 1.103 + return OPENINITRDERR; 1.104 + for (end = 0;; end += i) { 1.105 + i = read(data, buffer, BUFFERSZ); 1.106 + if (i <= 0) 1.107 + break; 1.108 + } 1.109 + p = number + sizeof(number) -1; 1.110 + x = end; *p-- = '\n'; 1.111 + do { 1.112 + *p-- = '0' + (x % 10); 1.113 + x /= 10; 1.114 + } while (x); 1.115 + if (*++p != '0') { 1.116 + writenhash("initrd:", 7); 1.117 + i = number - p + sizeof(number); 1.118 + writenhash(p, i); 1.119 + lseek(data, 0UL, SEEK_SET); 1.120 + do { 1.121 + i = read(data, buffer, BUFFERSZ); 1.122 + if (i <= 0) 1.123 + break; 1.124 + if (i > end) 1.125 + i = end; 1.126 + writenhash(buffer, i); 1.127 + end -= i; 1.128 + } while (end != 0); 1.129 + } 1.130 + close(data); 1.131 + } 1.132 + md5_end(); 1.133 + { 1.134 + static char h[] = "0123456789ABCDEF"; 1.135 + char string[32], *s = string + 30; 1.136 + unsigned char *p = (void *) hash; 1.137 + 1.138 + lseek(fd, 7 + pos, SEEK_SET); 1.139 + for (p += 15; s >= string; p--, s -= 2) { 1.140 + s[1] = h[ *p & 15 ]; 1.141 + s[0] = h[ *p >> 4 ]; 1.142 + } 1.143 + write(fd, string, 32); 1.144 + } 1.145 + } 1.146 + 1.147 if (forced == 0) { 1.148 status = 2; 1.149 /* Install hybridiso boot sector */ 1.150 @@ -354,6 +443,19 @@ 1.151 int main(int argc, char *argv[]) 1.152 { 1.153 int i; 1.154 + char *s; 1.155 + 1.156 + while (argc > 2) { 1.157 + s = argv[1]; 1.158 + if (*s != '-') break; 1.159 + while (*s == '-') s++; 1.160 + switch (*s | 0x20) { 1.161 + case 'a' : append=argv[2]; break; 1.162 + case 'i' : initrd=argv[2]; break; 1.163 + } 1.164 + argv += 2; 1.165 + argc -= 2; 1.166 + } 1.167 for (i = 2; i < argc; i++) { 1.168 char *s = argv[i]; 1.169 while ((unsigned)(*s - '-') <= ('/' - '-')) s++;
2.1 --- a/syslinux/stuff/iso2exe/iso2exe.sh Fri Jan 01 10:37:57 2016 +0100 2.2 +++ b/syslinux/stuff/iso2exe/iso2exe.sh Fri Jan 01 10:53:50 2016 +0100 2.3 @@ -184,7 +184,7 @@ 2.4 2.5 #define $(echo $name | tr '[a-z]' '[A-Z]')SZ $BOOTISOSZ 2.6 2.7 -#ifdef WIN32 2.8 +#ifndef __MSDOS__ 2.9 static char $name[] = { 2.10 /* head */ 2.11 $(hexdump -v -n $HSZ -e '" " 16/1 "0x%02X, "' -e '" // %04.4_ax |" 16/1 "%_p" "| \n"' $DATA | sed 's/ 0x ,/ /g') 2.12 @@ -257,7 +257,7 @@ 2.13 fi 2.14 done <<EOT 2.15 READSECTORERR Read sector failure. 2.16 -USAGE Usage: isohybrid.exe file.iso [--forced|--undo|--quick] 2.17 +USAGE Usage: isohybrid.exe [--append cmdline] [--initrd file] file.iso [--forced|--undo|--quick] 2.18 OPENERR Can't open r/w the iso file. 2.19 ELTORITOERR No EL TORITO SPECIFICATION signature. 2.20 CATALOGERR Invalid boot catalog. 2.21 @@ -266,6 +266,7 @@ 2.22 FORCEMSG You can add --forced to proceed anyway. 2.23 MD5MSG Computing md5sum... 2.24 UNINSTALLMSG Uninstall done. 2.25 +OPENINITRDERR Can't open the initrd file. 2.26 EOT 2.27 done 2.28 rm -rf $DATA