Skip to content

Commit

Permalink
[ui] progress bar improvements
Browse files Browse the repository at this point in the history
* progress bar now reflects actual completion of process more closely
* dropped the use of UM_FORMAT_PROGRESS and introduced UpdateProgress() instead
* also reduced the number of rw test patterns from 4 to 2
  • Loading branch information
pbatard committed Dec 9, 2011
1 parent 4ce6a1f commit 17132c3
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 71 deletions.
12 changes: 6 additions & 6 deletions src/badblocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,14 @@ static void print_status(void)
percent = calc_percent((unsigned long) currently_testing,
(unsigned long) num_blocks);
percent = (percent/2.0f) + ((cur_op==OP_READ)? 50.0f : 0.0f);
PrintStatus(0, "PASS %d/%d(%c): %6.2f%% done. (%d/%d/%d errors)",
PrintStatus(0, "BB PASS %d/%d(%c): %0.2f%% done. (%d/%d/%d errors)",
cur_pattern, nr_pattern,
(cur_op==OP_READ)?'R':'W',
percent,
num_read_errors,
num_write_errors,
num_corruption_errors);
PostMessage(hMainDialog, UM_FORMAT_PROGRESS, (WPARAM)(DWORD)percent, (LPARAM)0);
UpdateProgress(OP_BADBLOCKS, (((cur_pattern-1)*100.0f) + percent) / nr_pattern);
}

static void CALLBACK alarm_intr(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
Expand Down Expand Up @@ -567,7 +567,7 @@ static unsigned int test_ro (HANDLE hDrive, blk_t last_block,
static unsigned int test_rw(HANDLE hDrive, blk_t last_block, int block_size, blk_t first_block, unsigned int blocks_at_once)
{
unsigned char *buffer = NULL, *read_buffer;
const unsigned int patterns[] = {0xaa, 0x55, 0xff, 0x00};
const unsigned int patterns[] = EXT2_RW_PATTERNS;
const unsigned int *pattern;
int i, tryout, got, pat_idx;
unsigned int bb_count = 0;
Expand Down Expand Up @@ -766,7 +766,7 @@ static unsigned int test_nd(HANDLE hDrive, blk_t last_block,
nr_pattern = t_flag;
} else {
pattern = patterns;
nr_pattern = sizeof(patterns) / sizeof(patterns[0]);
nr_pattern = ARRAYSIZE(patterns);
}
for (pat_idx = 0; pat_idx < nr_pattern; pat_idx++) {
pattern_fill(test_base, pattern[pat_idx],
Expand Down Expand Up @@ -961,9 +961,9 @@ BOOL BadBlocks(HANDLE hPhysicalDrive, ULONGLONG disk_size, int block_size,
}
cancel_ops = 0;
/* use a timer to update status every second */
SetTimer(hMainDialog, BADBLOCK_TIMER_ID, 1000, alarm_intr);
SetTimer(hMainDialog, TID_BADBLOCKS_UPDATE, 1000, alarm_intr);
report->bb_count = test_func(hPhysicalDrive, last_block, block_size, first_block, EXT2_BLOCKS_AT_ONCE);
KillTimer(hMainDialog, BADBLOCK_TIMER_ID);
KillTimer(hMainDialog, TID_BADBLOCKS_UPDATE);
free(t_patts);
free(bb_list->list);
free(bb_list);
Expand Down
1 change: 1 addition & 0 deletions src/badblocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef struct ext2_struct_u32_iterate *ext2_u32_iterate;
#define EXT2_BAD_BLOCKS_THRESHOLD 256
#define EXT2_BLOCKS_AT_ONCE 64
#define EXT2_SYS_PAGE_SIZE 4096
#define EXT2_RW_PATTERNS {0xaa, 0x55}

enum test_types {
BADBLOCKS_RO, /* Read-only */
Expand Down
50 changes: 34 additions & 16 deletions src/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,48 @@
*/
DWORD FormatStatus;
badblocks_report report;
static float format_percent = 0.0f;
static int task_number = 0;
/* Number of steps for each FS for FCC_STRUCTURE_PROGRESS */
const int nb_steps[FS_MAX] = { 4, 4, 11, 9 };

/*
* FormatEx callback. Return FALSE to halt operations
*/
static BOOLEAN __stdcall FormatExCallback(FILE_SYSTEM_CALLBACK_COMMAND Command, DWORD Action, PVOID pData)
{
DWORD* percent;
int task_number = 0;

if (IS_ERROR(FormatStatus))
return FALSE;

switch(Command) {
case FCC_PROGRESS:
// TODO: send this percentage to the status bar
percent = (DWORD*)pData;
PostMessage(hMainDialog, UM_FORMAT_PROGRESS, (WPARAM)*percent, (LPARAM)0);
uprintf("%d percent completed.\n", *percent);
format_percent = 1.0f * (*percent);
UpdateProgress(OP_FORMAT_LONG, format_percent);
break;
case FCC_STRUCTURE_PROGRESS: // No progress on quick format
uprintf("Format task %d/? completed.\n", ++task_number);
uprintf("Format task %d/%d completed.\n", ++task_number,
nb_steps[ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem))]);
// TODO: figure out likely values
format_percent += 100.0f / (1.0f * nb_steps[ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem))]);
UpdateProgress(OP_FORMAT_QUICK, format_percent);
break;
case FCC_DONE:
if(*(BOOLEAN*)pData == FALSE) {
uprintf("Error while formatting.\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_GEN_FAILURE;
}
UpdateProgress(OP_FORMAT_DONE, 100.0f);
break;
case FCC_DONE_WITH_STRUCTURE: // We get this message when formatting Small FAT16
// pData Seems to be a struct with at least one (32 BIT!!!) string pointer to the size in MB
uprintf("Done with that sort of things: Action=%d pData=%0p\n", Action, pData);
DumpBufferHex(pData, 8);
uprintf("Volume size: %s MB\n", (char*)(LONG_PTR)(*(ULONG32*)pData));
UpdateProgress(OP_FORMAT_DONE, 100.0f);
break;
case FCC_INCOMPATIBLE_FILE_SYSTEM:
uprintf("Incompatible File System\n");
Expand Down Expand Up @@ -151,6 +161,8 @@ static BOOL FormatDrive(char DriveLetter)
}
GetWindowTextW(hLabel, wLabel, ARRAYSIZE(wLabel));
uprintf("Using cluster size: %d bytes\n", ComboBox_GetItemData(hClusterSize, ComboBox_GetCurSel(hClusterSize)));
format_percent = 0.0f;
task_number = 0;
pfFormatEx(wDriveRoot, SelectedDrive.Geometry.MediaType, wFSType, wLabel,
IsChecked(IDC_QUICKFORMAT), (ULONG)ComboBox_GetItemData(hClusterSize, ComboBox_GetCurSel(hClusterSize)),
FormatExCallback);
Expand Down Expand Up @@ -355,18 +367,20 @@ void __cdecl FormatThread(void* param)
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;
if (report.bb_count) {
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",
MB_ABORTRETRYIGNORE|MB_ICONWARNING)) {
case IDRETRY:
goto bb_retry;
case IDABORT:
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANCELLED;
goto out;
}
}
safe_unlockclose(hLogicalVolume);
}
Expand All @@ -378,11 +392,13 @@ void __cdecl FormatThread(void* param)
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT;
goto out;
}
UpdateProgress(OP_ZERO_MBR, -1.0f);

