//go:build !sqlite3_flock

package vfs

import (
	
	
	

	
)

func osSync( *os.File,  OpenFlag,  SyncFlag) error {
	// SQLite trusts Linux's fdatasync for all fsync's.
	for {
		 := unix.Fdatasync(int(.Fd()))
		if  != unix.EINTR {
			return 
		}
	}
}

func osAllocate( *os.File,  int64) error {
	if  == 0 {
		return nil
	}
	for {
		 := unix.Fallocate(int(.Fd()), 0, 0, )
		if  == unix.EOPNOTSUPP {
			break
		}
		if  != unix.EINTR {
			return 
		}
	}
	,  := .Seek(0, io.SeekEnd)
	if  != nil {
		return 
	}
	if  <=  {
		return nil
	}
	return .Truncate()

}

func osReadLock( *os.File, ,  int64,  time.Duration) _ErrorCode {
	return osLock(, unix.F_RDLCK, , , , _IOERR_RDLOCK)
}

func osWriteLock( *os.File, ,  int64,  time.Duration) _ErrorCode {
	return osLock(, unix.F_WRLCK, , , , _IOERR_LOCK)
}

func osLock( *os.File,  int16, ,  int64,  time.Duration,  _ErrorCode) _ErrorCode {
	 := unix.Flock_t{
		Type:  ,
		Start: ,
		Len:   ,
	}
	var  error
	switch {
	default:
		 = unix.FcntlFlock(.Fd(), unix.F_OFD_SETLK, &)
	case  < 0:
		 = unix.FcntlFlock(.Fd(), unix.F_OFD_SETLKW, &)
	}
	return osLockErrorCode(, )
}

func osUnlock( *os.File, ,  int64) _ErrorCode {
	 := unix.Flock_t{
		Type:  unix.F_UNLCK,
		Start: ,
		Len:   ,
	}
	for {
		 := unix.FcntlFlock(.Fd(), unix.F_OFD_SETLK, &)
		if  == nil {
			return _OK
		}
		if  != unix.EINTR {
			return _IOERR_UNLOCK
		}
	}
}