| ... | @@ -924,7 +924,7 @@ pub fn GetFinalPathNameByHandle( | ... | @@ -924,7 +924,7 @@ pub fn GetFinalPathNameByHandle( |
| 924 | out_buffer: []u16, | 924 | out_buffer: []u16, |
| 925 | ) GetFinalPathNameByHandleError![]u16 { | 925 | ) GetFinalPathNameByHandleError![]u16 { |
| 926 | // Get normalized path; doesn't include volume name though. | 926 | // Get normalized path; doesn't include volume name though. |
| 927 | var path_buffer: [@sizeOf(FILE_NAME_INFORMATION) + PATH_MAX_WIDE * 2 + 2]u8 = undefined; | 927 | var path_buffer: [PATH_MAX_WIDE * 2]u8 align(@alignOf(FILE_NAME_INFORMATION)) = undefined; |
| 928 | var io: IO_STATUS_BLOCK = undefined; | 928 | var io: IO_STATUS_BLOCK = undefined; |
| 929 | var rc = ntdll.NtQueryInformationFile(hFile, &io, &path_buffer, path_buffer.len, FILE_INFORMATION_CLASS.FileNormalizedNameInformation); | 929 | var rc = ntdll.NtQueryInformationFile(hFile, &io, &path_buffer, path_buffer.len, FILE_INFORMATION_CLASS.FileNormalizedNameInformation); |
| 930 | switch (rc) { | 930 | switch (rc) { |
| ... | @@ -934,7 +934,7 @@ pub fn GetFinalPathNameByHandle( | ... | @@ -934,7 +934,7 @@ pub fn GetFinalPathNameByHandle( |
| 934 | } | 934 | } |
| 935 | | 935 | |
| 936 | // Get NT volume name. | 936 | // Get NT volume name. |
| 937 | var volume_buffer: [MAX_PATH]u8 = undefined; // MAX_PATH bytes should be enough since it's Windows-defined name | 937 | var volume_buffer: [MAX_PATH]u8 align(@alignOf(FILE_NAME_INFORMATION)) = undefined; // MAX_PATH bytes should be enough since it's Windows-defined name |
| 938 | rc = ntdll.NtQueryInformationFile(hFile, &io, &volume_buffer, volume_buffer.len, FILE_INFORMATION_CLASS.FileVolumeNameInformation); | 938 | rc = ntdll.NtQueryInformationFile(hFile, &io, &volume_buffer, volume_buffer.len, FILE_INFORMATION_CLASS.FileVolumeNameInformation); |
| 939 | switch (rc) { | 939 | switch (rc) { |
| 940 | .SUCCESS => {}, | 940 | .SUCCESS => {}, |
| ... | @@ -942,10 +942,10 @@ pub fn GetFinalPathNameByHandle( | ... | @@ -942,10 +942,10 @@ pub fn GetFinalPathNameByHandle( |
| 942 | else => return unexpectedStatus(rc), | 942 | else => return unexpectedStatus(rc), |
| 943 | } | 943 | } |
| 944 | | 944 | |
| 945 | const file_name = @ptrCast(*const FILE_NAME_INFORMATION, @alignCast(@alignOf(FILE_NAME_INFORMATION), &path_buffer[0])); | 945 | const file_name = @ptrCast(*const FILE_NAME_INFORMATION, &path_buffer[0]); |
| 946 | const file_name_u16 = @ptrCast([*]const u16, &file_name.FileName[0])[0 .. file_name.FileNameLength / 2]; | 946 | const file_name_u16 = @ptrCast([*]const u16, &file_name.FileName[0])[0 .. file_name.FileNameLength / 2]; |
| 947 | | 947 | |
| 948 | const volume_name = @ptrCast(*const FILE_NAME_INFORMATION, @alignCast(@alignOf(FILE_NAME_INFORMATION), &volume_buffer[0])); | 948 | const volume_name = @ptrCast(*const FILE_NAME_INFORMATION, &volume_buffer[0]); |
| 949 | | 949 | |
| 950 | switch (fmt.volume_name) { | 950 | switch (fmt.volume_name) { |
| 951 | .Nt => { | 951 | .Nt => { |
| ... | @@ -966,8 +966,8 @@ pub fn GetFinalPathNameByHandle( | ... | @@ -966,8 +966,8 @@ pub fn GetFinalPathNameByHandle( |
| 966 | const MIN_SIZE = @sizeOf(MOUNTMGR_MOUNT_POINT) + MAX_PATH; | 966 | const MIN_SIZE = @sizeOf(MOUNTMGR_MOUNT_POINT) + MAX_PATH; |
| 967 | // We initialize the input buffer to all zeros for convenience since | 967 | // We initialize the input buffer to all zeros for convenience since |
| 968 | // `DeviceIoControl` with `IOCTL_MOUNTMGR_QUERY_POINTS` expects this. | 968 | // `DeviceIoControl` with `IOCTL_MOUNTMGR_QUERY_POINTS` expects this. |
| 969 | var input_buf = [_]u8{0} ** MIN_SIZE; | 969 | var input_buf: [MIN_SIZE]u8 align(@alignOf(MOUNTMGR_MOUNT_POINT)) = [_]u8{0} ** MIN_SIZE; |
| 970 | var output_buf: [MIN_SIZE * 4]u8 = undefined; | 970 | var output_buf: [MIN_SIZE * 4]u8 align(@alignOf(MOUNTMGR_MOUNT_POINTS)) = undefined; |
| 971 | | 971 | |
| 972 | // This surprising path is a filesystem path to the mount manager on Windows. | 972 | // This surprising path is a filesystem path to the mount manager on Windows. |
| 973 | // Source: https://stackoverflow.com/questions/3012828/using-ioctl-mountmgr-query-points | 973 | // Source: https://stackoverflow.com/questions/3012828/using-ioctl-mountmgr-query-points |
| ... | @@ -990,22 +990,17 @@ pub fn GetFinalPathNameByHandle( | ... | @@ -990,22 +990,17 @@ pub fn GetFinalPathNameByHandle( |
| 990 | }; | 990 | }; |
| 991 | defer CloseHandle(mgmt_handle); | 991 | defer CloseHandle(mgmt_handle); |
| 992 | | 992 | |
| 993 | var input_struct = @ptrCast(*MOUNTMGR_MOUNT_POINT, @alignCast(@alignOf(MOUNTMGR_MOUNT_POINT), &input_buf[0])); | 993 | var input_struct = @ptrCast(*MOUNTMGR_MOUNT_POINT, &input_buf[0]); |
| 994 | input_struct.DeviceNameOffset = @sizeOf(MOUNTMGR_MOUNT_POINT); | 994 | input_struct.DeviceNameOffset = @sizeOf(MOUNTMGR_MOUNT_POINT); |
| 995 | input_struct.DeviceNameLength = @intCast(USHORT, volume_name.FileNameLength); | 995 | input_struct.DeviceNameLength = @intCast(USHORT, volume_name.FileNameLength); |
| 996 | @memcpy(input_buf[@sizeOf(MOUNTMGR_MOUNT_POINT)..], @ptrCast([*]const u8, &volume_name.FileName[0]), volume_name.FileNameLength); | 996 | @memcpy(input_buf[@sizeOf(MOUNTMGR_MOUNT_POINT)..], @ptrCast([*]const u8, &volume_name.FileName[0]), volume_name.FileNameLength); |
| 997 | | 997 | |
| 998 | try DeviceIoControl( | 998 | try DeviceIoControl(mgmt_handle, IOCTL_MOUNTMGR_QUERY_POINTS, input_buf[0..], output_buf[0..]); |
| 999 | mgmt_handle, | 999 | const mount_points_struct = @ptrCast(*const MOUNTMGR_MOUNT_POINTS, &output_buf[0]); |
| 1000 | IOCTL_MOUNTMGR_QUERY_POINTS, | | |
| 1001 | input_buf[0 .. @sizeOf(MOUNTMGR_MOUNT_POINT) + volume_name.FileNameLength], | | |
| 1002 | output_buf[0..], | | |
| 1003 | ); | | |
| 1004 | const mount_points_struct = @ptrCast(*const MOUNTMGR_MOUNT_POINTS, @alignCast(@alignOf(MOUNTMGR_MOUNT_POINTS), &output_buf[0])); | | |
| 1005 | | 1000 | |
| 1006 | const mount_points = @ptrCast( | 1001 | const mount_points = @ptrCast( |
| 1007 | [*]const MOUNTMGR_MOUNT_POINT, | 1002 | [*]const MOUNTMGR_MOUNT_POINT, |
| 1008 | @alignCast(@alignOf(MOUNTMGR_MOUNT_POINT), &mount_points_struct.MountPoints[0]), | 1003 | &mount_points_struct.MountPoints[0], |
| 1009 | )[0..mount_points_struct.NumberOfMountPoints]; | 1004 | )[0..mount_points_struct.NumberOfMountPoints]; |
| 1010 | | 1005 | |
| 1011 | var found: bool = false; | 1006 | var found: bool = false; |