void ExtDskInternal_AddSectorToTrack(EXTDSK_INTERNAL *pExtDsk, int TrackIndex, EXTDSKCHRN *pCHRN, int FillerByte, int nAllocationSize) { EXTDSK_INTERNAL_TRACK *pTrack; /* add track if it doesn't exist already. */ ExtDskInternal_AddTrack(pExtDsk, TrackIndex); if (pExtDsk!=NULL) { if (pExtDsk->pTrackList!=NULL) { if (pExtDsk->pTrackList[TrackIndex]!=NULL) { /* get pointer to track */ pTrack = pExtDsk->pTrackList[TrackIndex]; if (pTrack->NoOfSectors<=0x03e) { int SectorSize; /* get size of data for this "N" */ SectorSize = GetSectorSize(pCHRN->N); /* allocate space for sector data based on N */ pTrack->pSectorData[pTrack->NoOfSectors] = malloc(nAllocationSize); /* copy C, H, R, N. */ memcpy(&pTrack->SectorIDs[pTrack->NoOfSectors], pCHRN, sizeof(EXTDSKCHRN)); /* store size of actual data! */ pTrack->SectorIDs[pTrack->NoOfSectors].SectorSizeLow = (unsigned char)(SectorSize & 0x0ff); pTrack->SectorIDs[pTrack->NoOfSectors].SectorSizeHigh = (unsigned char)((SectorSize>>8) & 0x0ff); /* if we succeeded in allocating memory, increase number of sectors in track */ if (pTrack->pSectorData[pTrack->NoOfSectors]!=NULL) { memset(pTrack->pSectorData[pTrack->NoOfSectors], FillerByte, nAllocationSize); pTrack->NoOfSectors++; } } } }
VOID ProcessCommands( HWND hwnd, INT id, HWND hwndCtl, UINT codeNotify) { DWORD exitCode; CHAR buffer[20]; ULONG tid; ULONG units; switch (id) { case DRV_BOX: if (codeNotify == CBN_KILLFOCUS) { // // Determine sector size of chosen drive. // ComboBox_GetText(GetDlgItem(hwnd,DRV_BOX),buffer, 4); sprintf(TestDrv,"\\\\.\\"); strcat(TestDrv,buffer); TestDrv[6] = '\0'; GetSectorSize(&SectorSize,TestDrv); } break; case START_BUTTON: if (!TestFileCreated) { // // Create gauge window. // units = GetDialogBaseUnits(); Gauge = CreateWindow("static","", WS_CHILD | WS_VISIBLE | SS_BLACKFRAME, (INT)(10 * (units & 0xFFFF) / 4), (INT)(60 * (units >> 16) / 8), (INT)(150 * (units & 0xFFFF) / 4), (INT)(12 * (units >> 16) / 8), hwnd, (HMENU)(26), HInst, NULL); GaugeId = GetDlgCtrlID(Gauge); TestFileParams.TestDrive = TestDrv; TestFileParams.TestFile = TestFile; TestFileParams.Window = hwnd; ThrdHandle = CreateThread (NULL,0,(LPTHREAD_START_ROUTINE)CreateTestFile, &TestFileParams,CREATE_SUSPENDED,&tid); // // Disable controls // Button_Enable(GetDlgItem(hwnd,STOP_BUTTON), TRUE); SetFocus(GetDlgItem(hwnd,STOP_BUTTON)); Button_Enable(GetDlgItem(hwnd,START_BUTTON), FALSE); SetTimer(hwnd,TIMER_ID2,1000,(TIMERPROC)NULL); ResumeThread(ThrdHandle); sprintf(buffer,"CREATING TEST FILE"); Static_SetText(GetDlgItem(hwnd,STATUS_TEST), buffer); break; } // // Determine the test drive. // strcpy(TestDrv,"\\\\.\\"); ComboBox_GetText(GetDlgItem(hwnd,DRV_BOX),buffer, 4); strcat (TestDrv,buffer); TestDrv[6] = '\0'; // // Determine the test case. // index = Button_GetCheck(GetDlgItem(hwnd,TEST_RAD_WRITE)); index <<= 1; index |= Button_GetCheck(GetDlgItem(hwnd,VAR_RAD_RAND)); // // Update the status fields // sprintf(buffer,"%Lu",BufferSize); Static_SetText(GetDlgItem(hwnd,STATUS_BUFFER ),buffer); sprintf(buffer,"%d",IoCount); Static_SetText(GetDlgItem(hwnd,STATUS_IOCOUNT), buffer); sprintf(buffer,"%s",(index >> 1) ? "Write" : "Read"); Static_SetText(GetDlgItem(hwnd,STATUS_CASE), buffer); sprintf(buffer,"%s",(index & 0x1) ? "Random" : "Sequential"); Static_SetText(GetDlgItem(hwnd,STATUS_CASE1), buffer); sprintf(buffer,"RUNNING"); Static_SetText(GetDlgItem(hwnd,STATUS_TEST), buffer); ElapsedTime = Seconds = Minutes = Hours = Days = 0; SetTimer(hwnd,TIMER_ID,1000,(TIMERPROC)NULL); // // Gather parameters and launch the test. // Params.BufferSize = BufferSize; Params.TargetFile = TestFile; Params.Tcount = NumberIOs; RunTest = TRUE; // // Launch the thread. // ThrdHandle = CreateThread (NULL, 0, TestProc[index], &Params, CREATE_SUSPENDED, &tid ); ResumeThread(ThrdHandle); // // Disable controls // Button_Enable(GetDlgItem(hwnd,STOP_BUTTON), TRUE); SetFocus(GetDlgItem(hwnd,STOP_BUTTON)); Button_Enable(GetDlgItem(hwnd,START_BUTTON), FALSE); break; case STOP_BUTTON: if (!TestFileCreated) { // // Kill the test file create thread. // KillFileCreate = TRUE; WaitForSingleObject(ThrdHandle,INFINITE); // // Redo button enable/disable/focus // Button_Enable(GetDlgItem(hwnd,START_BUTTON), TRUE); Button_Enable(GetDlgItem(hwnd,STOP_BUTTON), FALSE); SetFocus(GetDlgItem(hwnd,START_BUTTON)); KillTimer(hwnd, TIMER_ID2); KillFileCreate = FALSE; sprintf(buffer,"STOPPED"); Static_SetText(GetDlgItem(hwnd,STATUS_TEST), buffer); DestroyWindow(Gauge); UpdateWindow(hwnd); break; } KillTimer(hwnd, TIMER_ID); // // If the thread is not running disregard it. // GetExitCodeThread(ThrdHandle,&exitCode); if (exitCode == STILL_ACTIVE) { // // Set flag to kill the threads. // RunTest = FALSE; if ((WaitForSingleObject (ThrdHandle,INFINITE)) == WAIT_FAILED) { // // TODO: Do something drastic. // } } // // Re-enable/disable buttons // Button_Enable(GetDlgItem(hwnd,START_BUTTON), TRUE); Button_Enable(GetDlgItem(hwnd,STOP_BUTTON), FALSE); SetFocus(GetDlgItem(hwnd,START_BUTTON)); sprintf(buffer,"STOPPED"); Static_SetText(GetDlgItem(hwnd,STATUS_TEST), buffer); break; case QUIT_BUTTON: case IDCANCEL: EndDialog(hwnd, id); break; default: break; }
BOOL InitDialog ( HWND hwnd, HWND hwndFocus, LPARAM lParam ) { BOOLEAN Found = FALSE; CHAR buffer[34]; DWORD bytes; HWND Drives = GetDlgItem (hwnd,DRV_BOX); PCHAR lp; UINT i = 0, NoDrives = 0; srand(GetTickCount()); Button_Enable(GetDlgItem(hwnd,STOP_BUTTON), FALSE); // // Get attached drives, filter out non-disk drives, and fill drive box. // bytes = GetLogicalDriveStrings(0,NULL); DrvStrHandle = VirtualAlloc(NULL,bytes + 1, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); GetLogicalDriveStrings( bytes, DrvStrHandle); for (lp = DrvStrHandle;*lp; ) { if (GetDriveType(lp) == DRIVE_FIXED) { ComboBox_AddString(Drives,lp); ++NoDrives; } while(*lp++); } // // Check for cmd line params passed in, and set the test drive to either // the specified drive, or to the first in the drive list. // ComboBox_SetCurSel (Drives,0); if (TestDrv[4] != '\0') { do { ComboBox_GetText(GetDlgItem(hwnd,DRV_BOX),buffer,4); if (buffer[0] == TestDrv[4]) { Found = TRUE; } else { if (++i >= NoDrives) { Found = TRUE; } else { ComboBox_SetCurSel (Drives,i); } } } while (!Found); if (i >= NoDrives) { // // Couldn't find the drive, exit with a message. // LogError("Incorrect Drive Letter in command line.",1,0); EndDialog(hwnd,0); return FALSE; } } else { ComboBox_SetCurSel (Drives,0); } // // Get the sector size for the default selection. // TestDrv[4] = '\0'; ComboBox_GetText(GetDlgItem(hwnd,DRV_BOX),buffer, 4); strcat (TestDrv,buffer); TestDrv[6] = '\0'; GetSectorSize(&SectorSize,TestDrv); // // If index is 0, use defaults, otherwise set the test according to // the cmdline passes in. // Button_SetCheck(GetDlgItem(hwnd,TEST_RAD_READ + (index >> 1)), TRUE); Button_SetCheck(GetDlgItem(hwnd,VAR_RAD_SEQ + (index & 0x01)),TRUE); // // Set buffer size. // if (BufferSize == 0) { BufferSize = 65536; NumberIOs = FILE_SIZE / BufferSize; } else { // // Verify that buffersize is a multiple of sector size, if not adjust it. // if (BufferSize % SectorSize) { BufferSize &= ~(SectorSize - 1); } NumberIOs = FILE_SIZE / BufferSize; // // Cmd line was present and has been used to config. the test. Send a message // to the start button to get things rolling. // SendMessage(hwnd,WM_COMMAND,(BN_CLICKED << 16) | START_BUTTON,(LPARAM)GetDlgItem(hwnd,START_BUTTON)); } _ultoa(BufferSize,buffer,10); Static_SetText(GetDlgItem(hwnd,BUFFER_TEXT),buffer); return(TRUE); }