Does file add to file with Windows / NTFS?

If I write a simple text log file from several processes, can they overwrite / corrupt each other's records?

(Basically, this question is. Is the append file atomic on UNIX? But for Windows / NTFS.)

+3
source share
4 answers

Even if the append is atomic (I don't think so), it may not give you the results you need. For example, if the log contains a timestamp, it seems reasonable to expect the addition of later logs after older logs. With concurrency, this guarantee is not fulfilled - if several processes are waiting to write to the same file, any of them can get a write lock, and not just the oldest of them. In this way, logs can be recorded from a sequence.

, , , , . , . , , , , , .

+2

. FILE_APPEND_DATA ( WDK). FILE_WRITE_DATA, . FILE_WRITE_DATA, append write (Offset = FILE_WRITE_TO_END_OF_FILE OffsetHigh = -1 WDK).

. . 0, . , .

+12

MSDN :

CreateFile, , , , . . , (dwShareMode ), , , , , . .

, , , CreateFile.

, CreateFile, File.Open, , , .

Obviously, you will have to add code to your processes to deal with a situation where they cannot gain exclusive access to the log file.

+1
source

No, it is not. If you need it, Transactional NTFS on Windows Vista / 7.

0
source

Source: https://habr.com/ru/post/1749816/


All Articles