I should write 1024 files on disk. The content of files are a simple counter. When I write for example 64 files, every thing is OK but when the number of file increases, the content of file are corrupted. The procedure is as follow:
A thread reads buffers with 32KB length from a FIFO. FIFO is implemented using Link List. In this thread, the read data is written on disk. The write procedure is as follow:
char path[MAX_PATH+1];
char ch_itoa[8];
strcpy(path, "d:\\counter\\");
itoa(class_pointer->m_startWriteLL->index, ch_itoa, 10);
strcat(path, ch_itoa);
strcat(path, ".bin");
HANDLE fHandle;
fHandle = CreateFile(CA2W(path), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
DWORD dwPos = SetFilePointer(fHandle, 0, NULL, FILE_END);
DWORD dwBytes = class_pointer->m_startWriteLL->size;
bool bRet = LockFile(fHandle, dwPos, 0, dwBytes, 0);
WriteFile(fHandle, class_pointer->m_startWriteLL->data, dwBytes, &dwBytesWritten, NULL);
bRet = UnlockFile(fHandle, dwPos, 0, dwBytes, 0);
CloseHandle(fHandle);
At first I open appropriate file and then seek to the end of file, then I write data (32 KB) to the file and finally I close file. At next time, for writing new data to the file, this procedure is repeated. All of 1024 files are written as above. As I mentioned, when the number of files is little, there is no problem but when I should write data to 1024 files, files are corrupted. I should mention that at each time, just one file is opened for writing. Can any body say me why there is corruption? What is the solution?
[edit]Code block added - OriginalGriff[/edit]