From 93b35c69998398e962bff84f3e5006afa122fbde Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Wed, 8 Mar 2023 01:18:33 -0800 Subject: os.isCygwinPty: Fix a bug, replace kernel32 call, and optimize - Fixes the first few code units of the name being omitted (it was using `@sizeOf(FILE_NAME_INFO)` as the start of the name bytes, but that includes the length of the dummy [1]u16 field and padding; instead the start should be the offset of the dummy [1]u16 field) - Replaces kernel32.GetFileInformationByHandleEx call with ntdll.NtQueryInformationFile + Contributes towards #1840 - Checks that the handle is a named pipe first before querying and checking the name, which is a much faster call than NtQueryInformationFile (this was about a 10x speedup in my probably-not-so-good/take-it-with-a-grain-of-salt benchmarking) --- lib/std/os/windows.zig | 23 +++++++++++++++++++++++ lib/std/os/windows/ntdll.zig | 9 +++++++++ 2 files changed, 32 insertions(+) (limited to 'lib/std/os') diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index b63fdb9f92..23aa378e9e 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -2472,6 +2472,29 @@ pub const FILE_INFORMATION_CLASS = enum(c_int) { FileMaximumInformation, }; +pub const FILE_FS_DEVICE_INFORMATION = extern struct { + DeviceType: DEVICE_TYPE, + Characteristics: ULONG, +}; + +pub const FS_INFORMATION_CLASS = enum(c_int) { + FileFsVolumeInformation = 1, + FileFsLabelInformation, + FileFsSizeInformation, + FileFsDeviceInformation, + FileFsAttributeInformation, + FileFsControlInformation, + FileFsFullSizeInformation, + FileFsObjectIdInformation, + FileFsDriverPathInformation, + FileFsVolumeFlagsInformation, + FileFsSectorSizeInformation, + FileFsDataCopyInformation, + FileFsMetadataSizeInformation, + FileFsFullSizeInformationEx, + FileFsMaximumInformation, +}; + pub const OVERLAPPED = extern struct { Internal: ULONG_PTR, InternalHigh: ULONG_PTR, diff --git a/lib/std/os/windows/ntdll.zig b/lib/std/os/windows/ntdll.zig index 8c5260c1bc..58cba356a2 100644 --- a/lib/std/os/windows/ntdll.zig +++ b/lib/std/os/windows/ntdll.zig @@ -18,6 +18,7 @@ const IO_STATUS_BLOCK = windows.IO_STATUS_BLOCK; const LARGE_INTEGER = windows.LARGE_INTEGER; const OBJECT_INFORMATION_CLASS = windows.OBJECT_INFORMATION_CLASS; const FILE_INFORMATION_CLASS = windows.FILE_INFORMATION_CLASS; +const FS_INFORMATION_CLASS = windows.FS_INFORMATION_CLASS; const UNICODE_STRING = windows.UNICODE_STRING; const RTL_OSVERSIONINFOW = windows.RTL_OSVERSIONINFOW; const FILE_BASIC_INFORMATION = windows.FILE_BASIC_INFORMATION; @@ -232,6 +233,14 @@ pub extern "ntdll" fn NtQueryObject( ReturnLength: ?*ULONG, ) callconv(WINAPI) NTSTATUS; +pub extern "ntdll" fn NtQueryVolumeInformationFile( + FileHandle: HANDLE, + IoStatusBlock: *IO_STATUS_BLOCK, + FsInformation: *anyopaque, + Length: ULONG, + FsInformationClass: FS_INFORMATION_CLASS, +) callconv(WINAPI) NTSTATUS; + pub extern "ntdll" fn RtlWakeAddressAll( Address: ?*const anyopaque, ) callconv(WINAPI) void; -- cgit v1.2.3