mirror of
				https://github.com/pbatard/rufus.git
				synced 2024-08-14 23:57:05 +00:00 
			
		
		
		
	[core] add and use WriteFileWithRetry() where possible
This commit is contained in:
		
							parent
							
								
									2430c66a68
								
							
						
					
					
						commit
						f2a539a48c
					
				
					 11 changed files with 123 additions and 109 deletions
				
			
		
							
								
								
									
										12
									
								
								src/dos.c
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								src/dos.c
									
										
									
									
									
								
							|  | @ -2,8 +2,8 @@ | ||||||
|  * Rufus: The Reliable USB Formatting Utility |  * Rufus: The Reliable USB Formatting Utility | ||||||
|  * DOS boot file extraction, from the FAT12 floppy image in diskcopy.dll |  * DOS boot file extraction, from the FAT12 floppy image in diskcopy.dll | ||||||
|  * (MS WinME DOS) or from the embedded FreeDOS resource files |  * (MS WinME DOS) or from the embedded FreeDOS resource files | ||||||
|  * Copyright © 2011-2015 Pete Batard <pete@akeo.ie> |  * Copyright © 2011-2016 Pete Batard <pete@akeo.ie> | ||||||
|  *  |  * | ||||||
|  * This program is free software: you can redistribute it and/or modify |  * This program is free software: you can redistribute it and/or modify | ||||||
|  * it under the terms of the GNU General Public License as published by |  * it under the terms of the GNU General Public License as published by | ||||||
|  * the Free Software Foundation, either version 3 of the License, or |  * the Free Software Foundation, either version 3 of the License, or | ||||||
|  | @ -257,8 +257,8 @@ static BOOL ExtractFAT(int entry, const char* path) | ||||||
| 		return FALSE; | 		return FALSE; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if ((!WriteFile(hFile, &DiskImage[filestart], (DWORD)filesize, &Size, 0)) || (filesize != Size)) { | 	if (!WriteFileWithRetry(hFile, &DiskImage[filestart], (DWORD)filesize, &Size, WRITE_RETRIES)) { | ||||||
| 		uprintf("Couldn't write file '%s': %s.\n", filename, WindowsErrorString()); | 		uprintf("Could not write file '%s': %s.\n", filename, WindowsErrorString()); | ||||||
| 		safe_closehandle(hFile); | 		safe_closehandle(hFile); | ||||||
| 		return FALSE; | 		return FALSE; | ||||||
| 	} | 	} | ||||||
|  | @ -394,8 +394,8 @@ BOOL ExtractFreeDOS(const char* path) | ||||||
| 			return FALSE; | 			return FALSE; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if ((!WriteFile(hFile, res_data, res_size, &Size, 0)) || (res_size != Size)) { | 		if (!WriteFileWithRetry(hFile, res_data, res_size, &Size, WRITE_RETRIES)) { | ||||||
| 			uprintf("Couldn't write file '%s': %s.\n", filename, WindowsErrorString()); | 			uprintf("Could not write file '%s': %s.\n", filename, WindowsErrorString()); | ||||||
| 			safe_closehandle(hFile); | 			safe_closehandle(hFile); | ||||||
| 			return FALSE; | 			return FALSE; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/drive.c
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/drive.c
									
										
									
									
									
								
							|  | @ -1065,7 +1065,7 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m | ||||||
| 			bufsize = 65536;	// 64K should be enough for everyone
 | 			bufsize = 65536;	// 64K should be enough for everyone
 | ||||||
| 			buffer = calloc(bufsize, 1); | 			buffer = calloc(bufsize, 1); | ||||||
| 			if (buffer != NULL) { | 			if (buffer != NULL) { | ||||||
| 				if ((!WriteFile(hDrive, buffer, bufsize, &size, NULL)) || (size != bufsize)) | 				if (!WriteFileWithRetry(hDrive, buffer, bufsize, &size, WRITE_RETRIES)) | ||||||
| 					uprintf("  Could not zero MSR: %s", WindowsErrorString()); | 					uprintf("  Could not zero MSR: %s", WindowsErrorString()); | ||||||
| 				free(buffer); | 				free(buffer); | ||||||
| 			} | 			} | ||||||
|  | @ -1165,12 +1165,8 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m | ||||||
| 				uprintf("Could not access uefi-ntfs.img"); | 				uprintf("Could not access uefi-ntfs.img"); | ||||||
| 				return FALSE; | 				return FALSE; | ||||||
| 			} | 			} | ||||||
| 			r = WriteFile(hDrive, buffer, bufsize, &size, NULL); | 			if(!WriteFileWithRetry(hDrive, buffer, bufsize, &size, WRITE_RETRIES)) { | ||||||
| 			if ((!r) || (size != bufsize)) { | 				uprintf("Write error: %s", WindowsErrorString()); | ||||||
| 				if (!r) |  | ||||||
| 					uprintf("Write error: %s", WindowsErrorString()); |  | ||||||
| 				else |  | ||||||
| 					uprintf("Write error: Wrote %d bytes, expected %d bytes\n", size, bufsize); |  | ||||||
| 				return FALSE; | 				return FALSE; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -1251,7 +1251,7 @@ static BOOL SetupWinPE(char drive_letter) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if ((!WriteFile(handle, buf, size, &rw_size, NULL)) || (size != rw_size)) { | 	if (!WriteFileWithRetry(handle, buf, size, &rw_size, WRITE_RETRIES)) { | ||||||
| 		uprintf("Could not write patched file: %s\n", WindowsErrorString()); | 		uprintf("Could not write patched file: %s\n", WindowsErrorString()); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
							
								
								
									
										31
									
								
								src/icon.c
									
										
									
									
									
								
							
							
						
						
									
										31
									
								
								src/icon.c
									
										
									
									
									
								
							|  | @ -1,7 +1,7 @@ | ||||||
| /*
 | /*
 | ||||||
|  * Rufus: The Reliable USB Formatting Utility |  * Rufus: The Reliable USB Formatting Utility | ||||||
|  * Extract icon from executable and set autorun.inf |  * Extract icon from executable and set autorun.inf | ||||||
|  * Copyright © 2012-2013 Pete Batard <pete@akeo.ie> |  * Copyright © 2012-2016 Pete Batard <pete@akeo.ie> | ||||||
|  * |  * | ||||||
|  * This program is free software: you can redistribute it and/or modify |  * This program is free software: you can redistribute it and/or modify | ||||||
|  * it under the terms of the GNU General Public License as published by |  * it under the terms of the GNU General Public License as published by | ||||||
|  | @ -74,7 +74,7 @@ typedef struct | ||||||
| 	WORD	nID;			// the ID
 | 	WORD	nID;			// the ID
 | ||||||
| } GRPICONDIRENTRY, *LPGRPICONDIRENTRY; | } GRPICONDIRENTRY, *LPGRPICONDIRENTRY; | ||||||
| 
 | 
 | ||||||
| typedef struct  | typedef struct | ||||||
| { | { | ||||||
| 	WORD			idReserved;		// Reserved (must be 0)
 | 	WORD			idReserved;		// Reserved (must be 0)
 | ||||||
| 	WORD			idType;			// Resource type (1 for icons)
 | 	WORD			idType;			// Resource type (1 for icons)
 | ||||||
|  | @ -103,13 +103,13 @@ static BOOL SaveIcon(const char* filename) | ||||||
| 	hFile = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, | 	hFile = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, | ||||||
| 			NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); | 			NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); | ||||||
| 	if (hFile == INVALID_HANDLE_VALUE) { | 	if (hFile == INVALID_HANDLE_VALUE) { | ||||||
| 		uprintf("Unable to create icon '%s': %s.\n", filename, WindowsErrorString()); | 		uprintf("Unable to create icon '%s': %s.", filename, WindowsErrorString()); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Write .ico header
 | 	// Write .ico header
 | ||||||
| 	if ((!WriteFile(hFile, icondir, 3*sizeof(WORD), &Size, NULL)) || (Size != 3*sizeof(WORD))) { | 	if (!WriteFileWithRetry(hFile, icondir, 3*sizeof(WORD), &Size, WRITE_RETRIES)) { | ||||||
| 		uprintf("Couldn't write icon header: %s.\n", WindowsErrorString()); | 		uprintf("Could not write icon header: %s.", WindowsErrorString()); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -117,15 +117,14 @@ static BOOL SaveIcon(const char* filename) | ||||||
| 	offset = 3*sizeof(WORD) + icondir->idCount*sizeof(ICONDIRENTRY); | 	offset = 3*sizeof(WORD) + icondir->idCount*sizeof(ICONDIRENTRY); | ||||||
| 	for (i=0; i<icondir->idCount; i++) { | 	for (i=0; i<icondir->idCount; i++) { | ||||||
| 		// Write the common part of ICONDIRENTRY
 | 		// Write the common part of ICONDIRENTRY
 | ||||||
| 		if ( (!WriteFile(hFile, &icondir->idEntries[i], sizeof(GRPICONDIRENTRY)-sizeof(WORD), &Size, NULL)) | 		if (!WriteFileWithRetry(hFile, &icondir->idEntries[i], sizeof(GRPICONDIRENTRY)-sizeof(WORD), &Size, WRITE_RETRIES)) { | ||||||
| 		   || (Size != sizeof(GRPICONDIRENTRY)-sizeof(WORD)) ) { | 			uprintf("Could not write ICONDIRENTRY[%d]: %s.", i, WindowsErrorString()); | ||||||
| 			uprintf("Couldn't write ICONDIRENTRY[%d]: %s.\n", i, WindowsErrorString()); |  | ||||||
| 			goto out; | 			goto out; | ||||||
| 		} | 		} | ||||||
| 		res = FindResourceA(hMainInstance, MAKEINTRESOURCEA(icondir->idEntries[i].nID), _RT_ICON); | 		res = FindResourceA(hMainInstance, MAKEINTRESOURCEA(icondir->idEntries[i].nID), _RT_ICON); | ||||||
| 		// Write the DWORD offset
 | 		// Write the DWORD offset
 | ||||||
| 		if ( (!WriteFile(hFile, &offset, sizeof(offset), &Size, NULL)) || (Size != sizeof(offset)) ) { | 		if (!WriteFileWithRetry(hFile, &offset, sizeof(offset), &Size, WRITE_RETRIES)) { | ||||||
| 			uprintf("Couldn't write ICONDIRENTRY[%d] offset: %s.\n", i, WindowsErrorString()); | 			uprintf("Could not write ICONDIRENTRY[%d] offset: %s.", i, WindowsErrorString()); | ||||||
| 			goto out; | 			goto out; | ||||||
| 		} | 		} | ||||||
| 		offset += SizeofResource(NULL, res); | 		offset += SizeofResource(NULL, res); | ||||||
|  | @ -136,12 +135,12 @@ static BOOL SaveIcon(const char* filename) | ||||||
| 		res_handle = LoadResource(NULL, res); | 		res_handle = LoadResource(NULL, res); | ||||||
| 		res_data = (BYTE*)LockResource(res_handle); | 		res_data = (BYTE*)LockResource(res_handle); | ||||||
| 		res_size = SizeofResource(NULL, res); | 		res_size = SizeofResource(NULL, res); | ||||||
| 		if ( (!WriteFile(hFile, res_data, res_size, &Size, NULL)) || (Size != res_size) ) { | 		if (!WriteFileWithRetry(hFile, res_data, res_size, &Size, WRITE_RETRIES)) { | ||||||
| 			uprintf("Couldn't write icon data #%d: %s.\n", i, WindowsErrorString()); | 			uprintf("Could not write icon data #%d: %s.", i, WindowsErrorString()); | ||||||
| 			goto out; | 			goto out; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	uprintf("Created: %s\n", filename); | 	uprintf("Created: %s", filename); | ||||||
| 	r = TRUE; | 	r = TRUE; | ||||||
| 
 | 
 | ||||||
| out: | out: | ||||||
|  | @ -163,14 +162,14 @@ BOOL SetAutorun(const char* path) | ||||||
| 	safe_sprintf(filename, sizeof(filename), "%sautorun.inf", path); | 	safe_sprintf(filename, sizeof(filename), "%sautorun.inf", path); | ||||||
| 	fd = fopen(filename, "r");	// If there's an existing autorun, don't overwrite
 | 	fd = fopen(filename, "r");	// If there's an existing autorun, don't overwrite
 | ||||||
| 	if (fd != NULL) { | 	if (fd != NULL) { | ||||||
| 		uprintf("%s already exists - keeping it\n", filename); | 		uprintf("%s already exists - keeping it", filename); | ||||||
| 		fclose(fd); | 		fclose(fd); | ||||||
| 		return FALSE; | 		return FALSE; | ||||||
| 	} | 	} | ||||||
| 	// No "/autorun.inf" => create a new one in UTF-16 LE mode
 | 	// No "/autorun.inf" => create a new one in UTF-16 LE mode
 | ||||||
| 	fd = fopen(filename, "w, ccs=UTF-16LE"); | 	fd = fopen(filename, "w, ccs=UTF-16LE"); | ||||||
| 	if (fd == NULL) { | 	if (fd == NULL) { | ||||||
| 		uprintf("Unable to create %s\n", filename); | 		uprintf("Unable to create %s", filename); | ||||||
| 		uprintf("NOTE: This may be caused by a poorly designed security solution. " | 		uprintf("NOTE: This may be caused by a poorly designed security solution. " | ||||||
| 			"See http://rufus.akeo.ie/compatibility."); | 			"See http://rufus.akeo.ie/compatibility."); | ||||||
| 		return FALSE; | 		return FALSE; | ||||||
|  | @ -181,7 +180,7 @@ BOOL SetAutorun(const char* path) | ||||||
| 	fwprintf(fd, L"; Created by %s\n; " LTEXT(RUFUS_URL) L"\n", wRufusVersion); | 	fwprintf(fd, L"; Created by %s\n; " LTEXT(RUFUS_URL) L"\n", wRufusVersion); | ||||||
| 	fwprintf(fd, L"[autorun]\nicon  = autorun.ico\nlabel = %s\n", wlabel); | 	fwprintf(fd, L"[autorun]\nicon  = autorun.ico\nlabel = %s\n", wlabel); | ||||||
| 	fclose(fd); | 	fclose(fd); | ||||||
| 	uprintf("Created: %s\n", filename); | 	uprintf("Created: %s", filename); | ||||||
| 
 | 
 | ||||||
| 	// .inf -> .ico
 | 	// .inf -> .ico
 | ||||||
| 	filename[strlen(filename)-1] = 'o'; | 	filename[strlen(filename)-1] = 'o'; | ||||||
|  |  | ||||||
							
								
								
									
										41
									
								
								src/iso.c
									
										
									
									
									
								
							
							
						
						
									
										41
									
								
								src/iso.c
									
										
									
									
									
								
							|  | @ -1,7 +1,7 @@ | ||||||
| /*
 | /*
 | ||||||
|  * Rufus: The Reliable USB Formatting Utility |  * Rufus: The Reliable USB Formatting Utility | ||||||
|  * ISO file extraction |  * ISO file extraction | ||||||
|  * Copyright © 2011-2015 Pete Batard <pete@akeo.ie> |  * Copyright © 2011-2016 Pete Batard <pete@akeo.ie> | ||||||
|  * Based on libcdio's iso & udf samples: |  * Based on libcdio's iso & udf samples: | ||||||
|  * Copyright © 2003-2014 Rocky Bernstein <rocky@gnu.org> |  * Copyright © 2003-2014 Rocky Bernstein <rocky@gnu.org> | ||||||
|  * |  * | ||||||
|  | @ -429,17 +429,11 @@ static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const cha | ||||||
| 					goto out; | 					goto out; | ||||||
| 				} | 				} | ||||||
| 				buf_size = (DWORD)MIN(i_file_length, i_read); | 				buf_size = (DWORD)MIN(i_file_length, i_read); | ||||||
| 				for (i=0; i<WRITE_RETRIES; i++) { | 				ISO_BLOCKING(r = WriteFileWithRetry(file_handle, buf, buf_size, &wr_size, WRITE_RETRIES)); | ||||||
| 					ISO_BLOCKING(r = WriteFile(file_handle, buf, buf_size, &wr_size, NULL)); | 				if (!r) { | ||||||
| 					if ((!r) || (buf_size != wr_size)) { | 					uprintf("  Error writing file: %s", WindowsErrorString()); | ||||||
| 						uprintf("  Error writing file: %s", WindowsErrorString()); | 					goto out; | ||||||
| 						if (i < WRITE_RETRIES-1) |  | ||||||
| 							uprintf("  RETRYING...\n"); |  | ||||||
| 					} else { |  | ||||||
| 						break; |  | ||||||
| 					} |  | ||||||
| 				} | 				} | ||||||
| 				if (i >= WRITE_RETRIES) goto out; |  | ||||||
| 				i_file_length -= i_read; | 				i_file_length -= i_read; | ||||||
| 				if (nb_blocks++ % PROGRESS_THRESHOLD == 0) | 				if (nb_blocks++ % PROGRESS_THRESHOLD == 0) | ||||||
| 					UpdateProgress(OP_DOS, 100.0f*nb_blocks/total_blocks); | 					UpdateProgress(OP_DOS, 100.0f*nb_blocks/total_blocks); | ||||||
|  | @ -476,7 +470,7 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path) | ||||||
| 	HANDLE file_handle = NULL; | 	HANDLE file_handle = NULL; | ||||||
| 	DWORD buf_size, wr_size, err; | 	DWORD buf_size, wr_size, err; | ||||||
| 	EXTRACT_PROPS props; | 	EXTRACT_PROPS props; | ||||||
| 	BOOL s, is_symlink, is_identical; | 	BOOL is_symlink, is_identical; | ||||||
| 	int i_length, r = 1; | 	int i_length, r = 1; | ||||||
| 	char tmp[128], psz_fullpath[MAX_PATH], *psz_basename, *psz_sanpath; | 	char tmp[128], psz_fullpath[MAX_PATH], *psz_basename, *psz_sanpath; | ||||||
| 	const char *psz_iso_name = &psz_fullpath[strlen(psz_extract_dir)]; | 	const char *psz_iso_name = &psz_fullpath[strlen(psz_extract_dir)]; | ||||||
|  | @ -484,7 +478,7 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path) | ||||||
| 	CdioListNode_t* p_entnode; | 	CdioListNode_t* p_entnode; | ||||||
| 	iso9660_stat_t *p_statbuf; | 	iso9660_stat_t *p_statbuf; | ||||||
| 	CdioList_t* p_entlist; | 	CdioList_t* p_entlist; | ||||||
| 	size_t i, j; | 	size_t i; | ||||||
| 	lsn_t lsn; | 	lsn_t lsn; | ||||||
| 	int64_t i_file_length; | 	int64_t i_file_length; | ||||||
| 
 | 
 | ||||||
|  | @ -582,17 +576,11 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path) | ||||||
| 					goto out; | 					goto out; | ||||||
| 				} | 				} | ||||||
| 				buf_size = (DWORD)MIN(i_file_length, ISO_BLOCKSIZE); | 				buf_size = (DWORD)MIN(i_file_length, ISO_BLOCKSIZE); | ||||||
| 				for (j=0; j<WRITE_RETRIES; j++) { | 				ISO_BLOCKING(r = WriteFileWithRetry(file_handle, buf, buf_size, &wr_size, WRITE_RETRIES)); | ||||||
| 					ISO_BLOCKING(s = WriteFile(file_handle, buf, buf_size, &wr_size, NULL)); | 				if (!r) { | ||||||
| 					if ((!s) || (buf_size != wr_size)) { | 					uprintf("  Error writing file: %s", WindowsErrorString()); | ||||||
| 						uprintf("  Error writing file: %s", WindowsErrorString()); | 					goto out; | ||||||
| 						if (j < WRITE_RETRIES-1) |  | ||||||
| 							uprintf("  RETRYING...\n"); |  | ||||||
| 					} else { |  | ||||||
| 						break; |  | ||||||
| 					} |  | ||||||
| 				} | 				} | ||||||
| 				if (j >= WRITE_RETRIES) goto out; |  | ||||||
| 				i_file_length -= ISO_BLOCKSIZE; | 				i_file_length -= ISO_BLOCKSIZE; | ||||||
| 				if (nb_blocks++ % PROGRESS_THRESHOLD == 0) | 				if (nb_blocks++ % PROGRESS_THRESHOLD == 0) | ||||||
| 					UpdateProgress(OP_DOS, 100.0f*nb_blocks/total_blocks); | 					UpdateProgress(OP_DOS, 100.0f*nb_blocks/total_blocks); | ||||||
|  | @ -918,7 +906,6 @@ int64_t ExtractISOFile(const char* iso, const char* iso_file, const char* dest_f | ||||||
| 	int64_t file_length, r = 0; | 	int64_t file_length, r = 0; | ||||||
| 	char buf[UDF_BLOCKSIZE]; | 	char buf[UDF_BLOCKSIZE]; | ||||||
| 	DWORD buf_size, wr_size; | 	DWORD buf_size, wr_size; | ||||||
| 	BOOL s; |  | ||||||
| 	iso9660_t* p_iso = NULL; | 	iso9660_t* p_iso = NULL; | ||||||
| 	udf_t* p_udf = NULL; | 	udf_t* p_udf = NULL; | ||||||
| 	udf_dirent_t *p_udf_root = NULL, *p_udf_file = NULL; | 	udf_dirent_t *p_udf_root = NULL, *p_udf_file = NULL; | ||||||
|  | @ -957,8 +944,7 @@ int64_t ExtractISOFile(const char* iso, const char* iso_file, const char* dest_f | ||||||
| 			goto out; | 			goto out; | ||||||
| 		} | 		} | ||||||
| 		buf_size = (DWORD)MIN(file_length, read_size); | 		buf_size = (DWORD)MIN(file_length, read_size); | ||||||
| 		s = WriteFile(file_handle, buf, buf_size, &wr_size, NULL); | 		if (!WriteFileWithRetry(file_handle, buf, buf_size, &wr_size, WRITE_RETRIES)) { | ||||||
| 		if ((!s) || (buf_size != wr_size)) { |  | ||||||
| 			uprintf("  Error writing file %s: %s\n", dest_file, WindowsErrorString()); | 			uprintf("  Error writing file %s: %s\n", dest_file, WindowsErrorString()); | ||||||
| 			goto out; | 			goto out; | ||||||
| 		} | 		} | ||||||
|  | @ -989,8 +975,7 @@ try_iso: | ||||||
| 			goto out; | 			goto out; | ||||||
| 		} | 		} | ||||||
| 		buf_size = (DWORD)MIN(file_length, ISO_BLOCKSIZE); | 		buf_size = (DWORD)MIN(file_length, ISO_BLOCKSIZE); | ||||||
| 		s = WriteFile(file_handle, buf, buf_size, &wr_size, NULL); | 		if (!WriteFileWithRetry(file_handle, buf, buf_size, &wr_size, WRITE_RETRIES)) { | ||||||
| 		if ((!s) || (buf_size != wr_size)) { |  | ||||||
| 			uprintf("  Error writing file %s: %s\n", dest_file, WindowsErrorString()); | 			uprintf("  Error writing file %s: %s\n", dest_file, WindowsErrorString()); | ||||||
| 			goto out; | 			goto out; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -2947,7 +2947,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine | ||||||
| 
 | 
 | ||||||
| 		hFile = CreateFileU(loc_file, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, | 		hFile = CreateFileU(loc_file, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, | ||||||
| 			NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | 			NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | ||||||
| 		if ((hFile == INVALID_HANDLE_VALUE) || (!WriteFile(hFile, loc_data, loc_size, &size, 0)) || (loc_size != size)) { | 		if ((hFile == INVALID_HANDLE_VALUE) || (!WriteFileWithRetry(hFile, loc_data, loc_size, &size, WRITE_RETRIES))) { | ||||||
| 			uprintf("localization: unable to extract '%s': %s.\n", loc_file, WindowsErrorString()); | 			uprintf("localization: unable to extract '%s': %s.\n", loc_file, WindowsErrorString()); | ||||||
| 			safe_closehandle(hFile); | 			safe_closehandle(hFile); | ||||||
| 			goto out; | 			goto out; | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| /*
 | /*
 | ||||||
|  * Rufus: The Reliable USB Formatting Utility |  * Rufus: The Reliable USB Formatting Utility | ||||||
|  * Copyright © 2011-2015 Pete Batard <pete@akeo.ie> |  * Copyright © 2011-2016 Pete Batard <pete@akeo.ie> | ||||||
|  * |  * | ||||||
|  * This program is free software: you can redistribute it and/or modify |  * This program is free software: you can redistribute it and/or modify | ||||||
|  * it under the terms of the GNU General Public License as published by |  * it under the terms of the GNU General Public License as published by | ||||||
|  | @ -457,6 +457,8 @@ extern int IsHDD(DWORD DriveIndex, uint16_t vid, uint16_t pid, const char* strid | ||||||
| extern void LostTranslatorCheck(void); | extern void LostTranslatorCheck(void); | ||||||
| extern LONG ValidateSignature(HWND hDlg, const char* path); | extern LONG ValidateSignature(HWND hDlg, const char* path); | ||||||
| extern BOOL IsFontAvailable(const char* font_name); | extern BOOL IsFontAvailable(const char* font_name); | ||||||
|  | extern BOOL WriteFileWithRetry(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, | ||||||
|  | 	LPDWORD lpNumberOfBytesWritten, DWORD nNumRetries); | ||||||
| 
 | 
 | ||||||
| DWORD WINAPI FormatThread(void* param); | DWORD WINAPI FormatThread(void* param); | ||||||
| DWORD WINAPI SaveImageThread(void* param); | DWORD WINAPI SaveImageThread(void* param); | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							|  | @ -32,7 +32,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL | ||||||
| 
 | 
 | ||||||
| IDD_DIALOG DIALOGEX 12, 12, 242, 376 | IDD_DIALOG DIALOGEX 12, 12, 242, 376 | ||||||
| STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | ||||||
| CAPTION "Rufus 2.7.830" | CAPTION "Rufus 2.7.831" | ||||||
| FONT 8, "Segoe UI Symbol", 400, 0, 0x0 | FONT 8, "Segoe UI Symbol", 400, 0, 0x0 | ||||||
| BEGIN | BEGIN | ||||||
|     LTEXT           "Device",IDS_DEVICE_TXT,9,6,200,8 |     LTEXT           "Device",IDS_DEVICE_TXT,9,6,200,8 | ||||||
|  | @ -319,8 +319,8 @@ END | ||||||
| // | // | ||||||
| 
 | 
 | ||||||
| VS_VERSION_INFO VERSIONINFO | VS_VERSION_INFO VERSIONINFO | ||||||
|  FILEVERSION 2,7,830,0 |  FILEVERSION 2,7,831,0 | ||||||
|  PRODUCTVERSION 2,7,830,0 |  PRODUCTVERSION 2,7,831,0 | ||||||
|  FILEFLAGSMASK 0x3fL |  FILEFLAGSMASK 0x3fL | ||||||
| #ifdef _DEBUG | #ifdef _DEBUG | ||||||
|  FILEFLAGS 0x1L |  FILEFLAGS 0x1L | ||||||
|  | @ -337,13 +337,13 @@ BEGIN | ||||||
|         BEGIN |         BEGIN | ||||||
|             VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" |             VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" | ||||||
|             VALUE "FileDescription", "Rufus" |             VALUE "FileDescription", "Rufus" | ||||||
|             VALUE "FileVersion", "2.7.830" |             VALUE "FileVersion", "2.7.831" | ||||||
|             VALUE "InternalName", "Rufus" |             VALUE "InternalName", "Rufus" | ||||||
|             VALUE "LegalCopyright", "© 2011-2016 Pete Batard (GPL v3)" |             VALUE "LegalCopyright", "© 2011-2016 Pete Batard (GPL v3)" | ||||||
|             VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" |             VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" | ||||||
|             VALUE "OriginalFilename", "rufus.exe" |             VALUE "OriginalFilename", "rufus.exe" | ||||||
|             VALUE "ProductName", "Rufus" |             VALUE "ProductName", "Rufus" | ||||||
|             VALUE "ProductVersion", "2.7.830" |             VALUE "ProductVersion", "2.7.831" | ||||||
|         END |         END | ||||||
|     END |     END | ||||||
|     BLOCK "VarFileInfo" |     BLOCK "VarFileInfo" | ||||||
|  |  | ||||||
							
								
								
									
										37
									
								
								src/stdfn.c
									
										
									
									
									
								
							
							
						
						
									
										37
									
								
								src/stdfn.c
									
										
									
									
									
								
							|  | @ -1,7 +1,7 @@ | ||||||
| /*
 | /*
 | ||||||
|  * Rufus: The Reliable USB Formatting Utility |  * Rufus: The Reliable USB Formatting Utility | ||||||
|  * Standard Windows function calls |  * Standard Windows function calls | ||||||
|  * Copyright © 2013-2015 Pete Batard <pete@akeo.ie> |  * Copyright © 2013-2016 Pete Batard <pete@akeo.ie> | ||||||
|  * |  * | ||||||
|  * This program is free software: you can redistribute it and/or modify |  * This program is free software: you can redistribute it and/or modify | ||||||
|  * it under the terms of the GNU General Public License as published by |  * it under the terms of the GNU General Public License as published by | ||||||
|  | @ -810,3 +810,38 @@ BOOL SetLGP(BOOL bRestore, BOOL* bExistingKey, const char* szPath, const char* s | ||||||
| 		return FALSE; | 		return FALSE; | ||||||
| 	return (BOOL) r; | 	return (BOOL) r; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | BOOL WriteFileWithRetry(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, | ||||||
|  | 	LPDWORD lpNumberOfBytesWritten, DWORD nNumRetries) | ||||||
|  | { | ||||||
|  | 	DWORD nTry = 1; | ||||||
|  | 	BOOL readFilePointer; | ||||||
|  | 	LARGE_INTEGER liFilePointer, liZero = { {0,0} }; | ||||||
|  | 	static char* retry_msg = " - retrying..."; | ||||||
|  | 
 | ||||||
|  | 	// Need to get the current file pointer in case we need to retry
 | ||||||
|  | 	readFilePointer = SetFilePointerEx(hFile, liZero, &liFilePointer, FILE_CURRENT); | ||||||
|  | 	if (!readFilePointer) | ||||||
|  | 		uprintf("  Warning  - could not read file pointer: %s", WindowsErrorString()); | ||||||
|  | 
 | ||||||
|  | 	do { | ||||||
|  | 		// Need to rewind our file position on retry
 | ||||||
|  | 		if ((nTry > 1) && (!SetFilePointerEx(hFile, liFilePointer, NULL, FILE_BEGIN))) { | ||||||
|  | 			uprintf("  Could not set file pointer%s", retry_msg); | ||||||
|  | 			goto next_try; | ||||||
|  | 		} | ||||||
|  | 		if (WriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, NULL)) { | ||||||
|  | 			if (nNumberOfBytesToWrite == *lpNumberOfBytesWritten) | ||||||
|  | 				return TRUE; | ||||||
|  | 			uprintf("  Wrote %d bytes but requested %d%s", *lpNumberOfBytesWritten, | ||||||
|  | 				nNumberOfBytesToWrite, nTry < nNumRetries ? retry_msg : ""); | ||||||
|  | 			SetLastError(ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_INCORRECT_SIZE); | ||||||
|  | 		} else { | ||||||
|  | 			uprintf("  Write error%s", nTry < nNumRetries ? retry_msg : ""); | ||||||
|  | 		} | ||||||
|  | next_try: | ||||||
|  | 		Sleep(200); | ||||||
|  | 		nTry++; | ||||||
|  | 	} while((readFilePointer) && (nTry < nNumRetries)); | ||||||
|  | 	return FALSE; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
|  * |  * | ||||||
|  *   Copyright 2003 Lars Munch Christensen - All Rights Reserved |  *   Copyright 2003 Lars Munch Christensen - All Rights Reserved | ||||||
|  *   Copyright 1998-2008 H. Peter Anvin - All Rights Reserved |  *   Copyright 1998-2008 H. Peter Anvin - All Rights Reserved | ||||||
|  *   Copyright 2012-2015 Pete Batard |  *   Copyright 2012-2016 Pete Batard | ||||||
|  * |  * | ||||||
|  *   Based on the Linux installer program for SYSLINUX by H. Peter Anvin |  *   Based on the Linux installer program for SYSLINUX by H. Peter Anvin | ||||||
|  * |  * | ||||||
|  | @ -137,16 +137,16 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type) | ||||||
| 				img_report.sl_version_ext, ldlinux, i==0?"sys":"bss"); | 				img_report.sl_version_ext, ldlinux, i==0?"sys":"bss"); | ||||||
| 			fd = fopen(path, "rb"); | 			fd = fopen(path, "rb"); | ||||||
| 			if (fd == NULL) { | 			if (fd == NULL) { | ||||||
| 				uprintf("Could not open %s\n", path); | 				uprintf("Could not open %s", path); | ||||||
| 				goto out; | 				goto out; | ||||||
| 			} | 			} | ||||||
| 			length = fread(syslinux_ldlinux[i], 1, (size_t)syslinux_ldlinux_len[i], fd); | 			length = fread(syslinux_ldlinux[i], 1, (size_t)syslinux_ldlinux_len[i], fd); | ||||||
| 			fclose(fd); | 			fclose(fd); | ||||||
| 			if (length != (size_t)syslinux_ldlinux_len[i]) { | 			if (length != (size_t)syslinux_ldlinux_len[i]) { | ||||||
| 				uprintf("Could not read %s\n", path); | 				uprintf("Could not read %s", path); | ||||||
| 				goto out; | 				goto out; | ||||||
| 			} | 			} | ||||||
| 			uprintf("Using existing './%s'\n", path); | 			uprintf("Using existing './%s'", path); | ||||||
| 		} | 		} | ||||||
| 	} else { | 	} else { | ||||||
| 		for (i=0; i<2; i++) { | 		for (i=0; i<2; i++) { | ||||||
|  | @ -167,38 +167,36 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type) | ||||||
| 			  FILE_ATTRIBUTE_HIDDEN, NULL); | 			  FILE_ATTRIBUTE_HIDDEN, NULL); | ||||||
| 
 | 
 | ||||||
| 	if (f_handle == INVALID_HANDLE_VALUE) { | 	if (f_handle == INVALID_HANDLE_VALUE) { | ||||||
| 		uprintf("Unable to create '%s'\n", &path[3]); | 		uprintf("Unable to create '%s'", &path[3]); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	/* Write ldlinux.sys file */ | 	/* Write ldlinux.sys file */ | ||||||
| 	if (!WriteFile(f_handle, (const char _force *)syslinux_ldlinux[0], | 	if (!WriteFileWithRetry(f_handle, (const char _force *)syslinux_ldlinux[0], | ||||||
| 		   syslinux_ldlinux_len[0], &bytes_written, NULL) || | 		   syslinux_ldlinux_len[0], &bytes_written, WRITE_RETRIES)) { | ||||||
| 		bytes_written != syslinux_ldlinux_len[0]) { | 		uprintf("Could not write '%s': %s", &path[3], WindowsErrorString()); | ||||||
| 		uprintf("Could not write '%s'\n", &path[3]); |  | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 	if (!WriteFile(f_handle, syslinux_adv, 2 * ADV_SIZE, | 	if (!WriteFileWithRetry(f_handle, syslinux_adv, 2 * ADV_SIZE, | ||||||
| 		   &bytes_written, NULL) || | 		   &bytes_written, WRITE_RETRIES)) { | ||||||
| 		bytes_written != 2 * ADV_SIZE) { | 		uprintf("Could not write ADV to '%s': %s", &path[3], WindowsErrorString()); | ||||||
| 		uprintf("Could not write ADV to '%s'\n", &path[3]); |  | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	uprintf("Successfully wrote '%s'\n", &path[3]); | 	uprintf("Successfully wrote '%s'", &path[3]); | ||||||
| 	if (bt != BT_ISO) | 	if (bt != BT_ISO) | ||||||
| 		UpdateProgress(OP_DOS, -1.0f); | 		UpdateProgress(OP_DOS, -1.0f); | ||||||
| 
 | 
 | ||||||
| 	/* Now flush the media */ | 	/* Now flush the media */ | ||||||
| 	if (!FlushFileBuffers(f_handle)) { | 	if (!FlushFileBuffers(f_handle)) { | ||||||
| 		uprintf("FlushFileBuffers failed\n"); | 		uprintf("FlushFileBuffers failed"); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	/* Reopen the volume (we already have a lock) */ | 	/* Reopen the volume (we already have a lock) */ | ||||||
| 	d_handle = GetLogicalHandle(drive_index, TRUE, FALSE); | 	d_handle = GetLogicalHandle(drive_index, TRUE, FALSE); | ||||||
| 	if (d_handle == INVALID_HANDLE_VALUE) { | 	if (d_handle == INVALID_HANDLE_VALUE) { | ||||||
| 		uprintf("Could open volume for Syslinux installation\n"); | 		uprintf("Could open volume for Syslinux installation"); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -242,7 +240,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type) | ||||||
| 	case FS_EXFAT: | 	case FS_EXFAT: | ||||||
| 		fs = libfat_open(libfat_readfile, (intptr_t) d_handle); | 		fs = libfat_open(libfat_readfile, (intptr_t) d_handle); | ||||||
| 		if (fs == NULL) { | 		if (fs == NULL) { | ||||||
| 			uprintf("Syslinux FAT access error\n"); | 			uprintf("Syslinux FAT access error"); | ||||||
| 			goto out; | 			goto out; | ||||||
| 		} | 		} | ||||||
| 		ldlinux_cluster = libfat_searchdir(fs, 0, "LDLINUX SYS", NULL); | 		ldlinux_cluster = libfat_searchdir(fs, 0, "LDLINUX SYS", NULL); | ||||||
|  | @ -257,7 +255,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type) | ||||||
| 		libfat_close(fs); | 		libfat_close(fs); | ||||||
| 		break; | 		break; | ||||||
| 	default: | 	default: | ||||||
| 		uprintf("Unsupported Syslinux filesystem\n"); | 		uprintf("Unsupported Syslinux filesystem"); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -269,9 +267,8 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type) | ||||||
| 
 | 
 | ||||||
| 	/* Rewrite the file */ | 	/* Rewrite the file */ | ||||||
| 	if (SetFilePointer(f_handle, 0, NULL, FILE_BEGIN) != 0 || | 	if (SetFilePointer(f_handle, 0, NULL, FILE_BEGIN) != 0 || | ||||||
| 		!WriteFile(f_handle, syslinux_ldlinux[0], syslinux_ldlinux_len[0], | 		!WriteFileWithRetry(f_handle, syslinux_ldlinux[0], syslinux_ldlinux_len[0], | ||||||
| 			   &bytes_written, NULL) | 			   &bytes_written, WRITE_RETRIES)) { | ||||||
| 		|| bytes_written != syslinux_ldlinux_len[0]) { |  | ||||||
| 		uprintf("Could not write '%s': %s\n", &path[3], WindowsErrorString()); | 		uprintf("Could not write '%s': %s\n", &path[3], WindowsErrorString()); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
|  | @ -282,9 +279,12 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type) | ||||||
| 	/* Read existing FAT data into boot sector */ | 	/* Read existing FAT data into boot sector */ | ||||||
| 	if (SetFilePointer(d_handle, 0, NULL, FILE_BEGIN) != 0 || | 	if (SetFilePointer(d_handle, 0, NULL, FILE_BEGIN) != 0 || | ||||||
| 		!ReadFile(d_handle, sectbuf, SECTOR_SIZE, | 		!ReadFile(d_handle, sectbuf, SECTOR_SIZE, | ||||||
| 			   &bytes_read, NULL) | 			   &bytes_read, NULL)) { | ||||||
| 		|| bytes_read != SECTOR_SIZE) { | 		uprintf("Could not read Syslinux boot record: %s", WindowsErrorString()); | ||||||
| 		uprintf("Could not read boot record: %s\n", WindowsErrorString()); | 		goto out; | ||||||
|  | 	} | ||||||
|  | 	if (bytes_read < SECTOR_SIZE) { | ||||||
|  | 		uprintf("Partial read of Syslinux boot record: read %d bytes but requested %d", bytes_read, SECTOR_SIZE); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -293,14 +293,12 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type) | ||||||
| 
 | 
 | ||||||
| 	/* Write boot sector back */ | 	/* Write boot sector back */ | ||||||
| 	if (SetFilePointer(d_handle, 0, NULL, FILE_BEGIN) != 0 || | 	if (SetFilePointer(d_handle, 0, NULL, FILE_BEGIN) != 0 || | ||||||
| 		!WriteFile(d_handle, sectbuf, SECTOR_SIZE, | 		!WriteFileWithRetry(d_handle, sectbuf, SECTOR_SIZE, | ||||||
| 			   &bytes_written, NULL) | 			   &bytes_written, WRITE_RETRIES)) { | ||||||
| 		|| bytes_written != SECTOR_SIZE) { | 		uprintf("Could not write Syslinux boot record: %s", WindowsErrorString()); | ||||||
| 		uprintf("Could not write Syslinux boot record: %s\n", WindowsErrorString()); |  | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 
 | 	uprintf("Successfully wrote Syslinux boot record"); | ||||||
| 	uprintf("Successfully wrote Syslinux boot record\n"); |  | ||||||
| 
 | 
 | ||||||
| 	if (bt == BT_SYSLINUX_V6) { | 	if (bt == BT_SYSLINUX_V6) { | ||||||
| 		IGNORE_RETVAL(_chdirU(app_dir)); | 		IGNORE_RETVAL(_chdirU(app_dir)); | ||||||
|  | @ -309,17 +307,17 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type) | ||||||
| 		static_sprintf(path, "%C:\\%s.%s", drive_letter, ldlinux, ldlinux_ext[2]); | 		static_sprintf(path, "%C:\\%s.%s", drive_letter, ldlinux, ldlinux_ext[2]); | ||||||
| 		fd = fopen(&path[3], "rb"); | 		fd = fopen(&path[3], "rb"); | ||||||
| 		if (fd == NULL) { | 		if (fd == NULL) { | ||||||
| 			uprintf("Caution: No '%s' was provided. The target will be missing a required Syslinux file!\n", &path[3]); | 			uprintf("Caution: No '%s' was provided. The target will be missing a required Syslinux file!", &path[3]); | ||||||
| 		} else { | 		} else { | ||||||
| 			fclose(fd); | 			fclose(fd); | ||||||
| 			if (CopyFileA(&path[3], path, TRUE)) { | 			if (CopyFileA(&path[3], path, TRUE)) { | ||||||
| 				uprintf("Created '%s' (from '%s/%s-%s/%s')", path, FILES_DIR, syslinux, embedded_sl_version_str[1], &path[3]); | 				uprintf("Created '%s' (from '%s/%s-%s/%s')", path, FILES_DIR, syslinux, embedded_sl_version_str[1], &path[3]); | ||||||
| 			} else { | 			} else { | ||||||
| 				uprintf("Failed to create '%s': %s\n", path, WindowsErrorString()); | 				uprintf("Failed to create '%s': %s", path, WindowsErrorString()); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} else if (IS_REACTOS(img_report)) { | 	} else if (IS_REACTOS(img_report)) { | ||||||
| 		uprintf("Setting up ReactOS...\n"); | 		uprintf("Setting up ReactOS..."); | ||||||
| 		syslinux_mboot = GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_SL_MBOOT_C32), | 		syslinux_mboot = GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_SL_MBOOT_C32), | ||||||
| 			_RT_RCDATA, "mboot.c32", &syslinux_mboot_len, FALSE); | 			_RT_RCDATA, "mboot.c32", &syslinux_mboot_len, FALSE); | ||||||
| 		if (syslinux_mboot == NULL) { | 		if (syslinux_mboot == NULL) { | ||||||
|  | @ -334,21 +332,20 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type) | ||||||
| 			uprintf("Unable to create '%s'\n", path); | 			uprintf("Unable to create '%s'\n", path); | ||||||
| 			goto out; | 			goto out; | ||||||
| 		} | 		} | ||||||
| 		if (!WriteFile(f_handle, syslinux_mboot, syslinux_mboot_len, | 		if (!WriteFileWithRetry(f_handle, syslinux_mboot, syslinux_mboot_len, | ||||||
| 			   &bytes_written, NULL) || | 			   &bytes_written, WRITE_RETRIES)) { | ||||||
| 			bytes_written != syslinux_mboot_len) { | 			uprintf("Could not write '%s'", path); | ||||||
| 			uprintf("Could not write '%s'\n", path); |  | ||||||
| 			goto out; | 			goto out; | ||||||
| 		} | 		} | ||||||
| 		safe_closehandle(f_handle); | 		safe_closehandle(f_handle); | ||||||
| 		static_sprintf(path, "%C:\\syslinux.cfg", drive_letter); | 		static_sprintf(path, "%C:\\syslinux.cfg", drive_letter); | ||||||
| 		fd = fopen(path, "w"); | 		fd = fopen(path, "w"); | ||||||
| 		if (fd == NULL) { | 		if (fd == NULL) { | ||||||
| 			uprintf("Could not create ReactOS 'syslinux.cfg'\n"); | 			uprintf("Could not create ReactOS 'syslinux.cfg'"); | ||||||
| 			goto out; | 			goto out; | ||||||
| 		} | 		} | ||||||
| 		/* Write the syslinux.cfg for ReactOS */ | 		/* Write the syslinux.cfg for ReactOS */ | ||||||
| 		fprintf(fd, "DEFAULT ReactOS\nLABEL ReactOS\n  KERNEL %s\n  APPEND %s\n", | 		fprintf(fd, "DEFAULT ReactOS\nLABEL ReactOS\n  KERNEL %s\n  APPEND %s", | ||||||
| 			mboot_c32, img_report.reactos_path); | 			mboot_c32, img_report.reactos_path); | ||||||
| 		fclose(fd); | 		fclose(fd); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| /*
 | /*
 | ||||||
|  * Rufus: The Reliable USB Formatting Utility |  * Rufus: The Reliable USB Formatting Utility | ||||||
|  * Virtual Disk Handling functions |  * Virtual Disk Handling functions | ||||||
|  * Copyright © 2013-2015 Pete Batard <pete@akeo.ie> |  * Copyright © 2013-2016 Pete Batard <pete@akeo.ie> | ||||||
|  * |  * | ||||||
|  * This program is free software: you can redistribute it and/or modify |  * This program is free software: you can redistribute it and/or modify | ||||||
|  * it under the terms of the GNU General Public License as published by |  * it under the terms of the GNU General Public License as published by | ||||||
|  | @ -178,7 +178,7 @@ BOOL AppendVHDFooter(const char* vhd_path) | ||||||
| 		heads = 16; | 		heads = 16; | ||||||
| 		cylinderTimesHeads = (uint32_t)(totalSectors / sectorsPerTrack); | 		cylinderTimesHeads = (uint32_t)(totalSectors / sectorsPerTrack); | ||||||
| 	} else { | 	} else { | ||||||
| 		sectorsPerTrack = 17;  | 		sectorsPerTrack = 17; | ||||||
| 		cylinderTimesHeads = (uint32_t)(totalSectors / sectorsPerTrack); | 		cylinderTimesHeads = (uint32_t)(totalSectors / sectorsPerTrack); | ||||||
| 
 | 
 | ||||||
| 		heads = (cylinderTimesHeads + 1023) / 1024; | 		heads = (cylinderTimesHeads + 1023) / 1024; | ||||||
|  | @ -207,12 +207,12 @@ BOOL AppendVHDFooter(const char* vhd_path) | ||||||
| 		checksum += ((uint8_t*)footer)[i]; | 		checksum += ((uint8_t*)footer)[i]; | ||||||
| 	footer->checksum = bswap_uint32(~checksum); | 	footer->checksum = bswap_uint32(~checksum); | ||||||
| 
 | 
 | ||||||
| 	if (!WriteFile(handle, footer, sizeof(vhd_footer), &size, NULL) || (size != sizeof(vhd_footer))) { | 	if (!WriteFileWithRetry(handle, footer, sizeof(vhd_footer), &size, WRITE_RETRIES)) { | ||||||
| 		uprintf("Could not write VHD footer: %s", WindowsErrorString()); | 		uprintf("Could not write VHD footer: %s", WindowsErrorString()); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 	r = TRUE; | 	r = TRUE; | ||||||
| 	 | 
 | ||||||
| out: | out: | ||||||
| 	safe_free(footer); | 	safe_free(footer); | ||||||
| 	safe_closehandle(handle); | 	safe_closehandle(handle); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue