A forum for reverse engineering, OS internals and malware analysis 

 #23796  by Carlbyte
 Fri Sep 05, 2014 5:56 pm
I have multiple threads reading data from a file, sometimes it is necessary to write data to this file. If I try to open this file for reading and writing, only one thread executes functions. I read something on the internet that you can do this by sending IRP WRITE. Is it possible?
 #23799  by Vrtule
 Fri Sep 05, 2014 6:30 pm
Hello,

opening the file with FILE_SHARE_READ | FILE_SHARE_WRITE did not solve the problem? If it solved the problem, you need to synchronize the threads anyway since reading a block of data that is being modified at the same time is really not a good idea.
 #23800  by Carlbyte
 Fri Sep 05, 2014 6:39 pm
When I open the file for reading and writing since I can not even read with a second thread, even using file_share_read flag. so if I'm not mistaken, for this reason I have not tried putting the flag share_write.

but I'll try, thanks for the help ...
 #23801  by Carlbyte
 Fri Sep 05, 2014 6:50 pm
Structured data within that file (reading in position 1 and writing data in 15), I need to insert and do not edit the data within that file.

What do you think? at first I did not see a problem ...
 #23802  by Vrtule
 Fri Sep 05, 2014 7:02 pm
Show your code that opens the file.

What error are you getting?

If you are absolutely sure you never read and write the same block at once, all should be fine (I hope the Cache Manager will ensure coherency accross multiple threads).
 #23803  by Carlbyte
 Fri Sep 05, 2014 7:20 pm
I tested in user mode with FILE_SHARE_WRITE and read flag and also did not work.

The doubt is because the function and ZwWriteFile Zwreadfile has the OFFSET option, then to my mind, if you do not read and write the same data block, I think has no biggie ...
 #23804  by Carlbyte
 Fri Sep 05, 2014 7:26 pm
FileOpen with FILE_READ_DATA, FILE_WRITE_DATA "SYNCHRONIZE" and the flags FILE_SHARE READ AND WRITE ...

I open the file and try to read with the main thread of the program. The reading happens normally. I create a new thread, and pass the handle to try to run some read function is not working.

If I put just file_read_data file_share_read and then works ...
 #23805  by Vrtule
 Fri Sep 05, 2014 8:06 pm
I open the file and try to read with the main thread of the program. The reading happens normally. I create a new thread, and pass the handle to try to run some read function is not working.
Which error code are you getting?