wok rev 24279

taziso: rework usbbootkey
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jan 10 14:18:26 2022 +0000 (2022-01-10)
parents 1c472d55ff93
children 00b254b52ef6
files slitaz-boot-scripts/receipt syslinux/stuff/iso2exe/Makefile syslinux/stuff/iso2exe/taziso syslinux/stuff/iso2exe/win32.c
line diff
     1.1 --- a/slitaz-boot-scripts/receipt	Thu Jan 06 11:28:11 2022 +0000
     1.2 +++ b/slitaz-boot-scripts/receipt	Mon Jan 10 14:18:26 2022 +0000
     1.3 @@ -1,7 +1,7 @@
     1.4  # SliTaz package receipt.
     1.5  
     1.6  PACKAGE="slitaz-boot-scripts"
     1.7 -VERSION="471"
     1.8 +VERSION="472"
     1.9  CATEGORY="base-system"
    1.10  SHORT_DESC="Provide all the initialisation scripts used at boot time."
    1.11  MAINTAINER="pankso@slitaz.org"
     2.1 --- a/syslinux/stuff/iso2exe/Makefile	Thu Jan 06 11:28:11 2022 +0000
     2.2 +++ b/syslinux/stuff/iso2exe/Makefile	Mon Jan 10 14:18:26 2022 +0000
     2.3 @@ -43,7 +43,7 @@
     2.4  	i586-pc-mingw32-windres $< -O coff -o $@
     2.5  
     2.6  win32.exe: win32.c win32.res
     2.7 -	i586-pc-mingw32-gcc -Os -s -o $@ $< win32.res -mwindows -lws2_32 && upx --ultra-brute $@
     2.8 +	i586-pc-mingw32-gcc -Os -s -o $@ $< win32.res -mwindows -lws2_32 -lcomctl32 && upx --ultra-brute $@
     2.9  
    2.10  %.o: %.c
    2.11  	$(BCC) $(BCCFLAGS) -A-l -A$*.lst -c -o $@ $<
     3.1 --- a/syslinux/stuff/iso2exe/taziso	Thu Jan 06 11:28:11 2022 +0000
     3.2 +++ b/syslinux/stuff/iso2exe/taziso	Mon Jan 10 14:18:26 2022 +0000
     3.3 @@ -1146,6 +1146,25 @@
     3.4  able to save the package updates or your own configuration and data files.\n\n"
     3.5  }
     3.6  
     3.7 +fixup_gpt()
     3.8 +{
     3.9 +	quads2bin 1 0 $2 0 | ddq bs=1 seek=$((512+24)) of=$1	# my gpt, alt gpt
    3.10 +	quads2bin 0 | ddq bs=1 seek=$((512+88)) of=$device
    3.11 +	quads2bin $(isohybrid --crc32 $1 1024 $(($(get 596 $1 4)*$(get 592 $1 4)))) | \
    3.12 +		ddq bs=1 seek=$((512+88)) of=$1			# CRC32 partitions
    3.13 +	ddn of=$1 if=$1 bs=512 skip=1 seek=$2 count=1
    3.14 +	ddn of=$1 if=$1 bs=512 skip=2 seek=$(($2-1)) count=1
    3.15 +	quads2bin $2 0 1 0 | ddq bs=1 seek=$(($2*512+24)) of=$1	# my gpt, alt gpt
    3.16 +	quads2bin $(($2-1)) 0 | ddq bs=1 seek=$(($2*512+72)) of=$1
    3.17 +	i=$(get 524 $1 4)
    3.18 +	quads2bin 0 | ddq bs=1 seek=$(($2*512+16)) of=$device
    3.19 +	quads2bin $(isohybrid --crc32 $1 $(($2*512)) $i) | \
    3.20 +		ddq bs=1 seek=$(($2*512+16)) of=$1	# CRC32 header
    3.21 +	quads2bin 0 | ddq bs=1 seek=$((512+16)) of=$device
    3.22 +	quads2bin $(isohybrid --crc32 $1 512 $i) | ddq bs=1 seek=$((512+16)) of=$1	# CRC32 header
    3.23 +	partprobe $1
    3.24 +}
    3.25 +
    3.26  usbbootkey()
    3.27  {
    3.28  	if [ -b "$1" ]; then
    3.29 @@ -1177,33 +1196,49 @@
    3.30  	# GPT partition + fat32 format for the remaining space
    3.31  	sectors=$(($(sectcnt $device)-1))
    3.32  	quads2bin $sectors | ddq bs=1 seek=458 of=$device	# pmbr
    3.33 -	quads2bin 0 | ddq bs=1 seek=$((512+16)) of=$device
    3.34  	quads2bin $((sectors-2)) 0 | ddq bs=1 seek=$((512+48)) of=$device
    3.35 -	uudecode - <<EOT | gunzip | ddn bs=128 seek=9 of=$device	# partiton fat32
    3.36 +	uudecode - <<EOT | gunzip | ddn bs=128 seek=9 of=$device	# basic data partiton
    3.37  begin-base64 644 -
    3.38 -H4sIAAAAAAACA1u04MLrpzuNXdoPZGzbrjbz+C/fHwyfEro9Z7E93Fi5/8sH
    3.39 -BhzAiSGRoZghkyGZQYEhBcguAWIFhgIgWQRkZ4JxPkMeAyEAAOuEo7uAAAAA
    3.40 +H4sIAAAAAAACA1u04MLrpzuNXdoPZGzbrjbzOAORwIkhkaGYIZMhmUGBIQXI
    3.41 +LgFiBYYCIFkEZGeCcT5DHkFzAAqvwhqAAAAA
    3.42  ====
    3.43  EOT
    3.44 +	ddq if=/dev/urandom bs=16 count=1 seek=73 of=$device		# partition uuid
    3.45  	last=$(sectcnt "$ISO")
    3.46  	custom=$((4*$(get 32848 $device 4)))
    3.47  	[ $custom -gt $((last-4)) ] && last=$((custom+4))		# room for cmdline
    3.48 -	quads2bin $last 0 | ddq bs=1 seek=$((1024+128+32)) of=$device	# vfat first address
    3.49 -	quads2bin $((sectors-2)) 0 | ddq bs=1 seek=$((1024+128+40)) of=$device	# vfat last address
    3.50 -	quads2bin $(isohybrid --crc32 $device 1024 $(($(get 596 $device 4)*$(get 592 $device 4)))) | \
    3.51 -		ddq bs=1 seek=$((512+88)) of=$device			# CRC32 partitions
    3.52 -	ddn of=$device if=$device bs=512 skip=1 seek=$sectors count=1
    3.53 -	ddn of=$device if=$device bs=512 skip=2 seek=$((sectors-1)) count=1
    3.54 -	quads2bin $sectors 0 1 0 | ddq bs=1 seek=$((sectors*512+24)) of=$device	# my gpt, alt gpt
    3.55 -	quads2bin 1 0 $sectors 0 | ddq bs=1 seek=$((512+24)) of=$device	# my gpt, alt gpt
    3.56 -	quads2bin $((sectors-1)) 0 | ddq bs=1 seek=$((sectors*512+72)) of=$device
    3.57 -	i=$(get 524 $device 4)
    3.58 -	quads2bin $(isohybrid --crc32 $device $((sectors*512)) $i) | \
    3.59 -		ddq bs=1 seek=$((sectors*512+16)) of=$device	# CRC32 header
    3.60 -	quads2bin $(isohybrid --crc32 $device 512 $i) | ddq bs=1 seek=$((512+16)) of=$device	# CRC32 header
    3.61 -	partprobe $device
    3.62 -	homedev=/dev/$(basename /sys/block/${device#/dev/}/${device#/dev/}*2)
    3.63 -	mkdosfs -n 'SLITAZ HOME' $homedev
    3.64 +	quads2bin $last 0 | ddq bs=1 seek=$((1024+128+32)) of=$device	# partition first address
    3.65 +	quads2bin $((sectors-2)) 0 | ddq bs=1 seek=$((1024+128+40)) of=$device	# partition last address
    3.66 +	fixup_gpt $device $sectors
    3.67 +	[ -b ${device}p2 ] && pdev=${device}p2 || pdev=${device}2
    3.68 +	value=$(cat /sys/block/${device#/dev/}/${pdev#/dev/}/size)
    3.69 +	[ ${#value} -gt 7 -a "$(which mkfs.exfat)" ] && value="exfat" || value="fat32"
    3.70 +	if [ -z "$1" ]; then
    3.71 +		echo -n "$DIALOG --clear --title \" Select the filesystem \" \
    3.72 +--radiolist \"\\nPlease select the filesystem type to create.\" 14 70 4" > /tmp/dialog$$
    3.73 +		while read type rem; do
    3.74 +			which mkfs.${type/fat32/vfat} > /dev/null || continue
    3.75 +			echo -n " $type \"$rem" >> /tmp/dialog$$
    3.76 +		done <<EOT
    3.77 +fat32	for a small key"	$([ "$value" = "fat32" ] && echo "on" || echo "off")
    3.78 +exfat	for a large key"	$([ "$value" = "exfat" ] && echo "on" || echo "off")
    3.79 +ntfs	"			off
    3.80 +ext3	for most linux"		off
    3.81 +ext4	"			off
    3.82 +btrfs	for recent linux"	off
    3.83 +xfs
    3.84 +EOT
    3.85 +		exec 3>&1
    3.86 +		value=$(. /tmp/dialog$$ 2>&1 1>&3)
    3.87 +		retval=$?
    3.88 +		exec 3>&-
    3.89 +		rm -f /tmp/dialog$$
    3.90 +	fi
    3.91 +	homedev=/dev/$(basename /sys/block/${device#/dev/}/${pdev#/dev/})
    3.92 +	case "$value" in
    3.93 +	*fat*)	mkfs.${value/fat32/vfat} -n 'SLITAZ HOME' $homedev;;
    3.94 +	*)	mkfs.$value -L 'SLITAZ HOME' $homedev;;
    3.95 +	esac > /dev/null 2>&1
    3.96  
    3.97  	# update boot/exe crc16
    3.98  	words2bin 0 | ddq bs=1 seek=18 of=$device
    3.99 @@ -1211,7 +1246,7 @@
   3.100  	i=$(($(od -v -N $i -t u2 -w2 -An $device | \
   3.101  		awk '{ i+= $0 } END { print (i % 65536) }') \
   3.102  		+ $(get $((i+1)) $device 1)))
   3.103 -	words2bin $(( (-i -1) % 65536 )) | ddq bs=1 seek=18 of=$device
   3.104 +	words2bin $(( (-i -1) & 65535 )) | ddq bs=1 seek=18 of=$device
   3.105  
   3.106  	[ "$1" ] || $DIALOG --clear --title " Set /home persistent " \
   3.107  			--yes-label "Continue" --yesno \
   3.108 @@ -1219,12 +1254,63 @@
   3.109  This option will mount /home on the USB key vfat during the boot process.\n\n
   3.110  Your own data will be saved, but the system stay not upgradable.\n" 16 70
   3.111  	if [ $? -eq 0 ]; then
   3.112 -		data="append=home=$(blkid $homedev | sed 's|.* UUID="||;s|".*||') kmap=$(cat /etc/keymap.conf) lang=${LANG%.UTF*} tz=$(cat /etc/TZ) loadfs"
   3.113 -		cat <<EOT | ddn bs=512 seek=$custom of=$device
   3.114 -#!boot $(echo "$data" | md5sum | sed 's/ .*//')
   3.115 -$data
   3.116 +		echo -en "$(echo "SliTaz persistent /home" | sed 's|.|&\\0|g')" | ddn bs=8 seek=151 of=$device
   3.117 +		fixup_gpt $device $sectors
   3.118 +		[ "$(ddn bs=512 skip=$custom if=$device | ddn bs=1 count=6)" = "#!boot" ] && return
   3.119 +		mkdir /tmp/mnt$$
   3.120 +		mount $pdev /tmp/mnt$$
   3.121 +		echo -e "keyboard\nlocale\ntimezone" > /tmp/dialog.out$$
   3.122 +		touch /tmp/dialog$$
   3.123 +		if [ -z "$1" ]; then
   3.124 +			cat > /tmp/dialog$$ <<EOT
   3.125 +$DIALOG --clear --title " Select configuration " \
   3.126 +	--separate-output \
   3.127 +	--cancel-label "Skip" \
   3.128 +	--checklist "Please select the configuration to store." \
   3.129 +	0 0 0 \
   3.130 +keyboard "kmap=$(cat /etc/keymap.conf)" on \
   3.131 +locale "lang=${LANG%.UTF*}" on \
   3.132 +timezone "tz=$(cat /etc/TZ)" on \
   3.133 +$([ -s /tmp/mnt$$/boot/rootfs.gz ] || cat <<EOM
   3.134 +network "/etc/network.conf" off \
   3.135 +ssh "/etc/dropbear" off \
   3.136 +password "/etc/passwd /etc/*shadow /etc/group" off \
   3.137 +custom "Your own list of files" off
   3.138 +EOM
   3.139 +)
   3.140 +EOT
   3.141 +			sh /tmp/dialog$$ 2> /tmp/dialog.out$$
   3.142 +			[ $? -eq 0 ] || echo -n "" > /tmp/dialog.out$$
   3.143 +		fi
   3.144 +		data=""; files=""
   3.145 +		while read i ; do
   3.146 +			case "$i" in
   3.147 +			keyboard)	data="${data}kmap=$(cat /etc/keymap.conf) ";;
   3.148 +			locale)		data="${data}lang=${LANG%.UTF*} " ;;
   3.149 +			timezone)	data="${data}tz=$(cat /etc/TZ) " ;;
   3.150 +			network)	files="${files} /etc/network.conf" ;;
   3.151 +			ssh)		files="${files} /etc/dropbear" ;;
   3.152 +			password)	files="${files} /etc/passwd /etc/*shadow /etc/group" ;;
   3.153 +			custom) 	exec 3>&1
   3.154 +					custom="$($DIALOG --clear --title " Custom files " \
   3.155 +				--inputbox "\nEnter the list of files to save:\n" 10 70 2>&1 1>&3)"
   3.156 +					retval=$?
   3.157 +					exec 3>&-
   3.158 +					[ $retval -eq 0 ] && files="${files} $custom" ;;
   3.159 +			esac
   3.160 +		done < /tmp/dialog.out$$
   3.161 +		rm -f /tmp/dialog$$ /tmp/dialog.out$$
   3.162 +		[ "$data" ] && cat <<EOT | ddn bs=512 seek=$custom of=$device
   3.163 +#!boot $(echo "append=$data" | md5sum | sed 's/ .*//')
   3.164 +append=$data
   3.165  --
   3.166  EOT
   3.167 +		if [ "$files" ]; then
   3.168 +			mkdir /tmp/mnt$$/boot 2> /dev/null
   3.169 +			find $files | cpio -o -H newc | gzip -9 > /tmp/mnt$$/boot/rootfs.gz
   3.170 +		fi
   3.171 +		umount /tmp/mnt$$
   3.172 +		rm -rf /tmp/mnt$$
   3.173  	fi
   3.174  }
   3.175  
   3.176 @@ -1571,7 +1657,7 @@
   3.177  	keymap="$(cat /etc/keymap.conf 2>/dev/null)"
   3.178  	locale="$(sed '/^LANG=/!d;s/.*=//' /etc/locale.conf 2>/dev/null)"
   3.179  	cat > /tmp/dialog$$ <<EOT
   3.180 -$DIALOG  --clear --title " $(isotitle) " --menu "" 28 70 30 \
   3.181 +$DIALOG  --clear --title " $(isotitle) " --menu "" 0 0 0 \
   3.182  $(initxfile tazkeymap	"tazkeymap"	"Select keyboard (${keymap:-none})") \
   3.183  $(initxfile tazlocale	"tazlocale"	"Select locale (${locale:-none})") \
   3.184  $(initx			"live"		"Linux RAM boot (full desktop)") \
   3.185 @@ -1592,7 +1678,7 @@
   3.186  $(gotposixovlzip	"inst2zip"	"ZIP installation archive (UMSDOS way)") \
   3.187  $(gotposixovlzip	"insttaz2zip"	"ZIP installation archive (TAZUSB way)") \
   3.188  $(gottazusb 		"usbkey"	"USB key read/write installation") \
   3.189 -$(ishybrid		"usbbootkey"	"USB boot key (not upgradable)") \
   3.190 +$(ishybrid		"usbbootkey"	"USB boot key (kernel not upgradable)") \
   3.191  $(hasflavinfo		"showfavinfo"	"Show flavor extra info") \
   3.192  $(hasflavor		"flavor"	"Get flavor file") \
   3.193  $(cdfile isolinux.cfg	"floppyset"	"Boot floppy set") \
     4.1 --- a/syslinux/stuff/iso2exe/win32.c	Thu Jan 06 11:28:11 2022 +0000
     4.2 +++ b/syslinux/stuff/iso2exe/win32.c	Mon Jan 10 14:18:26 2022 +0000
     4.3 @@ -1,9 +1,196 @@
     4.4  #include <windows.h>
     4.5  #include <winnt.h>
     4.6 +#include <winioctl.h>
     4.7 +#include <commctrl.h>
     4.8  #include <sys/types.h>
     4.9  #include <sys/stat.h>
    4.10  #include <fcntl.h>
    4.11  
    4.12 +#define e_grave "\xE8"
    4.13 +#define e_acute "\xE9"
    4.14 +#define e_circ  "\xEA"
    4.15 +#define e_trema "\xEB"
    4.16 +#define E_grave "\xC8"
    4.17 +#define E_acute "\xC9"
    4.18 +#define E_circ  "\xCA"
    4.19 +#define E_trema "\xCB"
    4.20 +#define a_grave "\xE0"
    4.21 +#define A_grave "\xC0"
    4.22 +#define a_circ  "\xE2"
    4.23 +#define A_circ  "\xC2"
    4.24 +#define c_cedil "\xE7"
    4.25 +#define C_cedil "\xC7"
    4.26 +#define i_circ  "\xEE"
    4.27 +#define I_circ  "\xCE"
    4.28 +#define i_trema "\xEF"
    4.29 +#define I_trema "\xCF"
    4.30 +#define o_circ  "\xF4"
    4.31 +#define O_circ  "\xD4"
    4.32 +#define o_trema "\xF6"
    4.33 +#define O_trema "\xD6"
    4.34 +#define u_grave "\xF9"
    4.35 +#define U_grave "\xD9"
    4.36 +#define u_circ  "\xFB"
    4.37 +#define U_circ  "\xDB"
    4.38 +#define u_trema "\xFC"
    4.39 +#define U_trema "\xDC"
    4.40 +
    4.41 +static char *MsgSet[2][27] = {
    4.42 +	{
    4.43 +#define LANG_EN	0
    4.44 +#define MSG_BUILD_KEY	0
    4.45 +		"Build the SliTaz USB key...",
    4.46 +#define MSG_EITHER_CREATE_KEY_OR_BOOT_FLOPPY	1
    4.47 +		"You can either:\n\n"
    4.48 +		"- create a SliTaz USB boot key or a boot memory card.\n"
    4.49 +		"  (note that the Linux kernel will not be upgradable.\n"
    4.50 +		"  The Slitaz utility 'tazusb' can be used later to create\n"
    4.51 +		"  a true read/write USB key).\n\n"
    4.52 +		"- create a SliTaz bootstrap floppy for the ISO image\n"
    4.53 +		"  on the hard disk.\n"
    4.54 +		"\nDo you want to create a boot key now ?",
    4.55 +#define MSG_NOT_DOS_MODE	2
    4.56 +		"This program should run in DOS mode.\n"
    4.57 +		"It can create the file slitaz.pif and launch it,\n"
    4.58 +		"but you can reboot in DOS mode too and run it.\n"
    4.59 +		"\nDo you want to create the slitaz.pif file and execute it now ?",
    4.60 +#define MSG_CRATE_PIF_NOW	3
    4.61 +		"Create slitaz.pif now ?",
    4.62 +#define MSG_NOT_HYBRID		4
    4.63 +		"Not an isolinux hybrid ISO.\n"
    4.64 +		"This ISO image will not boot\n"
    4.65 +		"from the media that you create !",
    4.66 +#define MSG_WILL_NOT_BOOT	5
    4.67 +		"Will not boot !", 
    4.68 +#define MSG_WANT_CREATE_BOOT_KEY	6
    4.69 +		"You can create a SliTaz USB boot key or\n"
    4.70 +		"a boot memory card.\n"
    4.71 +		"\nDo you want to create a boot key now ?",
    4.72 +#define MSG_Q_CREATE_STICK	7
    4.73 +		"Create a boot stick ?",
    4.74 +#define MSG_STEP_1		8
    4.75 +		"Step 1: unplug the USB stick.",
    4.76 +#define MSG_DETECT_1		9
    4.77 +		"Drive detection 1/2",
    4.78 +#define MSG_STEP_2		10
    4.79 +		"Step 2: plug the USB stick in, "
    4.80 +		"wait for Windows to mount it",
    4.81 +#define MSG_DETECT_2		11
    4.82 +		"Drive detection 2/2",
    4.83 +#define MSG_NOT_FOUND		12
    4.84 +		"No USB stick found.",
    4.85 +#define MSG_SORRY		13
    4.86 +		"Sorry",
    4.87 +#define MSG_HD0_UP_TO_DATE	14
    4.88 +		"(hd0) is up to date.",
    4.89 +#define MSG_HD0_UP_TO_DATE_BUT	15
    4.90 +		"(hd0) is up to date but the partition table is not\n"
    4.91 +		"updated because I can't get the total USB stick size\n\n"
    4.92 +		"You can boot SliTaz with this stick and you can update\n"
    4.93 +		"the partition table with 'taziso' by selecting "
    4.94 +		"'usbbootkey' as root.",
    4.95 +#define MSG_NO_REPART		16
    4.96 +		"Finished without repartitioning",
    4.97 +#define MSG_KEEP_CUSTOM_CONF	17
    4.98 +		"Do you want to keep your custom configuration ?",
    4.99 +#define MSG_KEEP_CONF		18
   4.100 +		"keep configuration ?",
   4.101 +#define MSG_WANT_HOME		19
   4.102 +		"Do you want to create a persistent partition for /home ?",
   4.103 +#define MSG_DO_HOME		20
   4.104 +		"Create a persistent /home ?",
   4.105 +#define MSG_FINISHED		21
   4.106 +		"Finished",
   4.107 +#define MSG_WANT_FLOPPY		22
   4.108 +		"Do you want to create a bootstrap floppy ?",
   4.109 +#define MSG_DO_FLOPPY		23
   4.110 +		"Create a bootstrap floppy ?",
   4.111 +#define MSG_INSERT_A_FLOPPY	24
   4.112 +		"Insert a floppy disk in drive now",
   4.113 +#define MSG_INSERT_FLOPPY	25
   4.114 +		"Insert floppy",
   4.115 +#define MSG_FLOPPY_DONE		26
   4.116 +		"The bootstrap floppy is up to date."
   4.117 +	},
   4.118 +	{
   4.119 +#define LANG_FR	1
   4.120 +// MSG_BUILD_KEY
   4.121 +		"Construit la cl" e_acute " USB SliTaz...",
   4.122 +// MSG_EITHER_CREATE_KEY_OR BOOT_FLOPPY
   4.123 +		"Vous pouvez soit :\n\n"
   4.124 +		"- cr" e_acute "er une cl" e_acute " USB ou une carte m" e_acute "moire de d" e_acute "marrage.\n"
   4.125 +		"  (notez que le noyau Linux ne pourra pas " e_circ "tre mis " a_grave " jour.\n" 
   4.126 +		"  L'outil SliTaz 'tazusb' pourra " e_circ "tre utilis" e_acute " ensuite pour cr" e_acute "er\n"
   4.127 +		"  une v" e_acute "ritable cl" e_acute " USB read/write).\n\n"
   4.128 +		"- cr" e_acute "er une disquette de d" e_acute "marrage pour une image ISO\n"
   4.129 +		"  plac" e_acute " sur le disque dur.\n"
   4.130 +		"\nVoulez vous cr" e_acute "er une disquette de d" e_acute "marrage maintenant ?",
   4.131 +// MSG_NOT_DOS_MODE
   4.132 +		"Ce programme devrait " e_circ "tre lanc" e_acute " en mode DOS.\n"
   4.133 +		"Il peut cr" e_acute "er le fichier slitaz.pif et l'ex" e_acute "cuter,\n"
   4.134 +		"mais vous pouvez aussi red" e_acute "marrer en mode DOS et le lancer.\n"
   4.135 +		"\nVoulez cr" e_acute "er le fichier slitaz.pif et le lancer maintenant ?",
   4.136 +// MSG_CRATE_PIF_NOW
   4.137 +		"Cr" e_acute "er slitaz.pif maintenant ?",
   4.138 +// MSG_NOT_HYBRID
   4.139 +		"Ce n'est pas une image ISO hybride isolinux.\n"
   4.140 +		"Cette image ISO ne d" e_acute "marrera pas\n"
   4.141 +		"depuis le media o" u_grave " vous la cr" e_acute "er !",
   4.142 +// MSG_WILL_NOT_BOOT
   4.143 +		"Ne d" e_acute "marrera pas !\n",
   4.144 +// MSG_WANT_CREATE_BOOT_KEY
   4.145 +		"Vous pouvez cr" e_acute "er une cl" e_acute " USB / carte m" e_acute "moire de d" e_acute "marrage.\n"
   4.146 +		"\nVoulez vous cr" e_acute "er une cl" e_acute " de d" e_acute "marrage maintenant ?",
   4.147 +// MSG_Q_CREATE_STICK
   4.148 +		"Cr" e_acute "er une cl" e_acute " de d" e_acute "marrage ?",
   4.149 +// MSG_STEP_1
   4.150 +		"Etape 1 : d" e_acute "branchez la cl" e_acute " USB.",
   4.151 +// MSG_DETECT_1
   4.152 +		"D" e_acute "tection du p" e_acute "riph" e_acute "rique 1/2",
   4.153 +// MSG_STEP_2
   4.154 +		"Etape 2 : rebranchez la cl" e_acute " USB, "
   4.155 +		"et attendez que Windows la reconnaisse.",
   4.156 +// MSG_DETECT_2
   4.157 +		"D" e_acute "tection du p" e_acute "riph" e_acute "rique 2/2",
   4.158 +// MSG_NOT_FOUND
   4.159 +		"Aucune cl" e_acute " USB trouv" e_acute "e.",
   4.160 +// MSG_SORRY
   4.161 +		"D" e_acute " sol" e_acute,
   4.162 +// MSG_HD0_UP_TO_DATE
   4.163 +		"(hd0) a " e_acute "t" e_acute " mis " a_grave " jour.",
   4.164 +// MSG_HD0_UP_TO_DATE_BUT
   4.165 +		"(hd0) a " e_acute "t" e_acute " mis " a_grave " jour mais la table de partition n'est pas\n"
   4.166 +		"modifi" e_acute "e car la taille totale de la cl" e_acute " USB n'a pu " e_circ "tre d" e_acute "tect" e_acute "e\n\n"
   4.167 +		"Vous pouvez d" e_acute "marrer avec cette cl" e_acute " puis vous pouvez mettre " a_grave " jour\n"
   4.168 +		"la table de partition avec 'taziso' en choisissant "
   4.169 +		"'usbbootkey' (si root).",
   4.170 +// MSG_NO_REPART
   4.171 +		"Termin" e_acute " sans repartitionement",
   4.172 +// MSG_KEEP_CUSTOM_CONF
   4.173 +		"Voulez vous conserver votre configuration personnelle ?",
   4.174 +// MSG_KEEP_CONF
   4.175 +		"Garder votre configuration ?",
   4.176 +// MSG_WANT_HOME
   4.177 +		"voulez vous cr" e_acute "er une partition persistante pour /home ?",
   4.178 +// MSG_DO_HOME
   4.179 +		"Cr" e_acute "er un /home persistant ?",
   4.180 +// MSG_FINISHED
   4.181 +		"Termin" e_acute,
   4.182 +// MSG_WANT_FLOPPY
   4.183 +		"Voulez-vous cr" e_acute "er une disquette de d" e_acute "marrage ?",
   4.184 +// MSG_DO_FLOPPY
   4.185 +		"Cr" e_acute "er une disquette de boot ?",
   4.186 +// MSG_INSERT_A_FLOPPY
   4.187 +		"Veuillez ins" e_acute "rer une disquette maintenant",
   4.188 +// MSG_INSERT_FLOPPY
   4.189 +		"Ins" e_acute "rer une disquette",
   4.190 +// MSG_FLOPPY_DONE
   4.191 +		"La disquette de d" e_acute "marage est cr" e_acute e_acute "e."
   4.192 +	}
   4.193 +};
   4.194 +static char **Msg = MsgSet[LANG_EN];
   4.195 +
   4.196 +#define BOOTSTRAP_SECTOR_COUNT_OFFSET	26
   4.197  #define BOOTSTRAP_SECTOR_COUNT_OFFSET	26
   4.198  
   4.199  static int fullread(int fd, char *p, int n)
   4.200 @@ -161,14 +348,14 @@
   4.201  };
   4.202  #pragma pack(pop)
   4.203  
   4.204 -static void exec16bits(char *isoFileName)
   4.205 +static void exec16bits(const char *isoFileName)
   4.206  {
   4.207  	int fd;
   4.208  	const char pifFileName[] = "slitaz.pif";
   4.209  
   4.210  	strcpy(PIF_content.s0.program_filename, isoFileName);
   4.211  	fd = open(pifFileName, O_WRONLY|O_BINARY|O_CREAT|O_TRUNC,0555);
   4.212 -	write(fd,&PIF_content,sizeof(PIF_content));
   4.213 +	write(fd,(void*)&PIF_content,sizeof(PIF_content));
   4.214  	close(fd);
   4.215  	WinExec(pifFileName, SW_MINIMIZE);
   4.216  	exit(0);
   4.217 @@ -183,7 +370,7 @@
   4.218  }
   4.219  
   4.220  #define LONG(x)	* (unsigned long *) (x)
   4.221 -static int ishybrid(char *isoFileName)
   4.222 +static int ishybrid(const char *isoFileName)
   4.223  {
   4.224  	int fdiso;
   4.225  	char buffer[2048];
   4.226 @@ -208,11 +395,69 @@
   4.227  	return (magic == 1886961915);
   4.228  }
   4.229  
   4.230 -static char buffer[512];
   4.231 +static unsigned long crc32(void *buf, int cnt)
   4.232 +{
   4.233 +	static unsigned long t[256] = {
   4.234 +	0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
   4.235 +	0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
   4.236 +	0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
   4.237 +	0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
   4.238 +	0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
   4.239 +	0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
   4.240 +	0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
   4.241 +	0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
   4.242 +	0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
   4.243 +	0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
   4.244 +	0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
   4.245 +	0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
   4.246 +	0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
   4.247 +	0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
   4.248 +	0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
   4.249 +	0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
   4.250 +	0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
   4.251 +	0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
   4.252 +	0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
   4.253 +	0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
   4.254 +	0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
   4.255 +	0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
   4.256 +	0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
   4.257 +	0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
   4.258 +	0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
   4.259 +	0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
   4.260 +	0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
   4.261 +	0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
   4.262 +	0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
   4.263 +	0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
   4.264 +	0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
   4.265 +	0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D };
   4.266 +	unsigned long crc;
   4.267 +	unsigned char *p = buf;
   4.268 +	int i;
   4.269  
   4.270 -#define MODE_READ  0
   4.271 -#define MODE_WRITE 1
   4.272 -static int rdwrsector(int mode, int drive, unsigned long startingsector)
   4.273 +	for (crc=0xFFFFFFFF, i=0; i < cnt; i++) {
   4.274 +		crc=((crc >> 8) ^ t[(crc ^ p[i]) & 255]);
   4.275 +	}
   4.276 +	return crc ^ 0xFFFFFFFF;
   4.277 +}
   4.278 +
   4.279 +static char buffer[2048];
   4.280 +
   4.281 +static int getDrive(unsigned long mask)
   4.282 +{
   4.283 +	int dev;
   4.284 +	if (mask == 0) {
   4.285 +		exit(1);
   4.286 +	}
   4.287 +	for (dev = 128; (mask & 1) == 0; dev++)
   4.288 +		mask >>= 1;
   4.289 +	return dev;
   4.290 +}
   4.291 +
   4.292 +static unsigned long end = 0;
   4.293 +#define MODE_READ	0
   4.294 +#define MODE_WRITE	1
   4.295 +#define MODE_GET_SIZE	2
   4.296 +static int rdwrsector(int mode, int drive, unsigned long startingsector, int bufsiz)
   4.297  {
   4.298  	HANDLE hDevice;
   4.299  	DWORD  result;
   4.300 @@ -230,33 +475,99 @@
   4.301  		FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
   4.302  	if (hDevice == INVALID_HANDLE_VALUE)
   4.303  		return -1;
   4.304 -	SetFilePointer(hDevice, (startingsector*512), NULL, FILE_BEGIN);
   4.305 +
   4.306 +	SetFilePointer(hDevice, (startingsector*bufsiz), NULL, FILE_BEGIN);
   4.307  	if (mode == MODE_READ) {
   4.308 -		if (!ReadFile(hDevice, buffer, 512, &result, NULL))
   4.309 +		if (!ReadFile(hDevice, buffer, bufsiz, &result, NULL))
   4.310 +			result = -1;
   4.311 +	}
   4.312 +	else if (mode == MODE_WRITE) {
   4.313 +		if (!WriteFile(hDevice, buffer, bufsiz, &result, NULL))
   4.314  			result = -1;
   4.315  	}
   4.316  	else {
   4.317 -		if (!WriteFile(hDevice, buffer, 512, &result, NULL))
   4.318 -			result = -1;
   4.319 +		GET_LENGTH_INFORMATION li;
   4.320 +		DWORD rsize;
   4.321 +
   4.322 +		result = -1;
   4.323 +		if (DeviceIoControl(hDevice, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &li, sizeof(li), 
   4.324 +                 		&rsize, NULL) != 0) {
   4.325 +			end = li.Length.QuadPart >> 9;
   4.326 +			result = 0;
   4.327 +		}
   4.328 +		else {
   4.329 +			long i, high;
   4.330 +			high = -1;
   4.331 +			i = GetFileSize(hDevice, &high);
   4.332 +			if (i == INVALID_FILE_SIZE) {
   4.333 +				high = -1;
   4.334 +				i = SetFilePointer(hDevice, 0, &high, FILE_END);
   4.335 +			}
   4.336 +			if (i != INVALID_SET_FILE_POINTER) {
   4.337 +				end = (high << 23)|(i >> 9);
   4.338 +				result = 0;
   4.339 +			}
   4.340 +#if 0
   4.341 +			if (result == -1) {
   4.342 +				LARGE_INTEGER size;
   4.343 +				//if (GetFileSizeEx(hDevice, &size) != 0) {
   4.344 +				if ((*GetProcAddress(GetModuleHandle("kernel32.dll"),
   4.345 +						     "GetFileSizeEx"))(hDevice, &size) != 0) {
   4.346 +					end = (size.QuadPart >> 9);
   4.347 +					result = 0;
   4.348 +				}
   4.349 +			}
   4.350 +#endif
   4.351 +#if 0
   4.352 +			if (result == -1) {
   4.353 +				for (end = 0x40000000, i = (end >> 1); i != 0; i >>= 1) {
   4.354 +					high = (end >> 23);
   4.355 +					if (SetFilePointer(hDevice, end << 9, &high, FILE_BEGIN) == INVALID_SET_FILE_POINTER ||
   4.356 +						!ReadFile(hDevice, buffer, 512, &result, NULL) || result != 512) end -= i;
   4.357 +					else end += i;
   4.358 +				}
   4.359 +				high = (end >> 23);
   4.360 +				if (SetFilePointer(hDevice, end << 9, &high, FILE_BEGIN)
   4.361 +					!= INVALID_SET_FILE_POINTER) end++;
   4.362 +				if (end > startingsector) result = 0;
   4.363 +			}
   4.364 +#endif
   4.365 +		}
   4.366 +	
   4.367  	}
   4.368  	CloseHandle(hDevice);
   4.369  	return result;
   4.370  }
   4.371  
   4.372 -static int rawrite(unsigned long drive, char *isoFileName)
   4.373 +static int rawrite(int dev, char *isoFileName)
   4.374  {
   4.375 -	int fdiso, s, dev;
   4.376 +	int fdiso, s;
   4.377 +	float next;
   4.378 +	off_t size;
   4.379 +	HWND hwndPB;
   4.380  	
   4.381 -	if (drive == 0) return;
   4.382 -	for (dev = 128; (drive & 1) == 0; dev++)
   4.383 -		drive >>= 1;
   4.384  	fdiso = open(isoFileName, O_RDONLY|O_BINARY);
   4.385 -	for (s = 0;; s++) {
   4.386 -		int n = read(fdiso, buffer, sizeof(buffer));
   4.387 +	size = lseek(fdiso,0,SEEK_END);
   4.388 +	lseek(fdiso,0,SEEK_SET);
   4.389 +	if (size != -1) { // https://docs.microsoft.com/en-us/windows/win32/controls/create-progress-bar-controls
   4.390 +		const left=100, right=100+400, bottom=80, scroll=50;
   4.391 +
   4.392 +		InitCommonControls();	// need -lcomctl32
   4.393 +		hwndPB = CreateWindowEx(0, PROGRESS_CLASS, Msg[MSG_BUILD_KEY],
   4.394 +					WS_VISIBLE | PBS_SMOOTH, left,
   4.395 +					bottom - scroll, right, scroll,
   4.396 +					NULL, (HMENU) 0, GetModuleHandle(0), NULL);
   4.397 +		if (hwndPB == NULL) size = -1;
   4.398 +		else SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0, 0xFFFF));
   4.399 +	}
   4.400 +	for (s = 0, next = 0.0;; s++) {
   4.401 +		int n = read(fdiso, buffer, 2048);
   4.402  		if (n <= 0) break;
   4.403 -		rdwrsector(MODE_WRITE, dev, s);
   4.404 +		rdwrsector(MODE_WRITE, dev, s, 2048);
   4.405 +		if (size != -1) SendMessage(hwndPB, PBM_SETPOS, (WPARAM) floor((65536.0*2048.0*s)/size), 0 ); 
   4.406  	}
   4.407  	close(fdiso);
   4.408 +	if (size != -1) DestroyWindow(hwndPB);
   4.409  	return dev;
   4.410  }
   4.411  
   4.412 @@ -265,12 +576,75 @@
   4.413  	int i, mask, result;
   4.414  
   4.415  	for (i = result = 0, mask = 1; i < 8; i++, mask <<= 1) {
   4.416 -		if (rdwrsector(MODE_READ, i+128, 0) != -1)
   4.417 +		if (rdwrsector(MODE_READ, getDrive(i+128), 0, 512) != -1)
   4.418  			result |= mask;
   4.419  	}
   4.420  	return result;
   4.421  }
   4.422  
   4.423 +static int EndOfIso(int dev, unsigned long *endiso,  unsigned long *endcustom)
   4.424 +{
   4.425 +	if (rdwrsector(MODE_READ, dev, 16, 2048) == -1) return -1;
   4.426 +	*endiso = *endcustom = LONG(buffer+80);
   4.427 +	if (rdwrsector(MODE_GET_SIZE, dev, *endiso, 512) == -1) return -1;
   4.428 +	if (rdwrsector(MODE_READ, dev, *endiso, 2048) != -1 && !memcmp(buffer,"#!boot",6)) {
   4.429 +		char *s;
   4.430 +		*endcustom++;
   4.431 +		s = strstr(buffer, "\ninitrd:");
   4.432 +		if (s) {
   4.433 +			long n = strtol(s+8,&s,10);
   4.434 +			n += s - buffer;
   4.435 +			*endcustom += n/2048;
   4.436 +		}
   4.437 +		*endcustom += 511L; *endcustom &= ~511L;
   4.438 +	}
   4.439 +	return 0;
   4.440 +}
   4.441 +
   4.442 +static void AddPartition(int dev, char *label, unsigned long next)
   4.443 +{
   4.444 +	int i;
   4.445 +	unsigned long crc;
   4.446 +
   4.447 +	// https://en.wikipedia.org/wiki/GUID_Partition_Table
   4.448 +	if (rdwrsector(MODE_READ, dev, 2, 512) == -1) return;
   4.449 +	if (buffer[128+56] == 0) {
   4.450 +		static char id[16] = { 0xA2, 0xA0, 0xD0, 0xEB,
   4.451 +			0xE5, 0xB9, 0x33, 0x44, 0x87, 0xC0,
   4.452 +			0x68, 0xB6, 0xB7, 0x26, 0x99, 0xC7 };
   4.453 +		memcpy(buffer + 128, id, 16);
   4.454 +		for (i = 0; i < 16; i += 2)
   4.455 +			* (unsigned short *) (buffer + 128+16 + i) = rand();
   4.456 +		for (i = 56; *label; i += 2)
   4.457 +			buffer[128+i] = *label++;
   4.458 +		LONG(buffer + 128+32) = next * 2048/512;
   4.459 +		LONG(buffer + 128+40) = end - 3;
   4.460 +	}
   4.461 +	rdwrsector(MODE_WRITE, dev, 2, 512);
   4.462 +	rdwrsector(MODE_WRITE, dev, end - 2, 512);
   4.463 +	crc = crc32(buffer, 512L);
   4.464 +	if (rdwrsector(MODE_READ, dev, 1, 512) == -1) return;
   4.465 +	LONG(buffer+88) = crc;
   4.466 +	LONG(buffer+24) = 1;		// Current header
   4.467 +	LONG(buffer+28) = 0;
   4.468 +	LONG(buffer+32) = end - 1;	// Backup header
   4.469 +	LONG(buffer+36) = 0;
   4.470 +	LONG(buffer+48) = end - 3;	// Last usable sector
   4.471 +	LONG(buffer+52) = 0;
   4.472 +	LONG(buffer+16) = 0;
   4.473 +	crc = crc32(buffer, LONG(buffer + 0x0C));
   4.474 +	LONG(buffer+16) = crc;
   4.475 +	rdwrsector(MODE_WRITE, dev, 1, 512);
   4.476 +	LONG(buffer+24) = end - 1;	// Current header
   4.477 +	LONG(buffer+28) = 0;
   4.478 +	LONG(buffer+32) = 1;		// Backup header
   4.479 +	LONG(buffer+36) = 0;
   4.480 +	LONG(buffer+16) = 0;
   4.481 +	crc = crc32(buffer, LONG(buffer + 0x0C));
   4.482 +	LONG(buffer+16) = crc;
   4.483 +	rdwrsector(MODE_WRITE, dev, end - 1, 512);
   4.484 +}
   4.485 +
   4.486  static void writefloppy(char *isoFileName)
   4.487  {
   4.488  	int i, n, fd;
   4.489 @@ -278,7 +652,7 @@
   4.490  	buffer[BOOTSTRAP_SECTOR_COUNT_OFFSET] = 0;
   4.491  	fd = open(isoFileName, O_RDONLY|O_BINARY);
   4.492  	if (fd != -1) {
   4.493 -		read(fd, buffer, sizeof(buffer));
   4.494 +		read(fd, buffer, 512);
   4.495  		n = buffer[BOOTSTRAP_SECTOR_COUNT_OFFSET];
   4.496  		if (n != 0 &&
   4.497  	            lseek(fd, * (unsigned short *) (buffer + 66) - (512 * n),
   4.498 @@ -286,7 +660,7 @@
   4.499  			for (i = 0; i <= n; i++) {
   4.500  				if (i == 1) strncpy(buffer, isoFileName, 512);
   4.501  				else read(fd, buffer, 512);
   4.502 -				rdwrsector(MODE_WRITE, 0, i);
   4.503 +				rdwrsector(MODE_WRITE, 0, i, 512);
   4.504  			}
   4.505  		}
   4.506  		close(fd);
   4.507 @@ -300,33 +674,24 @@
   4.508  	char header[32];
   4.509  	int fd;
   4.510  	int  usbkeyicon = MB_ICONASTERISK;
   4.511 -	char *usbkeymsg = "You can either:\n\n"
   4.512 -		"- create a SliTaz USB boot key or a boot memory card.\n"
   4.513 -		"  (note that this will be read only like a CDROM.\n"
   4.514 -		"  The Slitaz utility 'tazusb' can be used later to create\n"
   4.515 -		"  a true read/write USB key).\n\n"
   4.516 -		"- create a SliTaz bootstrap floppy for the ISO image\n"
   4.517 -		"  on the hard disk.\n"
   4.518 -		"\nDo you want to create a boot key now ?";
   4.519 +	char *usbkeymsg;
   4.520  	
   4.521  	GetModuleFileName(hInstance, isoFileName, MAX_PATH);
   4.522 -	if (!iswinnt()) {
   4.523 -		if (MessageBox(NULL,
   4.524 -			"This program must be run in DOS mode.\n"
   4.525 -			"I can create the file slitaz.pif to launch it,\n"
   4.526 -			"but you can reboot in DOS mode to run it.\n"
   4.527 -			"\nDo you want to create the slitaz.pif file and execute it now ?",
   4.528 -			"Create slitaz.pif now ?",
   4.529 +	if (iswinnt()) {
   4.530 +		LANGID lid = (*GetProcAddress(GetModuleHandle("kernel32.dll"), "GetSystemDefaultUILanguage"))();
   4.531 +		if ((lid & 0xff) == 0x0c) Msg = MsgSet[LANG_FR];
   4.532 +	}
   4.533 +	else {
   4.534 +		struct stat statbuf;
   4.535 +		if (stat("C:\\Mes Documents",&statbuf) != -1) Msg = MsgSet[LANG_FR];
   4.536 +		if (MessageBox(NULL, Msg[MSG_NOT_DOS_MODE], Msg[MSG_CRATE_PIF_NOW],
   4.537  			MB_YESNO|MB_ICONQUESTION) == IDYES) {
   4.538  			exec16bits(isoFileName);
   4.539  		}
   4.540  		exit(1);
   4.541  	}
   4.542  	if (!ishybrid(isoFileName)) {
   4.543 -		if (MessageBox(NULL,"Not an isolinux hybrid ISO.\n"
   4.544 -				    "This ISO image will not boot\n"
   4.545 -				    "from the media that you create !",
   4.546 -			   "Will not boot !", 
   4.547 +		if (MessageBox(NULL, Msg[MSG_NOT_HYBRID], Msg[MSG_WILL_NOT_BOOT],
   4.548  			   MB_OKCANCEL|MB_ICONWARNING) == IDCANCEL)
   4.549  			exit(0);
   4.550  	}
   4.551 @@ -336,30 +701,21 @@
   4.552  		read(fd, header, sizeof(header));
   4.553  		close(fd);
   4.554  	}
   4.555 +	usbkeymsg = Msg[MSG_EITHER_CREATE_KEY_OR_BOOT_FLOPPY];
   4.556  	if (header[BOOTSTRAP_SECTOR_COUNT_OFFSET] == 0) { // No floppy bootstrap available
   4.557  		usbkeyicon = MB_ICONQUESTION;
   4.558 -		usbkeymsg =
   4.559 -		"You can create a SliTaz USB boot key or\n"
   4.560 -		"a boot memory card.\n"
   4.561 -		"(note that this will be read only like\n"
   4.562 -		"a CDROM. The Slitaz utility 'tazusb'\n"
   4.563 -		"can be used later to create a true\n"
   4.564 -		"read/write USB key).\n"
   4.565 -		"\nDo you want to create a boot key now ?";
   4.566 +		usbkeymsg = Msg[MSG_WANT_CREATE_BOOT_KEY];
   4.567  	}
   4.568 -	if (MessageBox(NULL,usbkeymsg, "Create a boot stick ?",
   4.569 +	if (MessageBox(NULL,usbkeymsg, Msg[MSG_Q_CREATE_STICK],
   4.570  			MB_YESNO|usbkeyicon) == IDYES) {
   4.571  		unsigned long base, new;
   4.572  		int retry;
   4.573  		
   4.574 -		if (MessageBox(NULL,"Step 1: unplug the USB stick.",
   4.575 -				"Drive detection 1/2",
   4.576 +		if (MessageBox(NULL, Msg[MSG_STEP_1], Msg[MSG_DETECT_1],
   4.577  				MB_OKCANCEL|MB_ICONEXCLAMATION) == IDCANCEL)
   4.578  			exit(0);
   4.579  		base = drives();
   4.580 -		if (MessageBox(NULL,"Step 2: plug the USB stick in, "
   4.581 -				    "wait for Windows to mount it",
   4.582 -				"Drive detection 2/2",
   4.583 +		if (MessageBox(NULL, Msg[MSG_STEP_2], Msg[MSG_DETECT_2],
   4.584  				MB_OKCANCEL|MB_ICONEXCLAMATION) == IDCANCEL)
   4.585  			exit(0);
   4.586  		retry = 0;
   4.587 @@ -368,27 +724,40 @@
   4.588  			new = drives();
   4.589  		} while (new == base && retry++ < 10);
   4.590  		if (new == base) {
   4.591 -			MessageBox(NULL,"No USB stick found.","Sorry",
   4.592 +			MessageBox(NULL, Msg[MSG_NOT_FOUND], Msg[MSG_SORRY],
   4.593  				   MB_OK|MB_ICONERROR);
   4.594  		}
   4.595  		else {
   4.596 -			char *msg = "(hd0) is up to date.";
   4.597 -			msg[3] += rawrite(base ^ new, isoFileName) - 128;
   4.598 -			MessageBox(NULL,msg,"Finished",MB_OK);
   4.599 +			unsigned long endiso, endcustom;
   4.600 +			char *msg = Msg[MSG_HD0_UP_TO_DATE];
   4.601 +			int drive = getDrive(base ^ new);
   4.602 +			msg[3] += rawrite(drive, isoFileName) - 128;
   4.603 +			if (EndOfIso(drive, &endiso, &endcustom) == -1) {
   4.604 +				char *msg2 = Msg[MSG_HD0_UP_TO_DATE_BUT];
   4.605 +				msg2[3] = msg[3];
   4.606 +				MessageBox(NULL,msg2, Msg[MSG_NO_REPART] ,MB_OK|MB_ICONEXCLAMATION);
   4.607 +			}
   4.608 +			else {
   4.609 +				static char *labels[2] = { "Basic data partition", "SliTaz persistent /home" };
   4.610 +				if (endiso != endcustom && MessageBox(NULL, Msg[MSG_KEEP_CUSTOM_CONF],
   4.611 +						Msg[MSG_KEEP_CONF], MB_YESNO|MB_ICONQUESTION) == IDYES)
   4.612 +					endiso = endcustom;
   4.613 +				AddPartition(drive, labels[MessageBox(NULL, Msg[MSG_WANT_HOME],
   4.614 +					Msg[MSG_DO_HOME], MB_YESNO|MB_ICONQUESTION) == IDYES], endiso); 
   4.615 +				MessageBox(NULL,msg, Msg[MSG_FINISHED], MB_OK);
   4.616 +			}
   4.617  		}
   4.618  	}
   4.619  	else if (header[BOOTSTRAP_SECTOR_COUNT_OFFSET] != 0 &&
   4.620 -	    MessageBox(NULL,"Do you want to create a bootstrap floppy ?",
   4.621 -			    "Create a bootstrap floppy ?",
   4.622 +	    MessageBox(NULL, Msg[MSG_WANT_FLOPPY], Msg[MSG_DO_FLOPPY],
   4.623  			MB_YESNO|MB_ICONQUESTION) == IDYES &&
   4.624 -	    MessageBox(NULL,"Insert a floppy disk in drive now",
   4.625 -			    "Insert floppy",
   4.626 +	    MessageBox(NULL, Msg[MSG_INSERT_A_FLOPPY], Msg[MSG_INSERT_FLOPPY],
   4.627  			MB_OKCANCEL|MB_ICONEXCLAMATION) != IDCANCEL) {
   4.628  
   4.629 -		// Create a 9k bootstrap with vfat, ext2 & ntfs drivers
   4.630 +		// Create a 9k bootstrap with vfat, exfat, ntfs, ext2 & usb drivers
   4.631  		// to boot the ISO image on hard disk
   4.632  		writefloppy(isoFileName);
   4.633 -		MessageBox(NULL,"The bootstrap floppy is up to date.",
   4.634 -				"Finished",MB_OK);
   4.635 +		MessageBox(NULL, Msg[MSG_FLOPPY_DONE],
   4.636 +			Msg[MSG_FINISHED], MB_OK);
   4.637  	}
   4.638  }