diff --git a/vfs/lock.go b/vfs/lock.go index e83530e..d7aa446 100644 --- a/vfs/lock.go +++ b/vfs/lock.go @@ -1,3 +1,5 @@ +//go:build !sqlite3_nolock + package vfs import ( diff --git a/vfs/nolock.go b/vfs/nolock.go new file mode 100644 index 0000000..a1f6236 --- /dev/null +++ b/vfs/nolock.go @@ -0,0 +1,22 @@ +//go:build sqlite3_nolock + +package vfs + +const ( + _PENDING_BYTE = 0x40000000 + _RESERVED_BYTE = (_PENDING_BYTE + 1) + _SHARED_FIRST = (_PENDING_BYTE + 2) + _SHARED_SIZE = 510 +) + +func (f *vfsFile) Lock(lock LockLevel) error { + return nil +} + +func (f *vfsFile) Unlock(lock LockLevel) error { + return nil +} + +func (f *vfsFile) CheckReservedLock() (bool, error) { + return false, nil +} diff --git a/vfs/os_nolock.go b/vfs/os_nolock.go new file mode 100644 index 0000000..499cce6 --- /dev/null +++ b/vfs/os_nolock.go @@ -0,0 +1,28 @@ +//go:build sqlite3_nolock && solaris && !illumos + +package vfs + +import ( + "os" + "time" +) + +func osUnlock(file *os.File, start, len int64) _ErrorCode { + return _OK +} + +func osLock(file *os.File, typ int16, start, len int64, timeout time.Duration, def _ErrorCode) _ErrorCode { + return _OK +} + +func osReadLock(file *os.File, start, len int64, timeout time.Duration) _ErrorCode { + return _OK +} + +func osWriteLock(file *os.File, start, len int64, timeout time.Duration) _ErrorCode { + return _OK +} + +func osCheckLock(file *os.File, start, len int64) (bool, _ErrorCode) { + return false, _OK +} diff --git a/vfs/os_std_access.go b/vfs/os_std_access.go new file mode 100644 index 0000000..d6e8fd1 --- /dev/null +++ b/vfs/os_std_access.go @@ -0,0 +1,36 @@ +//go:build !unix + +package vfs + +import ( + "io/fs" + "os" +) + +const ( + _S_IREAD = 0400 + _S_IWRITE = 0200 + _S_IEXEC = 0100 +) + +func osAccess(path string, flags AccessFlag) error { + fi, err := os.Stat(path) + if err != nil { + return err + } + if flags == ACCESS_EXISTS { + return nil + } + + var want fs.FileMode = _S_IREAD + if flags == ACCESS_READWRITE { + want |= _S_IWRITE + } + if fi.IsDir() { + want |= _S_IEXEC + } + if fi.Mode()&want != want { + return fs.ErrPermission + } + return nil +} diff --git a/vfs/os_other.go b/vfs/os_std_alloc.go similarity index 76% rename from vfs/os_other.go rename to vfs/os_std_alloc.go index 23fe3b4..619061d 100644 --- a/vfs/os_other.go +++ b/vfs/os_std_alloc.go @@ -7,10 +7,6 @@ import ( "os" ) -func osSync(file *os.File, fullsync, dataonly bool) error { - return file.Sync() -} - func osAllocate(file *os.File, size int64) error { off, err := file.Seek(0, io.SeekEnd) if err != nil { diff --git a/vfs/os_std_mode.go b/vfs/os_std_mode.go new file mode 100644 index 0000000..dfee7a4 --- /dev/null +++ b/vfs/os_std_mode.go @@ -0,0 +1,14 @@ +//go:build !unix + +package vfs + +import "os" + +func osSetMode(file *os.File, modeof string) error { + fi, err := os.Stat(modeof) + if err != nil { + return err + } + file.Chmod(fi.Mode()) + return nil +} diff --git a/vfs/os_std_open.go b/vfs/os_std_open.go new file mode 100644 index 0000000..ab2242e --- /dev/null +++ b/vfs/os_std_open.go @@ -0,0 +1,12 @@ +//go:build !windows + +package vfs + +import ( + "io/fs" + "os" +) + +func osOpenFile(name string, flag int, perm fs.FileMode) (*os.File, error) { + return os.OpenFile(name, flag, perm) +} diff --git a/vfs/os_std_sync.go b/vfs/os_std_sync.go new file mode 100644 index 0000000..45dba18 --- /dev/null +++ b/vfs/os_std_sync.go @@ -0,0 +1,9 @@ +//go:build !linux && (!darwin || sqlite3_bsd) + +package vfs + +import "os" + +func osSync(file *os.File, fullsync, dataonly bool) error { + return file.Sync() +} diff --git a/vfs/os_unix.go b/vfs/os_unix.go index 345bbbf..cba8ef5 100644 --- a/vfs/os_unix.go +++ b/vfs/os_unix.go @@ -3,7 +3,6 @@ package vfs import ( - "io/fs" "os" "syscall" "time" @@ -11,10 +10,6 @@ import ( "golang.org/x/sys/unix" ) -func osOpenFile(name string, flag int, perm fs.FileMode) (*os.File, error) { - return os.OpenFile(name, flag, perm) -} - func osAccess(path string, flags AccessFlag) error { var access uint32 // unix.F_OK switch flags { diff --git a/vfs/os_windows.go b/vfs/os_windows.go index 5017a36..6e1f9e0 100644 --- a/vfs/os_windows.go +++ b/vfs/os_windows.go @@ -25,37 +25,6 @@ func osOpenFile(name string, flag int, perm fs.FileMode) (*os.File, error) { return os.NewFile(uintptr(r), name), nil } -func osAccess(path string, flags AccessFlag) error { - fi, err := os.Stat(path) - if err != nil { - return err - } - if flags == ACCESS_EXISTS { - return nil - } - - var want fs.FileMode = windows.S_IRUSR - if flags == ACCESS_READWRITE { - want |= windows.S_IWUSR - } - if fi.IsDir() { - want |= windows.S_IXUSR - } - if fi.Mode()&want != want { - return fs.ErrPermission - } - return nil -} - -func osSetMode(file *os.File, modeof string) error { - fi, err := os.Stat(modeof) - if err != nil { - return err - } - file.Chmod(fi.Mode()) - return nil -} - func osGetSharedLock(file *os.File, timeout time.Duration) _ErrorCode { // Acquire the PENDING lock temporarily before acquiring a new SHARED lock. rc := osReadLock(file, _PENDING_BYTE, 1, timeout)