if (!CreatePartition(hPhysicalDrive)) {
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_PARTITION_FAILURE;
goto out;
}
UpdateProgress(OP_PARTITION, -1.0f);

// Make sure we can access the volume again before trying to format it
for (i=0; i<10; i++) {
Expand Down Expand Up @@ -416,6 +432,7 @@ void __cdecl FormatThread(void* param)
// Errorcode has already been set
goto out;
}
UpdateProgress(OP_FIX_MBR, -1.0f);

if (IsChecked(IDC_DOS)) {
// We must have a lock to modify the volume boot record...
Expand All @@ -432,6 +449,7 @@ void __cdecl FormatThread(void* param)
}
// ... and we must have relinquished that lock to write the MS-DOS files
safe_unlockclose(hLogicalVolume);
UpdateProgress(OP_DOS, -1.0f);
PrintStatus(0, "Copying MS-DOS files...\n");
if (!ExtractMSDOS(drive_name)) {
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANNOT_COPY;
Expand Down
1 change: 1 addition & 0 deletions src/msdos.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ BOOL ExtractMSDOS(const char* path)
for (j=0; r && j<ARRAYSIZE(extractlist); j++) {
if (memcmp(extractlist[j], &DiskImage[FAT12_ROOTDIR_OFFSET + i*FAT_BYTES_PER_DIRENT], 8+3) == 0) {
r = ExtractFAT(i, path);
UpdateProgress(OP_DOS, -1.0f);
}
}
}
Expand Down
Loading

0 comments on commit 17132c3

Please sign in to comment.