[sys] windows: add NtSetInformationFile

160 views
Skip to first unread message

Hao Mou (Gerrit)

unread,
Oct 13, 2021, 1:22:22 AM10/13/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Hao Mou has uploaded this change for review.

View Change

windows: add NtSetInformationFile

Added NtSetInformationFile and some const values related to it.

The doc for the function and the values of the file information class
can be found here:
https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-ntsetinformationfile
The values of the flags in the individual FILE_INFORMATION_CLASS can be
found here:
FILE_RENAME_INFORMATION - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_rename_information
FILE_DISPOSITION_INFORMATION_EX - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddk/ns-ntddk-_file_disposition_information_ex
FILE_CASE_SENSITIVE_INFORMATION - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_case_sensitive_information
FILE_LINK_INFORMATION - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_link_information
The other file information classes do not have flag values.

Fixes golang/go#48933

Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
---
M windows/syscall_windows.go
M windows/types_windows.go
M windows/zsyscall_windows.go
3 files changed, 88 insertions(+), 0 deletions(-)

diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go
index d3b59ae..083f35b 100644
--- a/windows/syscall_windows.go
+++ b/windows/syscall_windows.go
@@ -418,6 +418,7 @@
//sys RtlInitString(destinationString *NTString, sourceString *byte) = ntdll.RtlInitString
//sys NtCreateFile(handle *Handle, access uint32, oa *OBJECT_ATTRIBUTES, iosb *IO_STATUS_BLOCK, allocationSize *int64, attributes uint32, share uint32, disposition uint32, options uint32, eabuffer uintptr, ealength uint32) (ntstatus error) = ntdll.NtCreateFile
//sys NtCreateNamedPipeFile(pipe *Handle, access uint32, oa *OBJECT_ATTRIBUTES, iosb *IO_STATUS_BLOCK, share uint32, disposition uint32, options uint32, typ uint32, readMode uint32, completionMode uint32, maxInstances uint32, inboundQuota uint32, outputQuota uint32, timeout *int64) (ntstatus error) = ntdll.NtCreateNamedPipeFile
+//sys NtSetInformationFile(handle Handle, iosb *IO_STATUS_BLOCK, inBuffer *byte, inBufferLen uint32, class uint32) (ntstatus error) = ntdll.NtSetInformationFile
//sys RtlDosPathNameToNtPathName(dosName *uint16, ntName *NTUnicodeString, ntFileNamePart *uint16, relativeName *RTL_RELATIVE_NAME) (ntstatus error) = ntdll.RtlDosPathNameToNtPathName_U_WithStatus
//sys RtlDosPathNameToRelativeNtPathName(dosName *uint16, ntName *NTUnicodeString, ntFileNamePart *uint16, relativeName *RTL_RELATIVE_NAME) (ntstatus error) = ntdll.RtlDosPathNameToRelativeNtPathName_U_WithStatus
//sys RtlDefaultNpAcl(acl **ACL) (ntstatus error) = ntdll.RtlDefaultNpAcl
diff --git a/windows/types_windows.go b/windows/types_windows.go
index 88e0ce5..19c7a0e 100644
--- a/windows/types_windows.go
+++ b/windows/types_windows.go
@@ -2498,6 +2498,60 @@
FILE_PIPE_SERVER_END = 0x00000001
)

