Skip to content

Commit d33ad2d

Browse files
callthingsoffqmuntal
authored andcommitted
syscall: support O_SYNC flag for os.OpenFile on windows
os.OpenFile on windows did not use the O_SYNC flag. This meant that even if the user set O_SYNC, os.OpenFile would ignore it. This change adds a new flag FILE_FLAG_WRITE_THROUGH, which is the equivalent of O_SYNC flag on Linux and is documented in https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea Fixes #35358 Change-Id: Ib338caed5bb2f215723bfe30a2551a83998d92c9 GitHub-Last-Rev: 82c6275 GitHub-Pull-Request: #64027 Reviewed-on: https://go-review.googlesource.com/c/go/+/541015 Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]> Run-TryBot: Jes Cok <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: David Chase <[email protected]> Reviewed-by: Quim Muntal <[email protected]>
1 parent 1d187fd commit d33ad2d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/syscall/syscall_windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ func Open(path string, mode int, perm uint32) (fd Handle, err error) {
409409
// Necessary for opening directory handles.
410410
attrs |= FILE_FLAG_BACKUP_SEMANTICS
411411
}
412+
if mode&O_SYNC != 0 {
413+
const _FILE_FLAG_WRITE_THROUGH = 0x80000000
414+
attrs |= _FILE_FLAG_WRITE_THROUGH
415+
}
412416
return CreateFile(pathp, access, sharemode, sa, createmode, attrs, 0)
413417
}
414418

0 commit comments

Comments
 (0)