diff --git a/TODO b/TODO index 3642192f..5258757f 100644 --- a/TODO +++ b/TODO @@ -1,12 +1,10 @@ -o backblock check - http://git.kernel.org/?p=fs/ext2/e2fsprogs.git;a=blob;f=misc/badblocks.c +o create a report file with failed block details when bad blocks are found o progress bar during quick format / partitioning / MS-DOS files copy o use the umount/remount trick to make the volume reappear post formatting o set keyboard according to locale in DOS o allow selection of one of the existing compatible volume (keep existing MBR) / full repartitioning (overwrite MBR) o FreeDOS integration o Enable compression for NTFS -o Bootable NTFS/exFAT? - http://sourceforge.net/projects/grub4dos/ +o Bootable NTFS/exFAT (http://sourceforge.net/projects/grub4dos)? o GPT support? o disable indexing support on NTFS? diff --git a/src/badblocks.c b/src/badblocks.c index a5a9e107..447d8667 100644 --- a/src/badblocks.c +++ b/src/badblocks.c @@ -363,10 +363,10 @@ static void print_status(void) time_end = GetTickCount(); percent = calc_percent((unsigned long) currently_testing, (unsigned long) num_blocks); - PrintStatus("%d/%d(%c): %6.2f%% done, %.0fs elapsed. " + percent = (percent/2.0f) + ((cur_op==OP_READ)? 50.0f : 0.0f); + PrintStatus(0, "PASS %d/%d(%c): %6.2f%% done, %.0fs elapsed. " "(%d/%d/%d errors)", - 2*cur_pattern - ((cur_op==OP_WRITE)?1:0), - 2*nr_pattern, + cur_pattern, nr_pattern, (cur_op==OP_READ)?'R':'W', percent, (time_end - time_start)/1000.0, @@ -398,7 +398,8 @@ static void pattern_fill(unsigned char *buffer, unsigned int pattern, for (ptr = buffer; ptr < buffer + n; ptr++) { (*ptr) = rand() % (1 << (8 * sizeof(char))); } - PrintStatus("Testing with random pattern: "); + PrintStatus(3500, "Testing with random pattern: "); + uprintf("Testing with random pattern: "); } else { bpattern[0] = 0; for (i = 0; i < sizeof(bpattern); i++) { @@ -415,7 +416,8 @@ static void pattern_fill(unsigned char *buffer, unsigned int pattern, else i--; } - PrintStatus("Testing with pattern 0x%02X", bpattern[i]); + PrintStatus(3500, "Testing with pattern 0x%02X", bpattern[i]); + uprintf("Testing with pattern 0x%02X", bpattern[i]); cur_pattern++; } } @@ -700,7 +702,7 @@ static unsigned int test_nd(HANDLE hDrive, blk_t last_block, int tryout, i; const unsigned int patterns[] = { ~0 }; const unsigned int *pattern; - int nr_pattern, pat_idx; + int pat_idx; int got, used2, written; blk_t save_currently_testing; struct saved_blk_record *test_record; @@ -965,13 +967,13 @@ BOOL BadBlocks(HANDLE hPhysicalDrive, ULONGLONG disk_size, int block_size, time_start = GetTickCount(); cancel_ops = 0; /* use a timer to update status every second */ - SetTimer(hMainDialog, EXT2_TIMER_ID, 1000, alarm_intr); + SetTimer(hMainDialog, BADBLOCK_TIMER_ID, 1000, alarm_intr); report->bb_count = test_func(hPhysicalDrive, last_block, block_size, first_block, EXT2_BLOCKS_AT_ONCE); - KillTimer(hMainDialog, EXT2_TIMER_ID); + KillTimer(hMainDialog, BADBLOCK_TIMER_ID); free(t_patts); free(bb_list->list); free(bb_list); - // TODO: report first problem block for each error + // TODO: report first problem block for each error or create a report file report->num_read_errors = num_read_errors; report->num_write_errors = num_write_errors; report->num_corruption_errors = num_corruption_errors; diff --git a/src/badblocks.h b/src/badblocks.h index 3e687665..5b035054 100644 --- a/src/badblocks.h +++ b/src/badblocks.h @@ -41,7 +41,6 @@ typedef struct ext2_struct_u32_iterate *ext2_u32_iterate; #define EXT2_BAD_BLOCKS_THRESHOLD 32 #define EXT2_BLOCKS_AT_ONCE 64 #define EXT2_SYS_PAGE_SIZE 4096 -#define EXT2_TIMER_ID 0x1000 enum test_types { BADBLOCKS_RO, /* Read-only */ diff --git a/src/format.c b/src/format.c index a4c04ca3..cc682e97 100644 --- a/src/format.c +++ b/src/format.c @@ -138,7 +138,7 @@ static BOOL FormatDrive(char DriveLetter) size_t i; wDriveRoot[0] = (WCHAR)DriveLetter; - PrintStatus("Formatting..."); + PrintStatus(0, "Formatting..."); PF_INIT_OR_OUT(FormatEx, fmifs); GetWindowTextW(hFileSystem, wFSType, ARRAYSIZE(wFSType)); @@ -323,6 +323,7 @@ void __cdecl FormatThread(void* param) HANDLE hPhysicalDrive = INVALID_HANDLE_VALUE; HANDLE hLogicalVolume = INVALID_HANDLE_VALUE; char drive_name[] = "?:"; + char bb_msg[256]; int i; hPhysicalDrive = GetDriveHandle(num, NULL, TRUE, TRUE); @@ -341,7 +342,7 @@ void __cdecl FormatThread(void* param) FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED; goto out; } - +bb_retry: if (!BadBlocks(hPhysicalDrive, SelectedDrive.DiskSize, SelectedDrive.Geometry.BytesPerSector, BADBLOCKS_RW, &report)) { uprintf("Bad blocks check failed.\n"); @@ -351,11 +352,23 @@ void __cdecl FormatThread(void* param) // TODO: should probably ClearMBR here as well goto out; } - uprintf("Check completed, %u bad blocks found. (%d/%d/%d errors)\n", - report.bb_count, report.num_read_errors, report.num_write_errors, report.num_corruption_errors); + uprintf("Check completed, %u bad block%s found. (%d/%d/%d errors)\n", + report.bb_count, (report.bb_count==1)?"":"s", + report.num_read_errors, report.num_write_errors, report.num_corruption_errors); + safe_sprintf(bb_msg, sizeof(bb_msg), "Check completed - %u bad block%s found:\n" + " %d read errors\n %d write errors\n %d corruption errors", + report.bb_count, (report.bb_count==1)?"":"s", + report.num_read_errors, report.num_write_errors, + report.num_corruption_errors); + switch(MessageBoxA(hMainDialog, bb_msg, "Bad blocks check", + report.bb_count?(MB_ABORTRETRYIGNORE|MB_ICONWARNING):(MB_OK|MB_ICONINFORMATION))) { + case IDRETRY: + goto bb_retry; + case IDABORT: + FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANCELLED; + goto out; + } safe_unlockclose(hLogicalVolume); - - // TODO: check bb_count and ask user if they want to continue } // Especially after destructive badblocks test, you must zero the MBR completely @@ -398,7 +411,7 @@ void __cdecl FormatThread(void* param) // TODO: use progress bar during MBR/FSBR/MSDOS copy // TODO: unlock/remount trick to make the volume reappear - PrintStatus("Writing master boot record...\n"); + PrintStatus(0, "Writing master boot record...\n"); if (!WriteMBR(hPhysicalDrive)) { // Errorcode has already been set goto out; @@ -412,14 +425,14 @@ void __cdecl FormatThread(void* param) FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED; goto out; } - PrintStatus("Writing partition boot record...\n"); + PrintStatus(0, "Writing partition boot record...\n"); if (!WritePBR(hLogicalVolume)) { // Errorcode has already been set goto out; } // ... and we must have relinquished that lock to write the MS-DOS files safe_unlockclose(hLogicalVolume); - PrintStatus("Copying MS-DOS files...\n"); + PrintStatus(0, "Copying MS-DOS files...\n"); if (!ExtractMSDOS(drive_name)) { FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANNOT_COPY; goto out; diff --git a/src/rufus.c b/src/rufus.c index 40f1fc25..5aad5f21 100644 --- a/src/rufus.c +++ b/src/rufus.c @@ -396,7 +396,7 @@ BOOL CreatePartition(HANDLE hDrive) BOOL r; DWORD size; - PrintStatus("Partitioning..."); + PrintStatus(0, "Partitioning..."); DriveLayoutEx->PartitionStyle = PARTITION_STYLE_MBR; DriveLayoutEx->PartitionCount = 4; // Must be multiple of 4 for MBR DriveLayoutEx->Mbr.Signature = GetTickCount(); @@ -591,7 +591,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA char str[MAX_PATH], tmp[128]; static uintptr_t format_thid = -1L; static HWND hProgress, hDOS; - static LONG ProgressStyle = 0; +// static LONG ProgressStyle = 0; static UINT uDOSChecked = BST_CHECKED; switch (message) { @@ -626,7 +626,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA hStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hMainDialog, (HMENU)IDC_STATUS, hMainInstance, NULL); // We'll switch the progressbar to marquee and back => keep a copy of current style - ProgressStyle = GetWindowLong(hProgress, GWL_STYLE); +// ProgressStyle = GetWindowLong(hProgress, GWL_STYLE); // Create the string array StrArrayCreate(&DriveID, MAX_DRIVES); StrArrayCreate(&DriveLabel, MAX_DRIVES); @@ -647,7 +647,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA // Operation may have completed in the meantime if (format_thid != -1L) { FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANCELLED; - PrintStatus("Cancelling - please wait..."); + PrintStatus(0, "Cancelling - please wait..."); } } return (INT_PTR)TRUE; @@ -664,7 +664,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA case IDC_DEVICE: switch (HIWORD(wParam)) { case CBN_SELCHANGE: - PrintStatus("%d device%s found.", ComboBox_GetCount(hDeviceList), + PrintStatus(0, "%d device%s found.", ComboBox_GetCount(hDeviceList), (ComboBox_GetCount(hDeviceList)!=1)?"s":""); PopulateProperties(ComboBox_GetCurSel(hDeviceList)); break; @@ -755,12 +755,12 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA EnableControls(TRUE); GetUSBDevices(); if (!IS_ERROR(FormatStatus)) { - PrintStatus("DONE"); + PrintStatus(0, "DONE"); } else if (SCODE_CODE(FormatStatus) == ERROR_CANCELLED) { - PrintStatus("Cancelled"); + PrintStatus(0, "Cancelled"); Notification(MSG_INFO, "Cancelled", "Operation cancelled by the user."); } else { - PrintStatus("FAILED"); + PrintStatus(0, "FAILED"); Notification(MSG_ERROR, "Error", "Error: %s", StrError(FormatStatus)); } return (INT_PTR)TRUE; diff --git a/src/rufus.h b/src/rufus.h index c6fec955..a92096bf 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -76,12 +76,18 @@ enum user_message_type { }; /* Custom notifications */ -enum MessageType { +enum notification_type { MSG_INFO, MSG_WARNING, MSG_ERROR }; +/* Timers used throughout the program */ +enum timer_id { + PRINTSTATUS_TIMER_ID = 0x1000, + BADBLOCK_TIMER_ID +}; + /* File system indexes in our FS combobox */ // TODO: FormatEx should support "NTFS", "FAT", "FAT32", "UDF", and "EXFAT" as per // http://msdn.microsoft.com/en-us/library/windows/desktop/aa819439.aspx @@ -124,7 +130,7 @@ extern RUFUS_DRIVE_INFO SelectedDrive; */ extern const char *WindowsErrorString(void); extern void DumpBufferHex(void *buf, size_t size); -extern void PrintStatus(const char *format, ...); +extern void PrintStatus(unsigned int duration, const char *format, ...); extern const char* StrError(DWORD error_code); extern void CenterDialog(HWND hDlg); extern void CreateStatusBar(void); diff --git a/src/rufus.rc b/src/rufus.rc index 0ad7f47b..f8f753c6 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -30,7 +30,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 206, 278 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW -CAPTION "Rufus v1.0.2.82 (Beta)" +CAPTION "Rufus v1.0.2.83 (Beta)" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN DEFPUSHBUTTON "Start",IDC_START,94,236,50,14 @@ -65,7 +65,7 @@ BEGIN DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP CONTROL "https://github.com/pbatard/rufus",IDC_ABOUT_RUFUS_URL, "SysLink",WS_TABSTOP,46,47,114,9 - LTEXT "Version 1.0.2 (Build 82)",IDC_STATIC,46,19,78,8 + LTEXT "Version 1.0.2 (Build 83)",IDC_STATIC,46,19,78,8 PUSHBUTTON "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP EDITTEXT IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL LTEXT "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8 @@ -164,8 +164,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,2,82 - PRODUCTVERSION 1,0,2,82 + FILEVERSION 1,0,2,83 + PRODUCTVERSION 1,0,2,83 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -182,13 +182,13 @@ BEGIN BEGIN VALUE "CompanyName", "akeo.ie" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "1.0.2.82" + VALUE "FileVersion", "1.0.2.83" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "1.0.2.82" + VALUE "ProductVersion", "1.0.2.83" END END BLOCK "VarFileInfo" diff --git a/src/stdio.c b/src/stdio.c index c14c4d9a..fac5697c 100644 --- a/src/stdio.c +++ b/src/stdio.c @@ -122,24 +122,46 @@ static char err_string[256]; return err_string; } -void PrintStatus(const char *format, ...) +/* + * Display a message on the status bar. If duration is non zero, ensures that message + * is displayed for at least duration ms regardless, regardless of any other incoming + * message + */ +static BOOL bStatusTimerArmed = FALSE; +static char szStatusMessage[256] = { 0 }; +static void CALLBACK PrintStatusTimeout(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { - char buf[256], *p = buf; + bStatusTimerArmed = FALSE; + // potentially display lower priority message that was overridden + SetDlgItemTextU(hMainDialog, IDC_STATUS, szStatusMessage); + KillTimer(hMainDialog, PRINTSTATUS_TIMER_ID); +} + +void PrintStatus(unsigned int duration, const char *format, ...) +{ + char *p = szStatusMessage; va_list args; int n; va_start(args, format); - n = safe_vsnprintf(p, sizeof(buf)-1, format, args); // room for NUL + n = safe_vsnprintf(p, sizeof(szStatusMessage)-1, format, args); // room for NUL va_end(args); - p += (n < 0)?sizeof(buf)-1:n; + p += (n < 0)?sizeof(szStatusMessage)-1:n; - while((p>buf) && (isspace(p[-1]))) + while((p>szStatusMessage) && (isspace(p[-1]))) *--p = '\0'; *p = '\0'; - SetDlgItemTextU(hMainDialog, IDC_STATUS, buf); + if ((duration) || (!bStatusTimerArmed)) { + SetDlgItemTextU(hMainDialog, IDC_STATUS, szStatusMessage); + } + + if (duration) { + SetTimer(hMainDialog, PRINTSTATUS_TIMER_ID, duration, PrintStatusTimeout); + bStatusTimerArmed = TRUE; + } } const char* StrError(DWORD error_code)