diff options
-rw-r--r-- | src/Common/Format.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/Common/Format.c b/src/Common/Format.c index f691c78d..4363f474 100644 --- a/src/Common/Format.c +++ b/src/Common/Format.c @@ -1184,74 +1184,80 @@ BOOL ExternalFormatFs (int driveNo, int clusterSize, int fsType) StringCbCat (szCmdline, sizeof (szCmdline), szSize); } ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) ); /* Set up members of the STARTUPINFO structure. This structure specifies the STDIN and STDOUT handles for redirection. */ ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) ); siStartInfo.cb = sizeof(STARTUPINFO); siStartInfo.hStdError = hChildStd_OUT_Wr; siStartInfo.hStdOutput = hChildStd_OUT_Wr; siStartInfo.hStdInput = hChildStd_IN_Rd; siStartInfo.wShowWindow = SW_HIDE; siStartInfo.dwFlags |= STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; /* Create the child process. */ bSuccess = CreateProcess(NULL, szCmdline, // command line NULL, // process security attributes NULL, // primary thread security attributes TRUE, // handles are inherited 0, // creation flags NULL, // use parent's environment NULL, // use parent's current directory &siStartInfo, // STARTUPINFO pointer &piProcInfo); // receives PROCESS_INFORMATION if (bSuccess) { /* Unblock the format process by simulating hit on ENTER key */ DWORD dwExitCode, dwWritten; LPCSTR newLine = "\n"; - WriteFile(hChildStd_IN_Wr, (LPCVOID) newLine, 1, &dwWritten, NULL); - - /* wait for the format process to finish */ - WaitForSingleObject (piProcInfo.hProcess, INFINITE); + if (WriteFile(hChildStd_IN_Wr, (LPCVOID) newLine, 1, &dwWritten, NULL)) + { + /* wait for the format process to finish */ + WaitForSingleObject (piProcInfo.hProcess, INFINITE); + } + else + { + /* we failed to write "\n". Maybe process exited too quickly. We wait 1 second */ + WaitForSingleObject (piProcInfo.hProcess, 1000); + } /* check if it was successfull */ if (GetExitCodeProcess (piProcInfo.hProcess, &dwExitCode)) { if (dwExitCode == 0) bSuccess = TRUE; else bSuccess = FALSE; } else bSuccess = FALSE; CloseHandle (piProcInfo.hThread); CloseHandle (piProcInfo.hProcess); } CloseHandle(hChildStd_OUT_Wr); CloseHandle(hChildStd_OUT_Rd); CloseHandle(hChildStd_IN_Rd); CloseHandle(hChildStd_IN_Wr); return bSuccess; } BOOL WriteSector (void *dev, char *sector, char *write_buf, int *write_buf_cnt, __int64 *nSecNo, PCRYPTO_INFO cryptoInfo) { static __int32 updateTime = 0; (*nSecNo)++; memcpy (write_buf + *write_buf_cnt, sector, FormatSectorSize); (*write_buf_cnt) += FormatSectorSize; |