mirror of
				https://github.com/pbatard/rufus.git
				synced 2024-08-14 23:57:05 +00:00 
			
		
		
		
	[ext2fs] add registry setting to specify which ext fs version we should use
* Also improve log progress report * Also move ext formatting to before we format the main partition
This commit is contained in:
		
							parent
							
								
									0ad3f8c1d3
								
							
						
					
					
						commit
						0a3600f9ff
					
				
					 5 changed files with 98 additions and 67 deletions
				
			
		|  | @ -1738,7 +1738,7 @@ extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list, | |||
| 				      FILE *f); | ||||
| 
 | ||||
| /* Rufus addtional */ | ||||
| extern errcode_t ext2fs_print_progress(uint64_t cur, uint64_t max); | ||||
| extern errcode_t ext2fs_print_progress(int64_t cur, int64_t max); | ||||
| 
 | ||||
| /* inline functions */ | ||||
| #ifdef NO_INLINE_FUNCS | ||||
|  |  | |||
							
								
								
									
										116
									
								
								src/format.c
									
										
									
									
									
								
							
							
						
						
									
										116
									
								
								src/format.c
									
										
									
									
									
								
							|  | @ -36,6 +36,7 @@ | |||
| #include "rufus.h" | ||||
| #include "missing.h" | ||||
| #include "resource.h" | ||||
| #include "settings.h" | ||||
| #include "msapi_utf8.h" | ||||
| #include "localization.h" | ||||
| 
 | ||||
|  | @ -658,12 +659,7 @@ out: | |||
| 	return r; | ||||
| } | ||||
| 
 | ||||
| errcode_t ext2fs_print_progress(uint64_t cur, uint64_t max) | ||||
| { | ||||
| 	UPDATE_PERCENT(MSG_217, 25.0f + 75.0f * cur / (float)max); | ||||
| 	return IS_ERROR(FormatStatus) ? EXT2_ET_CANCEL_REQUESTED : 0; | ||||
| } | ||||
| 
 | ||||
| // Error messages for ext2fs
 | ||||
