I am writing at the end of file in my filter driver and I am reading from user space.
Scenario is like whenever a rename request comes then just write the name into a log file I am opening file with FILE_APPEND_DATA. I always write at the end of file.
And at the same time there may be a read happening on the same file from user space like it reads line by line (the name of file).
Q1:: Is it possible that I may read partial data because read and write may happen at the same time. ?
Do I need synchronization between write’s? Like multiple rename may be happening, so is it possible the data I am writing may get intermingled for eg
First name of file : AAAAAA.txt
Second name of file : BBBBBB.txt
So is it possible that I get the name in file as AAAABBB(corrupted data)?
Q2:: Is it possible that file name gets intermingled?? or file system handles this?
I read about FILE_APPEND_DATA that it is atomic operation. “Write operation will not write over existing data” .And buffer in ZWWritefile will always be written to contiguous area of memory.
To test for Q2, I write an application :
Buffer size : 1MB
4 threads : Continously writing at the end of file.
1st Buffer : “AAA…” (string contains only characters ‘A’)
2nd Buffer : “BBB…” (string contains only characters ‘B’)
3rd Buffer : “CCC…” (string contains only characters ‘C’)
4th Buffer : “DDD…” (string contains only characters ‘D’)
then after all the writes are finished then read the data to check whether characters got intermingled or not. But I did not find this happening. Corruption did not happen.
To test Q1, I am writing in 1 process (1MB) with FILE_APPEND_DATA and reading from another process(1MB), I never saw the scenario where ReadFile reads less than 1MB or simply it never reads partial data. It just return from file that it reached end of file though Write is happening in another process.
So is it possible that Q1 or Q2 scenario may happen or I did the right testing?