+const (
+ // FileInformationClass for NtSetInformationFile
+ FileBasicInformation = 4
+ FileRenameInformation = 10
+ FileDispositionInformation = 13
+ FilePositionInformation = 14
+ FileEndOfFileInformation = 20
+ FileValidDataLengthInformation = 39
+ FileShortNameInformation = 40
+ FileIoPriorityHintInformation = 43
+ FileReplaceCompletionInformation = 61
+ FileDispositionInformationEx = 64
+ FileCaseSensitiveInformation = 71
+ FileLinkInformation = 72
+ FileCaseSensitiveInformationForceAccessCheck = 75
+ FileKnownFolderInformation = 76
+
+ // Flags for FILE_RENAME_INFORMATION
+ FILE_RENAME_REPLACE_IF_EXISTS = 0x00000001
+ FILE_RENAME_POSIX_SEMANTICS = 0x00000002
+ FILE_RENAME_SUPPRESS_PIN_STATE_INHERITANCE = 0x00000004
+ FILE_RENAME_SUPPRESS_STORAGE_RESERVE_INHERITANCE = 0x00000008
+ FILE_RENAME_NO_INCREASE_AVAILABLE_SPACE = 0x00000010
+ FILE_RENAME_NO_DECREASE_AVAILABLE_SPACE = 0x00000020
+ FILE_RENAME_PRESERVE_AVAILABLE_SPACE = 0x00000030
+ FILE_RENAME_IGNORE_READONLY_ATTRIBUTE = 0x00000040
+ FILE_RENAME_FORCE_RESIZE_TARGET_SR = 0x00000080
+ FILE_RENAME_FORCE_RESIZE_SOURCE_SR = 0x00000100
+ FILE_RENAME_FORCE_RESIZE_SR = 0x00000180
+
+ // Flags for FILE_DISPOSITION_INFORMATION_EX
+ FILE_DISPOSITION_DO_NOT_DELETE = 0x00000000
+ FILE_DISPOSITION_DELETE = 0x00000001
+ FILE_DISPOSITION_POSIX_SEMANTICS = 0x00000002
+ FILE_DISPOSITION_FORCE_IMAGE_SECTION_CHECK = 0x00000004
+ FILE_DISPOSITION_ON_CLOSE = 0x00000008
+ FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE = 0x00000010
+
+ // Flags for FILE_CASE_SENSITIVE_INFORMATION
+ FILE_CS_FLAG_CASE_SENSITIVE_DIR = 0x00000001
+
+ // Flags for FILE_LINK_INFORMATION
+ FILE_LINK_REPLACE_IF_EXISTS = 0x00000001
+ FILE_LINK_POSIX_SEMANTICS = 0x00000002
+ FILE_LINK_SUPPRESS_STORAGE_RESERVE_INHERITANCE = 0x00000008
+ FILE_LINK_NO_INCREASE_AVAILABLE_SPACE = 0x00000010
+ FILE_LINK_NO_DECREASE_AVAILABLE_SPACE = 0x00000020
+ FILE_LINK_PRESERVE_AVAILABLE_SPACE = 0x00000030
+ FILE_LINK_IGNORE_READONLY_ATTRIBUTE = 0x00000040
+ FILE_LINK_FORCE_RESIZE_TARGET_SR = 0x00000080
+ FILE_LINK_FORCE_RESIZE_SOURCE_SR = 0x00000100
+ FILE_LINK_FORCE_RESIZE_SR = 0x00000180
+)
+
// ProcessInformationClasses for NtQueryInformationProcess and NtSetInformationProcess.
const (
ProcessBasicInformation = iota
diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go
index 4ea788e..8a9ce45 100644
--- a/windows/zsyscall_windows.go
+++ b/windows/zsyscall_windows.go
@@ -364,6 +364,7 @@
procNetUserGetInfo = modnetapi32.NewProc("NetUserGetInfo")
procNtCreateFile = modntdll.NewProc("NtCreateFile")
procNtCreateNamedPipeFile = modntdll.NewProc("NtCreateNamedPipeFile")
+ procNtSetInformationFile = modntdll.NewProc("NtSetInformationFile")
procNtQueryInformationProcess = modntdll.NewProc("NtQueryInformationProcess")
procNtSetInformationProcess = modntdll.NewProc("NtSetInformationProcess")
procRtlDefaultNpAcl = modntdll.NewProc("RtlDefaultNpAcl")
@@ -3152,6 +3153,14 @@
return
}