| const char* error_message(errcode_t error_code) | ||||
| { | ||||
| 	static char error_string[256]; | ||||
|  | @ -786,12 +782,30 @@ const char* error_message(errcode_t error_code) | |||
| 	case EXT2_ET_EA_INODE_CORRUPTED: | ||||
| 		return "Inode is corrupted"; | ||||
| 	default: | ||||
| 		static_sprintf(error_string, "Unknown ext2fs error 0x%08lX", error_code - EXT2_ET_BASE); | ||||
| 		if ((error_code > EXT2_ET_BASE) && error_code < (EXT2_ET_BASE + 1000)) | ||||
| 			static_sprintf(error_string, "Unknown ext2fs error %ld (EXT2_ET_BASE + %ld)", error_code, error_code - EXT2_ET_BASE); | ||||
| 		else | ||||
| 			static_sprintf(error_string, "Unknown ext2fs error 0x%08lX", error_code); | ||||
| 		return error_string; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| BOOL FormatExt2Fs(const char* label) | ||||
| static float ext2_percent_start = 0.0f, ext2_percent_share = 50.0f; | ||||
| errcode_t ext2fs_print_progress(int64_t cur_value, int64_t max_value) | ||||
| { | ||||
| 	static int64_t last_value = -1; | ||||
| 	if (max_value == 0) | ||||
| 		return 0; | ||||
| 	UPDATE_PERCENT(MSG_217, ext2_percent_start + ext2_percent_share * cur_value / (float)max_value); | ||||
| 	cur_value = (int64_t)(((float)cur_value / (float)max_value) * min(80.0f, (float)max_value)); | ||||
| 	if ((cur_value < last_value) || (cur_value > last_value)) { | ||||
| 		last_value = cur_value; | ||||
| 		uprintfs("+"); | ||||
| 	} | ||||
| 	return IS_ERROR(FormatStatus) ? EXT2_ET_CANCEL_REQUESTED : 0; | ||||
| } | ||||
| 
 | ||||
| BOOL FormatExtFs(const char* label, uint32_t version) | ||||
| { | ||||
| 	// Mostly taken from mke2fs.conf
 | ||||
| 	const float reserve_ratio = 0.05f; | ||||
|  | @ -804,7 +818,7 @@ BOOL FormatExt2Fs(const char* label) | |||
| 	}; | ||||
| 
 | ||||
| 	BOOL ret = FALSE; | ||||
| 	char* path = NULL; | ||||
| 	char *path = NULL, *extfs_name = "ext#";; | ||||
| 	int i, count; | ||||
| 	struct ext2_super_block features = { 0 }; | ||||
| 	io_manager manager = nt_io_manager(); | ||||
|  | @ -834,8 +848,16 @@ BOOL FormatExt2Fs(const char* label) | |||
| #endif | ||||
| 	if (path == NULL) | ||||
| 		goto out; | ||||
| 	if ((version < 2) || (version > 3)) { | ||||
| 		if (version == 4) | ||||
| 			uprintf("ext4 file system is not supported, will use ext3 instead"); | ||||
| 		else | ||||
| 			uprintf("invalid ext file system version requested, will use ext3"); | ||||
| 		version = 3; | ||||
| 	} | ||||
| 
 | ||||
| 	PrintInfoDebug(0, MSG_222, "ext3"); | ||||
| 	extfs_name[3] = '0' + version; | ||||
| 	PrintInfoDebug(0, MSG_222, extfs_name); | ||||
| 	LastRefresh = 0; | ||||
| 
 | ||||
| 	// Figure out the volume size and block size
 | ||||
|  | @ -867,21 +889,22 @@ BOOL FormatExt2Fs(const char* label) | |||
| 	uprintf("%d possible inodes out of %lld blocks (block size = %d)", features.s_inodes_count, size, EXT2_BLOCK_SIZE(&features)); | ||||
| 	uprintf("%lld blocks (%0.1f%%) reserved for the super user", ext2fs_r_blocks_count(&features), reserve_ratio * 100.0f); | ||||
| 
 | ||||
| 	// Set features for ext3
 | ||||
| 	ext2fs_set_feature_journal(&features); | ||||
| 	// Set features
 | ||||
| 	ext2fs_set_feature_xattr(&features); | ||||
| 	ext2fs_set_feature_resize_inode(&features); | ||||
| 	ext2fs_set_feature_dir_index(&features); | ||||
| 	ext2fs_set_feature_filetype(&features); | ||||
| 	ext2fs_set_feature_sparse_super(&features); | ||||
| 	ext2fs_set_feature_large_file(&features); | ||||
| 	if (version >= 3) | ||||
| 		ext2fs_set_feature_journal(&features); | ||||
| 	features.s_backup_bgs[0] = ~0; | ||||
| 	features.s_default_mount_opts = EXT2_DEFM_XATTR_USER | EXT2_DEFM_ACL; | ||||
| 
 | ||||
| 	// Now that we have set our base features, initialize a virtual superblock
 | ||||
| 	r = ext2fs_initialize(path, EXT2_FLAG_EXCLUSIVE | EXT2_FLAG_64BITS, &features, manager, &ext2fs); | ||||
| 	if (r != 0) { | ||||
| 		uprintf("Could not initialize ext2fs features: %s", error_message(r)); | ||||
| 		uprintf("Could not initialize %s features: %s", extfs_name, error_message(r)); | ||||
| 		goto out; | ||||
| 	} | ||||
| 
 | ||||
|  | @ -891,7 +914,7 @@ BOOL FormatExt2Fs(const char* label) | |||
| 	r = io_channel_write_blk64(ext2fs->io, 0, 16, buf); | ||||
| 	safe_free(buf); | ||||
| 	if (r != 0) { | ||||
| 		uprintf("Could not zero ext2fs superblock area: %s", error_message(r)); | ||||
| 		uprintf("Could not zero %s superblock area: %s", extfs_name, error_message(r)); | ||||
| 		goto out; | ||||
| 	} | ||||
| 
 | ||||
|  | @ -907,29 +930,27 @@ BOOL FormatExt2Fs(const char* label) | |||
| 
 | ||||
| 	r = ext2fs_allocate_tables(ext2fs); | ||||
| 	if (r != 0) { | ||||
| 		uprintf("Could not allocate ext2fs tables: %s", error_message(r)); | ||||
| 		uprintf("Could not allocate %s tables: %s", extfs_name, error_message(r)); | ||||
| 		goto out; | ||||
| 	} | ||||
| 	r = ext2fs_convert_subcluster_bitmap(ext2fs, &ext2fs->block_map); | ||||
| 	if (r != 0) { | ||||
| 		uprintf("Could set ext2fs cluster bitmap: %s", error_message(r)); | ||||
| 		uprintf("Could set %s cluster bitmap: %s", extfs_name, error_message(r)); | ||||
| 		goto out; | ||||
| 	} | ||||
| 
 | ||||
| 	// This should take about 10%
 | ||||
| 	uprintf("Creating %d inodes...", ext2fs->group_desc_count); | ||||
| 	ext2_percent_start = 0.0f; | ||||
| 	ext2_percent_share = (version < 3) ? 100.0f : 50.0f; | ||||
| 	uprintf("Creating %d inode sets:", ext2fs->group_desc_count); | ||||
| 	for (i = 0; i < (int)ext2fs->group_desc_count; i++) { | ||||
| 		UPDATE_PERCENT(MSG_217, 25.0f * i / ((float)ext2fs->group_desc_count)) | ||||
| 		CHECK_FOR_USER_CANCEL; | ||||
| 		if (ext2fs_print_progress((int64_t)i, (int64_t)ext2fs->group_desc_count)) | ||||
| 			goto out; | ||||
| 		cur = ext2fs_inode_table_loc(ext2fs, i); | ||||
| 		count = ext2fs_div_ceil((ext2fs->super->s_inodes_per_group - ext2fs_bg_itable_unused(ext2fs, i)) | ||||
| 			* EXT2_BLOCK_SIZE(ext2fs->super), EXT2_BLOCK_SIZE(ext2fs->super)); | ||||
| 		uprintfs("+"); | ||||
| 		if ((i + 1) % 80 == 0) | ||||
| 			uprintfs("\r\n"); | ||||
| 		r = ext2fs_zero_blocks2(ext2fs, cur, count, &cur, &count); | ||||
| 		if (r != 0) { | ||||
| 			uprintf("Could not zero ext2fs inode at %llu (%d blocks): %s\n", cur, count, error_message(r)); | ||||
| 			uprintf("\r\nCould not zero inode set at position %llu (%d blocks): %s", cur, count, error_message(r)); | ||||
| 			goto out; | ||||
| 		} | ||||
| 	} | ||||
|  | @ -939,13 +960,13 @@ BOOL FormatExt2Fs(const char* label) | |||
| 	// Create root and lost+found dirs
 | ||||
| 	r = ext2fs_mkdir(ext2fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0); | ||||
| 	if (r != 0) { | ||||
| 		uprintf("Failed to create ext2fs root dir: %s", error_message(r)); | ||||
| 		uprintf("Failed to create %s root dir: %s", extfs_name, error_message(r)); | ||||
| 		goto out; | ||||
| 	} | ||||
| 	ext2fs->umask = 077; | ||||
| 	r = ext2fs_mkdir(ext2fs, EXT2_ROOT_INO, 0, "lost+found"); | ||||
| 	if (r != 0) { | ||||
| 		uprintf("Failed to create ext2fs 'lost+found' dir: %s", error_message(r)); | ||||
| 		uprintf("Failed to create %s 'lost+found' dir: %s", extfs_name, error_message(r)); | ||||
| 		goto out; | ||||
| 	} | ||||
| 
 | ||||
|  | @ -956,31 +977,35 @@ BOOL FormatExt2Fs(const char* label) | |||
| 
 | ||||
| 	r = ext2fs_mark_inode_bitmap2(ext2fs->inode_map, EXT2_BAD_INO); | ||||
| 	if (r != 0) { | ||||
| 		uprintf("Could not set ext2fs inode bitmaps: %s", error_message(r)); | ||||
| 		uprintf("Could not set inode bitmaps: %s", error_message(r)); | ||||
| 		goto out; | ||||
| 	} | ||||
| 	ext2fs_inode_alloc_stats(ext2fs, EXT2_BAD_INO, 1); | ||||
| 	r = ext2fs_update_bb_inode(ext2fs, NULL); | ||||
| 	if (r != 0) { | ||||
| 		uprintf("Could not set ext2fs inode stats:%s", error_message(r)); | ||||
| 		uprintf("Could not set inode stats: %s", error_message(r)); | ||||
| 		goto out; | ||||
| 	} | ||||
| 
 | ||||
| 	// Create the journal
 | ||||
| 	journal_size = ext2fs_default_journal_size(ext2fs_blocks_count(ext2fs->super)); | ||||
| 	journal_size /= 2;	// That journal init is really killing us!
 | ||||
| 	uprintf("Creating journal (%d blocks)", journal_size); | ||||
| 	// Even with EXT2_MKJOURNAL_LAZYINIT, this call is absolutely dreadful in terms of speed...
 | ||||
| 	r = ext2fs_add_journal_inode(ext2fs, journal_size, EXT2_MKJOURNAL_NO_MNT_CHECK | EXT2_MKJOURNAL_LAZYINIT); | ||||
| 	if (r != 0) { | ||||
| 		uprintf("Could not create Journal: %s", error_message(r)); | ||||
| 		goto out; | ||||
| 	if (version >= 3) { | ||||
| 		// Create the journal
 | ||||
| 		ext2_percent_start = 50.0f; | ||||
| 		journal_size = ext2fs_default_journal_size(ext2fs_blocks_count(ext2fs->super)); | ||||
| 		journal_size /= 2;	// That journal init is really killing us!
 | ||||
| 		uprintf("Creating %d journal blocks:", journal_size); | ||||
| 		// Even with EXT2_MKJOURNAL_LAZYINIT, this call is absolutely dreadful in terms of speed...
 | ||||
| 		r = ext2fs_add_journal_inode(ext2fs, journal_size, EXT2_MKJOURNAL_NO_MNT_CHECK | EXT2_MKJOURNAL_LAZYINIT); | ||||
| 		uprintfs("\r\n"); | ||||
| 		if (r != 0) { | ||||
| 			uprintf("Could not create %s journal: %s", extfs_name, error_message(r)); | ||||
| 			goto out; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// Finally we can call close() to get the file system gets created
 | ||||
| 	r = ext2fs_close(ext2fs); | ||||
| 	if (r != 0) { | ||||
| 		uprintf("Could not create ext3 volume: %s", error_message(r)); | ||||
| 		uprintf("Could not create %s volume: %s", extfs_name, error_message(r)); | ||||
| 		goto out; | ||||
| 	} | ||||
| 	UPDATE_PERCENT(MSG_217, 100.0f); | ||||
|  | @ -2320,6 +2345,16 @@ DWORD WINAPI FormatThread(void* param) | |||
| 		uprintf("Logical drive was not found!");	// We try to continue even if this fails, just in case
 | ||||
| 	CHECK_FOR_USER_CANCEL; | ||||
| 
 | ||||
| 	// Format Casper partition if required. Do it before we format anything with
 | ||||
| 	// a file system that Windows will recognize, to avoid concurrent access.
 | ||||
| 	if (extra_partitions & XP_CASPER) { | ||||
| 		if (!FormatExtFs("casper-rw", ReadSetting32(SETTING_USE_EXTFS_VERSION))) { | ||||
| 			if (!IS_ERROR(FormatStatus)) | ||||
| 				FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; | ||||
| 			goto out; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// If FAT32 is requested and we have a large drive (>32 GB) use
 | ||||
| 	// large FAT32 format, else use MS's FormatEx.
 | ||||
| 	// TODO: We'll want a single call for ext2/ext3/ext4, large FAT32 and everything (after we switch to VDS?)
 | ||||
|  | @ -2330,11 +2365,6 @@ DWORD WINAPI FormatThread(void* param) | |||
| 		goto out; | ||||
| 	} | ||||
| 
 | ||||
| 	// Format Casper partition if it exists
 | ||||
| 	if (extra_partitions & XP_CASPER) { | ||||
| 		ret = FormatExt2Fs("casper-rw"); | ||||
| 	} | ||||
| 
 | ||||
| 	// Thanks to Microsoft, we must fix the MBR AFTER the drive has been formatted
 | ||||
| 	if ((partition_type == PARTITION_STYLE_MBR) || ((boot_type != BT_NON_BOOTABLE) && (partition_type == PARTITION_STYLE_GPT))) { | ||||
| 		PrintInfoDebug(0, MSG_228);	// "Writing master boot record..."
 | ||||
|  |  | |||
|  | @ -1860,10 +1860,12 @@ out: | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| #ifdef RUFUS_TEST | ||||
| extern BOOL FormatExtFs(const char* label, uint32_t version); | ||||
| #endif | ||||
| /*
 | ||||
|  * Main dialog callback | ||||
|  */ | ||||
| extern BOOL FormatExt2Fs(const char* label); | ||||
| static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) | ||||
| { | ||||
| 	static DWORD DeviceNum = 0; | ||||
|  | @ -1896,7 +1898,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA | |||
| 	case WM_COMMAND: | ||||
| #ifdef RUFUS_TEST | ||||
| 		if (LOWORD(wParam) == IDC_TEST) { | ||||
| 			FormatExt2Fs("casper-rw"); | ||||
| 			FormatExtFs("casper-rw", 3); | ||||
| 			break; | ||||
| 		} | ||||
| #endif | ||||
|  |  | |||
							
								
								
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							|  | @ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL | |||
| IDD_DIALOG DIALOGEX 12, 12, 232, 326 | ||||
| STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | ||||
| EXSTYLE WS_EX_ACCEPTFILES | ||||
| CAPTION "Rufus 3.6.1524" | ||||
| CAPTION "Rufus 3.6.1525" | ||||
| FONT 9, "Segoe UI Symbol", 400, 0, 0x0 | ||||
| BEGIN | ||||
|     LTEXT           "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP | ||||
|  | @ -394,8 +394,8 @@ END | |||
| // | ||||
| 
 | ||||
| VS_VERSION_INFO VERSIONINFO | ||||
|  FILEVERSION 3,6,1524,0 | ||||
|  PRODUCTVERSION 3,6,1524,0 | ||||
|  FILEVERSION 3,6,1525,0 | ||||
|  PRODUCTVERSION 3,6,1525,0 | ||||
|  FILEFLAGSMASK 0x3fL | ||||
| #ifdef _DEBUG | ||||
|  FILEFLAGS 0x1L | ||||
|  | @ -413,13 +413,13 @@ BEGIN | |||
|             VALUE "Comments", "https://akeo.ie" | ||||
|             VALUE "CompanyName", "Akeo Consulting" | ||||
|             VALUE "FileDescription", "Rufus" | ||||
|             VALUE "FileVersion", "3.6.1524" | ||||
|             VALUE "FileVersion", "3.6.1525" | ||||
|             VALUE "InternalName", "Rufus" | ||||
|             VALUE "LegalCopyright", "© 2011-2019 Pete Batard (GPL v3)" | ||||
|             VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html" | ||||
|             VALUE "OriginalFilename", "rufus-3.6.exe" | ||||
|             VALUE "ProductName", "Rufus" | ||||
|             VALUE "ProductVersion", "3.6.1524" | ||||
|             VALUE "ProductVersion", "3.6.1525" | ||||
|         END | ||||
|     END | ||||
|     BLOCK "VarFileInfo" | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| /*
 | ||||
|  * Rufus: The Reliable USB Formatting Utility | ||||
|  * Settings access, through either registry or INI file | ||||
|  * Copyright © 2015-2016 Pete Batard <pete@akeo.ie> | ||||
|  * Copyright © 2015-2019 Pete Batard <pete@akeo.ie> | ||||
|  * | ||||
|  * 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 | ||||
|  | @ -27,27 +27,26 @@ extern char* ini_file; | |||
| /*
 | ||||
|  * List of setting names used by this application | ||||
|  */ | ||||
| #define SETTING_VERBOSE_UPDATES             "VerboseUpdateCheck" | ||||
| #define SETTING_LAST_UPDATE                 "LastUpdateCheck" | ||||
| #define SETTING_UPDATE_INTERVAL             "UpdateCheckInterval" | ||||
| #define SETTING_INCLUDE_BETAS               "CheckForBetas" | ||||
| #define SETTING_COMM_CHECK                  "CommCheck64" | ||||
| #define SETTING_LOCALE                      "Locale" | ||||
| #define SETTING_DISABLE_LGP                 "DisableLGP" | ||||
| #define SETTING_DISABLE_SECURE_BOOT_NOTICE  "DisableSecureBootNotice" | ||||
| 
 | ||||
| #define SETTING_ADVANCED_MODE               "AdvancedMode" | ||||
| #define SETTING_ADVANCED_MODE_DEVICE        "ShowAdvancedDriveProperties" | ||||
| #define SETTING_ADVANCED_MODE_FORMAT        "ShowAdvancedFormatOptions" | ||||
| #define SETTING_PRESERVE_TIMESTAMPS         "PreserveTimestamps" | ||||
| #define SETTING_USE_PROPER_SIZE_UNITS       "UseProperSizeUnits" | ||||
| #define SETTING_ENABLE_USB_DEBUG            "EnableUsbDebug" | ||||
| #define SETTING_COMM_CHECK                  "CommCheck64" | ||||
| #define SETTING_DISABLE_FAKE_DRIVES_CHECK   "DisableFakeDrivesCheck" | ||||
| #define SETTING_DISABLE_LGP                 "DisableLGP" | ||||
| #define SETTING_DISABLE_SECURE_BOOT_NOTICE  "DisableSecureBootNotice" | ||||
| #define SETTING_ENABLE_FILE_INDEXING        "EnableFileIndexing" | ||||
| #define SETTING_ENABLE_USB_DEBUG            "EnableUsbDebug" | ||||
| #define SETTING_ENABLE_VMDK_DETECTION       "EnableVmdkDetection" | ||||
| #define SETTING_ENABLE_WIN_DUAL_EFI_BIOS    "EnableWindowsDualUefiBiosMode" | ||||
| #define SETTING_FORCE_LARGE_FAT32_FORMAT    "ForceLargeFat32Formatting" | ||||
| #define SETTING_ENABLE_VMDK_DETECTION       "EnableVmdkDetection" | ||||
| #define SETTING_ENABLE_FILE_INDEXING        "EnableFileIndexing" | ||||
| 
 | ||||
| #define SETTING_INCLUDE_BETAS               "CheckForBetas" | ||||
| #define SETTING_LAST_UPDATE                 "LastUpdateCheck" | ||||
| #define SETTING_LOCALE                      "Locale" | ||||
| #define SETTING_UPDATE_INTERVAL             "UpdateCheckInterval" | ||||
| #define SETTING_USE_EXTFS_VERSION           "UseExtFsVersion" | ||||
| #define SETTING_USE_PROPER_SIZE_UNITS       "UseProperSizeUnits" | ||||
| #define SETTING_PRESERVE_TIMESTAMPS         "PreserveTimestamps" | ||||
| #define SETTING_VERBOSE_UPDATES             "VerboseUpdateCheck" | ||||
| 
 | ||||
| 
 | ||||
| static __inline BOOL CheckIniKey(const char* key) { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue