Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: O_SYNC not utilized in os.OpenFile() on Windows #35358

aschmahmann opened this issue Nov 4, 2019 · 1 comment


Copy link

@aschmahmann aschmahmann commented Nov 4, 2019

While Linux systems are able to pass their low level flags directly into os.OpenFile on Windows os.OpenFile takes "invented values"

const (
// Invented values to support what package os expects.
O_RDONLY = 0x00000
O_WRONLY = 0x00001
O_RDWR = 0x00002
O_CREAT = 0x00040
O_EXCL = 0x00080
O_NOCTTY = 0x00100
O_TRUNC = 0x00200
O_NONBLOCK = 0x00800
O_APPEND = 0x00400
O_SYNC = 0x01000
O_ASYNC = 0x02000
O_CLOEXEC = 0x80000

These invented values are then checked against a subset of the features that Windows actually supports in syscall.Open

func Open(path string, mode int, perm uint32) (fd Handle, err error) {

Despite Windows supporting FILE_FLAG_WRITE_THROUGH (very close to O_SYNC on Linux) the Open function does not check for O_SYNC. This is unexpected behavior as developers would expect the O_SYNC flag on Windows to work since it can perform synchronous writes.

Some ways to resolve this unexpected behavior include:

  • Adding a check for O_SYNC in syscall.Open in syscall_windows.go
  • Having syscall.Open perform on Windows the same way it does on Linux, by passing in file flags directly
    • Note: This solution would also help with #34681
@aschmahmann aschmahmann changed the title os: O_SYNC not utilized in os.OpenFile() os: O_SYNC not utilized in os.OpenFile() on Windows Nov 4, 2019

This comment has been minimized.

Copy link

@networkimprov networkimprov commented Nov 5, 2019

@gopherbot gopherbot added the OS-Windows label Nov 5, 2019
@FiloSottile FiloSottile added this to the Go1.15 milestone Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
4 participants
You can’t perform that action at this time.