| 29 | int Ext2StartSrv(); |
| 30 | |
| 31 | HANDLE Ext2OpenPipe(CHAR *PipeName) |
| 32 | { |
| 33 | DWORD rc; |
| 34 | |
| 35 | if (g_hPipe != NULL && g_hPipe != INVALID_HANDLE_VALUE) { |
| 36 | return g_hPipe; |
| 37 | } |
| 38 | |
| 39 | retry: |
| 40 | |
| 41 | // open pipe (created by Ext2Srv) |
| 42 | g_hPipe = CreateFile(PipeName, |
| 43 | GENERIC_READ | GENERIC_WRITE, |
| 44 | 0, NULL, OPEN_EXISTING, 0, NULL); |
| 45 | |
| 46 | // exit if the pipe handle is valid. |
| 47 | if (g_hPipe == INVALID_HANDLE_VALUE) { |
| 48 | |
| 49 | // exit if an error other than ERROR_PIPE_BUSY occurs. |
| 50 | rc = GetLastError(); |
| 51 | if (rc != ERROR_PIPE_BUSY) { |
| 52 | return NULL; |
| 53 | } |
| 54 | |
| 55 | // all pipe instances are busy, so wait for 20 seconds. |
| 56 | if (!WaitNamedPipe(PipeName, 20000)) { |
| 57 | return NULL; |
| 58 | } |
| 59 | |
| 60 | Ext2StartSrv(); |
| 61 | |
| 62 | goto retry; |
| 63 | } |
| 64 | |
| 65 | return g_hPipe; |
| 66 | } |
| 67 | |
| 68 | void Ext2ClosePipe() |
| 69 | { |
no test coverage detected