mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-31 22:36:44 -04:00
windows: add LockFileEx, UnlockFileEx system calls
Changes in syscall_windows.go were copied from internal/syscall/syscall_windows.go. zsyscall_windows.go was regenerated by running 'go generate -tags=generate golang.org/x/sys/windows' using a toolchain built from tip (after CL 196122). These functions are called by cmd/go/internal/lockedfile via internal/syscall/windows. I'd like to copy lockedfile into another project (CL 197299), but these functions need to be exposed here in order to do so. We may need these in x/mod eventually, too. Change-Id: I2033106d2ba65009e764591bfe5702f4d41dffdd Reviewed-on: https://go-review.googlesource.com/c/sys/+/198060 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
This commit is contained in:
committed by
Jason A. Donenfeld
parent
c990c680b6
commit
bb3f8db39f
@@ -57,6 +57,10 @@ const (
|
|||||||
FILE_VOLUME_IS_COMPRESSED = 0x00008000
|
FILE_VOLUME_IS_COMPRESSED = 0x00008000
|
||||||
FILE_VOLUME_QUOTAS = 0x00000020
|
FILE_VOLUME_QUOTAS = 0x00000020
|
||||||
|
|
||||||
|
// Flags for LockFileEx.
|
||||||
|
LOCKFILE_FAIL_IMMEDIATELY = 0x00000001
|
||||||
|
LOCKFILE_EXCLUSIVE_LOCK = 0x00000002
|
||||||
|
|
||||||
// Return values of SleepEx and other APC functions
|
// Return values of SleepEx and other APC functions
|
||||||
STATUS_USER_APC = 0x000000C0
|
STATUS_USER_APC = 0x000000C0
|
||||||
WAIT_IO_COMPLETION = STATUS_USER_APC
|
WAIT_IO_COMPLETION = STATUS_USER_APC
|
||||||
@@ -160,6 +164,8 @@ func NewCallbackCDecl(fn interface{}) uintptr {
|
|||||||
//sys DeleteFile(path *uint16) (err error) = DeleteFileW
|
//sys DeleteFile(path *uint16) (err error) = DeleteFileW
|
||||||
//sys MoveFile(from *uint16, to *uint16) (err error) = MoveFileW
|
//sys MoveFile(from *uint16, to *uint16) (err error) = MoveFileW
|
||||||
//sys MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) = MoveFileExW
|
//sys MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) = MoveFileExW
|
||||||
|
//sys LockFileEx(file Handle, flags uint32, reserved uint32, bytesLow uint32, bytesHigh uint32, overlapped *Overlapped) (err error)
|
||||||
|
//sys UnlockFileEx(file Handle, reserved uint32, bytesLow uint32, bytesHigh uint32, overlapped *Overlapped) (err error)
|
||||||
//sys GetComputerName(buf *uint16, n *uint32) (err error) = GetComputerNameW
|
//sys GetComputerName(buf *uint16, n *uint32) (err error) = GetComputerNameW
|
||||||
//sys GetComputerNameEx(nametype uint32, buf *uint16, n *uint32) (err error) = GetComputerNameExW
|
//sys GetComputerNameEx(nametype uint32, buf *uint16, n *uint32) (err error) = GetComputerNameExW
|
||||||
//sys SetEndOfFile(handle Handle) (err error)
|
//sys SetEndOfFile(handle Handle) (err error)
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ var (
|
|||||||
procDeleteFileW = modkernel32.NewProc("DeleteFileW")
|
procDeleteFileW = modkernel32.NewProc("DeleteFileW")
|
||||||
procMoveFileW = modkernel32.NewProc("MoveFileW")
|
procMoveFileW = modkernel32.NewProc("MoveFileW")
|
||||||
procMoveFileExW = modkernel32.NewProc("MoveFileExW")
|
procMoveFileExW = modkernel32.NewProc("MoveFileExW")
|
||||||
|
procLockFileEx = modkernel32.NewProc("LockFileEx")
|
||||||
|
procUnlockFileEx = modkernel32.NewProc("UnlockFileEx")
|
||||||
procGetComputerNameW = modkernel32.NewProc("GetComputerNameW")
|
procGetComputerNameW = modkernel32.NewProc("GetComputerNameW")
|
||||||
procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
|
procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
|
||||||
procSetEndOfFile = modkernel32.NewProc("SetEndOfFile")
|
procSetEndOfFile = modkernel32.NewProc("SetEndOfFile")
|
||||||
@@ -994,6 +996,30 @@ func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LockFileEx(file Handle, flags uint32, reserved uint32, bytesLow uint32, bytesHigh uint32, overlapped *Overlapped) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall6(procLockFileEx.Addr(), 6, uintptr(file), uintptr(flags), uintptr(reserved), uintptr(bytesLow), uintptr(bytesHigh), uintptr(unsafe.Pointer(overlapped)))
|
||||||
|
if r1 == 0 {
|
||||||
|
if e1 != 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
} else {
|
||||||
|
err = syscall.EINVAL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func UnlockFileEx(file Handle, reserved uint32, bytesLow uint32, bytesHigh uint32, overlapped *Overlapped) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall6(procUnlockFileEx.Addr(), 5, uintptr(file), uintptr(reserved), uintptr(bytesLow), uintptr(bytesHigh), uintptr(unsafe.Pointer(overlapped)), 0)
|
||||||
|
if r1 == 0 {
|
||||||
|
if e1 != 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
} else {
|
||||||
|
err = syscall.EINVAL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func GetComputerName(buf *uint16, n *uint32) (err error) {
|
func GetComputerName(buf *uint16, n *uint32) (err error) {
|
||||||
r1, _, e1 := syscall.Syscall(procGetComputerNameW.Addr(), 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0)
|
r1, _, e1 := syscall.Syscall(procGetComputerNameW.Addr(), 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0)
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user