Skip to content

Commit

Permalink
Support O_SYNC flag for os.Open on windows
Browse files Browse the repository at this point in the history
The current implementation of `os.Open` function does not use the O_SYNC
flag. This means that even if user has set the O_SYNC flag, the
`os.Open` call will ignore the `SYNC` flag. This commit fixes the issue
by adding the `FILE_FLAG_WRITE_THROUGH` which is the equivalent of
`O_SYNC` flag on linux.

Fixes golang#35358
  • Loading branch information
jarifibrahim committed May 25, 2020
1 parent f65ad0d commit d8c49d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/syscall/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func Open(path string, mode int, perm uint32) (fd Handle, err error) {
default:
createmode = OPEN_EXISTING
}
var attrs uint32 = FILE_ATTRIBUTE_NORMAL
var attrsAndFlags uint32 = FILE_ATTRIBUTE_NORMAL
if perm&S_IWRITE == 0 {
attrs = FILE_ATTRIBUTE_READONLY
if createmode == CREATE_ALWAYS {
Expand All @@ -360,6 +360,11 @@ func Open(path string, mode int, perm uint32) (fd Handle, err error) {
}
}
}

if O_SYNC {
attrsAndFlags != FILE_FLAG_WRITE_THROUGH
}

h, e := CreateFile(pathp, access, sharemode, sa, createmode, attrs, 0)
return h, e
}
Expand Down
1 change: 1 addition & 0 deletions src/syscall/types_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const (
FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000
FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
FILE_FLAG_OVERLAPPED = 0x40000000
FILE_FLAG_WRITE_THROUGH = 0x80000000

HANDLE_FLAG_INHERIT = 0x00000001
STARTF_USESTDHANDLES = 0x00000100
Expand Down

0 comments on commit d8c49d6

Please sign in to comment.