From a2cbaa05f9720b15eb1eee7a05893ab992c289b5 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Thu, 18 Sep 2014 15:15:52 -0500 Subject: Fix bolt on OpenBSD. OpenBSD does not include a UBC kernel and writes must be synchronized with the msync(2) syscall. In addition, the NoSync field of the DB struct should be ignored on OpenBSD, since unlike other platforms, missing msyncs will result in data corruption. Depends on PR #258. Fixes #257. --- bolt_openbsd.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 bolt_openbsd.go (limited to 'bolt_openbsd.go') diff --git a/bolt_openbsd.go b/bolt_openbsd.go new file mode 100644 index 0000000..7c1bef1 --- /dev/null +++ b/bolt_openbsd.go @@ -0,0 +1,29 @@ +package bolt + +import ( + "syscall" + "unsafe" +) + +const ( + msAsync = 1 << iota // perform asynchronous writes + msSync // perform synchronous writes + msInvalidate // invalidate cached data +) + +var odirect int + +func msync(db *DB) error { + _, _, errno := syscall.Syscall(syscall.SYS_MSYNC, uintptr(unsafe.Pointer(db.data)), uintptr(db.datasz), msInvalidate) + if errno != 0 { + return errno + } + return nil +} + +func fdatasync(db *DB) error { + if db.data != nil { + return msync(db) + } + return db.file.Sync() +} -- cgit v1.2.3