-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…2546) File writes are cached and not immediately flushed to disk. So if there is a power loss prior to flushing it seems that some corruption occurs. This adds the FILE_FLAG_WRITE_THROUGH flag to the CreateFile call to ensure that writes go directly to the disk.
- Loading branch information
1 parent
65f37f7
commit 679248b
Showing
4 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// +build !windows | ||
|
||
package checkpoint | ||
|
||
import "os" | ||
|
||
func create(path string) (*os.File, error) { | ||
return os.Create(path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package checkpoint | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
const ( | ||
_FILE_FLAG_WRITE_THROUGH = 0x80000000 | ||
) | ||
|
||
func create(path string) (*os.File, error) { | ||
return createWriteThroughFile(path) | ||
} | ||
|
||
// createWriteThroughFile creates a file whose write operations do not go | ||
// through any intermediary cache, they go directly to disk. | ||
func createWriteThroughFile(path string) (*os.File, error) { | ||
if len(path) == 0 { | ||
return nil, syscall.ERROR_FILE_NOT_FOUND | ||
} | ||
pathp, err := syscall.UTF16PtrFromString(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
h, err := syscall.CreateFile( | ||
pathp, // Path | ||
syscall.GENERIC_READ|syscall.GENERIC_WRITE, // Access Mode | ||
uint32(syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE), // Share Mode | ||
nil, // Security Attributes | ||
syscall.CREATE_ALWAYS, // Create Mode | ||
uint32(syscall.FILE_ATTRIBUTE_NORMAL|_FILE_FLAG_WRITE_THROUGH), // Flags and Attributes | ||
0) // Template File | ||
|
||
return os.NewFile(uintptr(h), path), err | ||
} |