+func NtSetInformationFile(handle Handle, iosb *IO_STATUS_BLOCK, inBuffer *byte, inBufferLen uint32, class uint32) (ntstatus error) {
+ r0, _, _ := syscall.Syscall6(procNtSetInformationFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(iosb)), uintptr(unsafe.Pointer(inBuffer)), uintptr(inBufferLen), uintptr(class), 0)
+ if r0 != 0 {
+ ntstatus = NTStatus(r0)
+ }
+ return
+}
+
func NtQueryInformationProcess(proc Handle, procInfoClass int32, procInfo unsafe.Pointer, procInfoLen uint32, retLen *uint32) (ntstatus error) {
r0, _, _ := syscall.Syscall6(procNtQueryInformationProcess.Addr(), 5, uintptr(proc), uintptr(procInfoClass), uintptr(procInfo), uintptr(procInfoLen), uintptr(unsafe.Pointer(retLen)), 0)
if r0 != 0 {

To view, visit change 355495. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: sys
Gerrit-Branch: master
Gerrit-Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
Gerrit-Change-Number: 355495
Gerrit-PatchSet: 1
Gerrit-Owner: Hao Mou <mouh...@gmail.com>
Gerrit-MessageType: newchange

Tobias Klauser (Gerrit)

unread,
Oct 14, 2021, 12:03:00 PM10/14/21
to Hao Mou, goph...@pubsubhelper.golang.org, Alex Brainman, Brad Fitzpatrick, Go Bot, golang-co...@googlegroups.com

Attention is currently required from: Alex Brainman, Brad Fitzpatrick, Hao Mou.

Patch set 1:Run-TryBot +1

View Change

    To view, visit change 355495. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
    Gerrit-Change-Number: 355495
    Gerrit-PatchSet: 1
    Gerrit-Owner: Hao Mou <mouh...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-CC: Go Bot <go...@golang.org>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Hao Mou <mouh...@gmail.com>
    Gerrit-Comment-Date: Thu, 14 Oct 2021 16:02:54 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Alex Brainman (Gerrit)

    unread,
    Oct 15, 2021, 6:16:55 PM10/15/21
    to Hao Mou, goph...@pubsubhelper.golang.org, Go Bot, Tobias Klauser, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Hao Mou.

    Patch set 1:Run-TryBot +1Trust +1

    View Change

    3 comments:

    To view, visit change 355495. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
    Gerrit-Change-Number: 355495
    Gerrit-PatchSet: 1
    Gerrit-Owner: Hao Mou <mouh...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Hao Mou <mouh...@gmail.com>
    Gerrit-Comment-Date: Fri, 15 Oct 2021 22:16:46 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Hao Mou (Gerrit)

    unread,
    Oct 17, 2021, 10:13:48 AM10/17/21
    to goph...@pubsubhelper.golang.org, Alex Brainman, Go Bot, Tobias Klauser, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman, Brad Fitzpatrick.

    View Change

    2 comments:

    • File windows/syscall_windows.go:

      • Patch Set #1, Line 421: //sys NtSetInformationFile(handle Handle, iosb *IO_STATUS_BLOCK, inBuffer *byte, inBufferLen uint32, class uint32) (ntstatus error) = ntdll.NtSetInformationFile

      • Is it possible to add test that uses NtSetInformationFile that you added? This will prove that your […]

        No problem. I'll try add one.

      • s/uint32/uint64/ […]

        The doc you linked says ULONG is an "unsigned LONG", and it says LONG is a "32-bit signed integer", so ULONG should be uint32?

    To view, visit change 355495. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
    Gerrit-Change-Number: 355495
    Gerrit-PatchSet: 1
    Gerrit-Owner: Hao Mou <mouh...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Comment-Date: Sun, 17 Oct 2021 14:13:45 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Alex Brainman <alex.b...@gmail.com>
    Gerrit-MessageType: comment

    Hao Mou (Gerrit)

    unread,
    Oct 17, 2021, 11:53:51 AM10/17/21
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman, Brad Fitzpatrick.

    Hao Mou uploaded patch set #3 to this change.

    View Change

    windows: add NtSetInformationFile

    Added NtSetInformationFile and some const values related to it.

    The doc for the function and the values of the file information class
    can be found here:
    https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-ntsetinformationfile
    The values of the flags in the individual FILE_INFORMATION_CLASS can be
    found here:
    FILE_RENAME_INFORMATION - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_rename_information
    FILE_DISPOSITION_INFORMATION_EX - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddk/ns-ntddk-_file_disposition_information_ex
    FILE_CASE_SENSITIVE_INFORMATION - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_case_sensitive_information
    FILE_LINK_INFORMATION - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_link_information
    The other file information classes do not have flag values.

    Fixes golang/go#48933

    Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
    ---
    M windows/syscall_windows.go
    M windows/types_windows.go
    M windows/zsyscall_windows.go
    M windows/syscall_windows_test.go
    4 files changed, 176 insertions(+), 0 deletions(-)

    To view, visit change 355495. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
    Gerrit-Change-Number: 355495
    Gerrit-PatchSet: 3
    Gerrit-Owner: Hao Mou <mouh...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-MessageType: newpatchset

    Hao Mou (Gerrit)

    unread,
    Oct 17, 2021, 11:56:25 AM10/17/21
    to goph...@pubsubhelper.golang.org, Alex Brainman, Go Bot, Tobias Klauser, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman, Brad Fitzpatrick.

    View Change

    1 comment:

    • File windows/syscall_windows.go:

      • Patch Set #1, Line 421: //sys NtSetInformationFile(handle Handle, iosb *IO_STATUS_BLOCK, inBuffer *byte, inBufferLen uint32, class uint32) (ntstatus error) = ntdll.NtSetInformationFile

      • No problem. I'll try add one.

        Done

    To view, visit change 355495. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
    Gerrit-Change-Number: 355495
    Gerrit-PatchSet: 3
    Gerrit-Owner: Hao Mou <mouh...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Comment-Date: Sun, 17 Oct 2021 15:56:21 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Alex Brainman <alex.b...@gmail.com>
    Comment-In-Reply-To: Hao Mou <mouh...@gmail.com>
    Gerrit-MessageType: comment

    Alex Brainman (Gerrit)

    unread,
    Oct 20, 2021, 4:31:41 AM10/20/21
    to Hao Mou, goph...@pubsubhelper.golang.org, Go Bot, Tobias Klauser, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Hao Mou.

    Patch set 3:Run-TryBot +1Trust +1

    View Change

    16 comments:

    • Patchset:

      • Patch Set #3:

        Thanks for adding test.

        Some comments for your test.

        Alex

    • File windows/syscall_windows.go:

      • Patch Set #1, Line 421: uint32

        The doc you linked says ULONG is an "unsigned LONG", and it says LONG is a "32-bit signed integer", […]

        Indeed you are correct, and I am wrong. Lets leave your code as is.

    • File windows/syscall_windows_test.go:

      • Patch Set #3, Line 815: TestNtCreateFileNtSetInformationFile

        s/TestNtCreateFileNtSetInformationFile/TestNtCreateFileAndNtSetInformationFile/

        otherwise function name does not make sense.

      • Patch Set #3, Line 822: Fatalf("cannot create NT string: %v", testDirPath)

        s/Fatalf("cannot create NT string: %v", testDirPath)/Fatal(err)/

        otherwise the indows.NewNTUnicodeString error won't be displayed.

      • Patch Set #3, Line 824:

        oa := &windows.OBJECT_ATTRIBUTES{
        Length: 0,
        RootDirectory: windows.Handle(uintptr(0)),
        ObjectName: objectName,
        Attributes: 0,
        SecurityDescriptor: nil,
        SecurityQoS: nil,
        }
        oa.Length = uint32(unsafe.Sizeof(*oa))

        You can replace lines 823-832 with

        oa := &windows.OBJECT_ATTRIBUTES{
        Length: uint32(unsafe.Sizeof(*oa)),
        ObjectName: objectName,
        }

        All other fields will be set to 0 anyway.

      • Patch Set #3, Line 838: Fatalf("cannot open test directory with NtCreateFile: %v", testDirPath)

        s/Fatalf("cannot open test directory with NtCreateFile: %v", testDirPath)/Fatalf("NtCreateFile(%v) failed: %v", testDirPath, err)/

        otherwise we will not know why NtCreateFile failed.

      • Patch Set #3, Line 846: Fatalf("cannot create NT string: %v", fileName)

        s/Fatalf("cannot create NT string: %v", testDirPath)/Fatal(err)/

      • Patch Set #3, Line 854: defer windows.CloseHandle(fileHandle)

        Move line code on line 854 after line 857. Otherwise fileHandle might by undefined if err != nil.

      • Patch Set #3, Line 856: Fatalf("cannot create file with NtCreateFile: %v", filePath)

        s/Fatalf("cannot create file with NtCreateFile: %v", filePath)/Fatalf("NtCreateFile(%v) failed: %v", filePath, err)/

      • Patch Set #3, Line 860: filePath

        s/filePath/err/

        so we know why os.Stat failed.

      • Patch Set #3, Line 867: Fatalf("cannot create UTF16 string: %v", newName)

        s/Fatalf("cannot create UTF16 string: %v", newName)/Fatal(err)/

        so you can see the error.

      • Patch Set #3, Line 875: typedBufferPtr.RootDirectory = windows.Handle(uintptr(0))

        Delete line 875. typedBufferPtr.RootDirectory will be set to 0 anyway.

      • Patch Set #3, Line 877:

        	fileNamePtr := unsafe.Pointer(&typedBufferPtr.FileName[0])
        for i := 0; i < len(newNameUTF16)-1; i++ {
        *(*uint16)(fileNamePtr) = newNameUTF16[i]
        fileNamePtr = unsafe.Pointer(uintptr(fileNamePtr) + uintptr(2))
        }

        You should be able to replace lines 877-881 with

        copy((*[1 << 29]uint16)(unsafe.Pointer(&typedBufferPtr.FileName[0]))[:], newNameUTF16)

        (not tested).

      • Patch Set #3, Line 884: Fatalf("cannot rename using NtSetInformationFile: %v", newPath)

        s/Fatalf("cannot rename using NtSetInformationFile: %v", newPath)/Fatalf("NtSetInformationFile(%v) failed: %v", newPath, err)/

        so we can see the error.

      • Patch Set #3, Line 888: windows.CloseHandle(fileHandle)

        I don't understand why you are not just calling windows.CloseHandle regardless of result of windows.GetVersion call? Why do you need to call windows.GetVersion?

      • Patch Set #3, Line 892: Fatalf("cannot stat rename target: %v", newPath)

        s/Fatalf("cannot stat rename target: %v", newPath)/Fatalf("cannot stat rename target %v: %v", newPath, err)/

        so we can see the error.

    To view, visit change 355495. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
    Gerrit-Change-Number: 355495
    Gerrit-PatchSet: 3
    Gerrit-Owner: Hao Mou <mouh...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Hao Mou <mouh...@gmail.com>
    Gerrit-Comment-Date: Wed, 20 Oct 2021 08:31:36 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes

    Hao Mou (Gerrit)

    unread,
    Oct 20, 2021, 7:54:09 AM10/20/21
    to goph...@pubsubhelper.golang.org, Go Bot, Alex Brainman, Tobias Klauser, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman, Brad Fitzpatrick.

    View Change

    2 comments:

    • File windows/syscall_windows.go:

      • Indeed you are correct, and I am wrong. Lets leave your code as is.

        Ack

    • File windows/syscall_windows_test.go:

      • Patch Set #3, Line 888: windows.CloseHandle(fileHandle)

        I don't understand why you are not just calling windows.CloseHandle regardless of result of windows. […]

        I was confused about the FILE_RENAME_POSIX_SEMANTICS flag, which only exists on Windows 10 or above, incorrectly assuming the rename would not take effect without closing the handle on earlier versions of Windows. I was wrong. The flag would only be effective when the rename would replace an existing file.

        I will remove the version check. Rename should take effect without closing the handle, so I will remove windows.CloseHandle as well.

    To view, visit change 355495. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
    Gerrit-Change-Number: 355495
    Gerrit-PatchSet: 3
    Gerrit-Owner: Hao Mou <mouh...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Comment-Date: Wed, 20 Oct 2021 11:54:04 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No

    Hao Mou (Gerrit)

    unread,
    Oct 20, 2021, 8:08:18 AM10/20/21
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman, Brad Fitzpatrick.

    Hao Mou uploaded patch set #4 to this change.

    View Change

    windows: add NtSetInformationFile

    Added NtSetInformationFile and some const values related to it.

    The doc for the function and the values of the file information class
    can be found here:
    https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-ntsetinformationfile
    The values of the flags in the individual FILE_INFORMATION_CLASS can be
    found here:
    FILE_RENAME_INFORMATION - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_rename_information
    FILE_DISPOSITION_INFORMATION_EX - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddk/ns-ntddk-_file_disposition_information_ex
    FILE_CASE_SENSITIVE_INFORMATION - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_case_sensitive_information
    FILE_LINK_INFORMATION - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_link_information
    The other file information classes do not have flag values.

    Fixes golang/go#48933

    Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
    ---
    M windows/syscall_windows.go
    M windows/types_windows.go
    M windows/zsyscall_windows.go
    M windows/syscall_windows_test.go
    4 files changed, 162 insertions(+), 0 deletions(-)

    To view, visit change 355495. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
    Gerrit-Change-Number: 355495
    Gerrit-PatchSet: 4
    Gerrit-Owner: Hao Mou <mouh...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-MessageType: newpatchset

    Hao Mou (Gerrit)

    unread,
    Oct 20, 2021, 8:10:08 AM10/20/21
    to goph...@pubsubhelper.golang.org, Go Bot, Alex Brainman, Tobias Klauser, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman, Brad Fitzpatrick.

    View Change

    14 comments:

    • File windows/syscall_windows_test.go:

      • Patch Set #3, Line 815: TestNtCreateFileNtSetInformationFile

        s/TestNtCreateFileNtSetInformationFile/TestNtCreateFileAndNtSetInformationFile/ […]

        Done

      • s/Fatalf("cannot create NT string: %v", testDirPath)/Fatal(err)/ […]

        Done

      • Patch Set #3, Line 824:

        oa := &windows.OBJECT_ATTRIBUTES{
        Length: 0,
        RootDirectory: windows.Handle(uintptr(0)),
        ObjectName: objectName,
        Attributes: 0,
        SecurityDescriptor: nil,
        SecurityQoS: nil,
        }
        oa.Length = uint32(unsafe.Sizeof(*oa))

      • You can replace lines 823-832 with […]

        Done

      • s/Fatalf("cannot open test directory with NtCreateFile: %v", testDirPath)/Fatalf("NtCreateFile(%v) f […]

        Done

      • Patch Set #3, Line 846: Fatalf("cannot create NT string: %v", fileName)

        s/Fatalf("cannot create NT string: %v", testDirPath)/Fatal(err)/

      • Done

      • Patch Set #3, Line 854: defer windows.CloseHandle(fileHandle)

        Move line code on line 854 after line 857. Otherwise fileHandle might by undefined if err != nil.

      • Done

      • s/Fatalf("cannot create file with NtCreateFile: %v", filePath)/Fatalf("NtCreateFile(%v) failed: %v", […]

        Done

      • s/filePath/err/ […]

        Done

      • s/Fatalf("cannot create UTF16 string: %v", newName)/Fatal(err)/ […]

        Done

      • Patch Set #3, Line 875: typedBufferPtr.RootDirectory = windows.Handle(uintptr(0))

        Delete line 875. typedBufferPtr.RootDirectory will be set to 0 anyway.

      • Done

      • Patch Set #3, Line 877:

        	fileNamePtr := unsafe.Pointer(&typedBufferPtr.FileName[0])
        for i := 0; i < len(newNameUTF16)-1; i++ {
        *(*uint16)(fileNamePtr) = newNameUTF16[i]
        fileNamePtr = unsafe.Pointer(uintptr(fileNamePtr) + uintptr(2))
        }

      • You should be able to replace lines 877-881 with […]

        Yes, it works!

      • s/Fatalf("cannot rename using NtSetInformationFile: %v", newPath)/Fatalf("NtSetInformationFile(%v) f […]

        Done

      • I was confused about the FILE_RENAME_POSIX_SEMANTICS flag, which only exists on Windows 10 or above, […]

        Done

      • s/Fatalf("cannot stat rename target: %v", newPath)/Fatalf("cannot stat rename target %v: %v", newPat […]

        Done

    To view, visit change 355495. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
    Gerrit-Change-Number: 355495
    Gerrit-PatchSet: 4
    Gerrit-Owner: Hao Mou <mouh...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Comment-Date: Wed, 20 Oct 2021 12:10:04 +0000

    Hao Mou (Gerrit)

    unread,
    Oct 22, 2021, 1:51:00 AM10/22/21
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman, Brad Fitzpatrick.

    Hao Mou uploaded patch set #5 to this change.

    View Change

    windows: add NtSetInformationFile

    Added NtSetInformationFile and some const values related to it.

    The doc for the function and the values of the file information class
    can be found here:
    https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-ntsetinformationfile
    The values of the flags in the individual FILE_INFORMATION_CLASS can be
    found here:
    FILE_RENAME_INFORMATION - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_rename_information
    FILE_DISPOSITION_INFORMATION_EX - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddk/ns-ntddk-_file_disposition_information_ex
    FILE_CASE_SENSITIVE_INFORMATION - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_case_sensitive_information
    FILE_LINK_INFORMATION - https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_link_information
    The other file information classes do not have flag values.

    Fixes golang/go#48933

    Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
    ---
    M windows/syscall_windows.go
    M windows/types_windows.go
    M windows/zsyscall_windows.go
    M windows/syscall_windows_test.go
    4 files changed, 162 insertions(+), 0 deletions(-)

    To view, visit change 355495. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
    Gerrit-Change-Number: 355495
    Gerrit-PatchSet: 5
    Gerrit-Owner: Hao Mou <mouh...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-MessageType: newpatchset

    Hao Mou (Gerrit)

    unread,
    Oct 22, 2021, 1:53:21 AM10/22/21
    to goph...@pubsubhelper.golang.org, Go Bot, Alex Brainman, Tobias Klauser, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman, Brad Fitzpatrick.

    View Change

    1 comment:

    • Patchset:

      • Patch Set #5:

        Ready for another round of review. Merged main branch in Patchset 5 to resolve conflict.

    To view, visit change 355495. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
    Gerrit-Change-Number: 355495
    Gerrit-PatchSet: 5
    Gerrit-Owner: Hao Mou <mouh...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Comment-Date: Fri, 22 Oct 2021 05:53:18 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Alex Brainman (Gerrit)

    unread,
    Oct 23, 2021, 4:46:15 AM10/23/21
    to Hao Mou, goph...@pubsubhelper.golang.org, Go Bot, Tobias Klauser, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Hao Mou.

    Patch set 5:Run-TryBot +1Trust +1

    View Change

      To view, visit change 355495. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: sys
      Gerrit-Branch: master
      Gerrit-Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
      Gerrit-Change-Number: 355495
      Gerrit-PatchSet: 5
      Gerrit-Owner: Hao Mou <mouh...@gmail.com>
      Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Reviewer: Go Bot <go...@golang.org>
      Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
      Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Attention: Hao Mou <mouh...@gmail.com>
      Gerrit-Comment-Date: Sat, 23 Oct 2021 08:46:06 +0000

      Alex Brainman (Gerrit)

      unread,
      Oct 23, 2021, 4:50:39 AM10/23/21
      to Hao Mou, goph...@pubsubhelper.golang.org, Go Bot, Tobias Klauser, Brad Fitzpatrick, golang-co...@googlegroups.com

      Attention is currently required from: Brad Fitzpatrick, Hao Mou.

      Patch set 5:Code-Review +2

      View Change

      1 comment:

      • Patchset:

        • Patch Set #5:

          LGTM. Thank you very much for your contribution.

          I will go and find another reviewer before I can submit your change.

          Alex

      To view, visit change 355495. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: sys
      Gerrit-Branch: master
      Gerrit-Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
      Gerrit-Change-Number: 355495
      Gerrit-PatchSet: 5
      Gerrit-Owner: Hao Mou <mouh...@gmail.com>
      Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Reviewer: Go Bot <go...@golang.org>
      Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
      Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Attention: Hao Mou <mouh...@gmail.com>
      Gerrit-Comment-Date: Sat, 23 Oct 2021 08:50:31 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Gerrit-MessageType: comment

      Emmanuel Odeke (Gerrit)

      unread,
      Oct 23, 2021, 4:54:33 AM10/23/21
      to Hao Mou, goph...@pubsubhelper.golang.org, Alex Brainman, Go Bot, Tobias Klauser, Brad Fitzpatrick, golang-co...@googlegroups.com

      Attention is currently required from: Brad Fitzpatrick, Hao Mou.

      Patch set 5:Trust +1

      View Change

        To view, visit change 355495. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: sys
        Gerrit-Branch: master
        Gerrit-Change-Id: I917ff4c8df132f8584fd6d924cf5a9626a065092
        Gerrit-Change-Number: 355495
        Gerrit-PatchSet: 5
        Gerrit-Owner: Hao Mou <mouh...@gmail.com>
        Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
        Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-Reviewer: Emmanuel Odeke <emma...@orijtech.com>
        Gerrit-Reviewer: Go Bot <go...@golang.org>
        Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
        Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-Attention: Hao Mou <mouh...@gmail.com>
        Gerrit-Comment-Date: Sat, 23 Oct 2021 08:54:29 +0000
        Reply all
        Reply to author
        Forward
        0 new messages