Skip to content
This repository has been archived by the owner. It is now read-only.

fixed write data overwrites the old data when open a file with O_APPEND flag. #229

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
5 participants
@runner-mei
Copy link

commented Oct 28, 2011

fixed write data overwrites the old data when open a file with O_APPEND flag.

@bnoordhuis

This comment has been minimized.

Copy link
Contributor

commented Oct 28, 2011

@piscisaureus and @igorzi: Looks OK to me. Test passes on UNIX.

@igorzi

This comment has been minimized.

Copy link

commented Oct 28, 2011

Looks good.

@bnoordhuis

This comment has been minimized.

Copy link
Contributor

commented Oct 28, 2011

@runner-mei: Thanks, I'll merge it. Can you sign the CLA?

@runner-mei

This comment has been minimized.

Copy link
Author

commented Oct 31, 2011

how to sign the CLA?

@mmalecki

This comment has been minimized.

Copy link

commented Oct 31, 2011

Go to this part, fill in your details and submit it (there are other options, like printing, signing and e-mailing it, but doing it electronically is the most convenient one).

@runner-mei

This comment has been minimized.

Copy link
Author

commented Nov 1, 2011

I sign it

@runner-mei

This comment has been minimized.

Copy link
Author

commented Nov 1, 2011

Note that this patch does not completely solve the problem, when the call fs__write with offset != -1, there will still be the problem.

@piscisaureus

This comment has been minimized.

Copy link

commented Nov 1, 2011

I don't like the patch. We should specify the correct flags for CreateFile instead. From a user comment at the
CreateFile documentation page:

Opening File for APPEND access

You can get atomic append on local files by opening a file with FILE_APPEND_DATA access and without FILE_WRITE_DATA access. If you do this then all writes will ignore the the current file pointer and be done at the end-of file.

HANDLE hFile = CreateFile(TEXT("c:\\file.txt"), FILE_APPEND_DATA , FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

The append behavior is properly synchronized between multiple writes (with or without multiple handles), where the typical way I've seen this implemented (by seeking to EOF and then writing) has a race condition if multiple threads / processes are appending to the same file.

This behavior is documented in Windows Driver Kit / Device and Driver Technologies / Installable File System / Reference / IO Manager Routines / IoCreateFileSpecifyDeviceObject

@runner-mei

This comment has been minimized.

Copy link
Author

commented Nov 3, 2011

Oh, you have a better way, then I closed it. Please fix it as soon as possible.

@runner-mei runner-mei closed this Nov 3, 2011

@piscisaureus piscisaureus reopened this Nov 4, 2011

@igorzi

This comment has been minimized.

Copy link

commented Nov 4, 2011

This was landed in fe97c4d.

@igorzi igorzi closed this Nov 4, 2011

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.