ReadFile error 31

Hi,

I've been using the readfile api to read an image of a hard disk drive which has been mounted to become a virtual disk.

It reads fine for the most part, however usually towards the end of the disk, it occasionally crashes and the readfile api keeps returning error 31, which I looked up in the error codes as "A device attached to the system is not working"

I have used several different programs to mount the image so I cant see it being a problem with the mounting program, I've used several image files and had the same problem.

I don't understand why it just stops, has anyone got any ideas?

Thanks for any help

Code attached below


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
			dwError = GetLastError();
			bResult = GetOverlappedResult(hfile,
										  nextOverlapped,
										  &byteRead,
										  FALSE) ;
			if (!bResult)
			{
				switch (dwError = GetLastError()) 
				{ 
					case ERROR_HANDLE_EOF: 
					{ 
						// Handle an end of file
						return 0;
						break;
					} 
					case ERROR_IO_INCOMPLETE:
					{
						do
						{
							bResult = GetOverlappedResult(hfile,
														 nextOverlapped,
														 &byteRead,
														 FALSE) ;
							if (!bResult)
							{
								Sleep(15);
							}
							check++;
						}while ((!bResult) && (check < 300));
						if (check == 300)
						{
							int recover = recoverDiskRead();
							if (recover != 0)
							{
								dwError = GetLastError();
								printf("Error occured reading disk before end of disk, error: %d\n",dwError);
								return 0;
							}
						}
						break;
					}


Topic archived. No new replies allowed.