| ... | ... | @@ -228,20 +228,43 @@ pub fn DeviceIoControl( |
| 228 | 228 | out: ?[]u8, |
| 229 | 229 | ) DeviceIoControlError!void { |
| 230 | 230 | // Logic from: https://doxygen.reactos.org/d3/d74/deviceio_8c.html |
| 231 | | const syscall = if ((ioControlCode >> 16) == FILE_DEVICE_FILE_SYSTEM) ntdll.NtFsControlFile else ntdll.NtDeviceIoControlFile; |
| 231 | const is_fsctl = (ioControlCode >> 16) == FILE_DEVICE_FILE_SYSTEM; |
| 232 | |
| 232 | 233 | var io: IO_STATUS_BLOCK = undefined; |
| 233 | | const rc = syscall( |
| 234 | | h, |
| 235 | | null, |
| 236 | | null, |
| 237 | | null, |
| 238 | | &io, |
| 239 | | ioControlCode, |
| 240 | | if (in) |i| i.ptr else null, |
| 241 | | if (in) |i| @intCast(ULONG, i.len) else 0, |
| 242 | | if (out) |o| o.ptr else null, |
| 243 | | if (out) |o| @intCast(ULONG, o.len) else 0, |
| 244 | | ); |
| 234 | const in_ptr = if (in) |i| i.ptr else null; |
| 235 | const in_len = if (in) |i| @intCast(ULONG, i.len) else 0; |
| 236 | const out_ptr = if (out) |o| o.ptr else null; |
| 237 | const out_len = if (out) |o| @intCast(ULONG, o.len) else 0; |
| 238 | |
| 239 | const rc = blk: { |
| 240 | if (is_fsctl) { |
| 241 | break :blk ntdll.NtFsControlFile( |
| 242 | h, |
| 243 | null, |
| 244 | null, |
| 245 | null, |
| 246 | &io, |
| 247 | ioControlCode, |
| 248 | in_ptr, |
| 249 | in_len, |
| 250 | out_ptr, |
| 251 | out_len, |
| 252 | ); |
| 253 | } else { |
| 254 | break :blk ntdll.NtDeviceIoControlFile( |
| 255 | h, |
| 256 | null, |
| 257 | null, |
| 258 | null, |
| 259 | &io, |
| 260 | ioControlCode, |
| 261 | in_ptr, |
| 262 | in_len, |
| 263 | out_ptr, |
| 264 | out_len, |
| 265 | ); |
| 266 | } |
| 267 | }; |
| 245 | 268 | switch (rc) { |
| 246 | 269 | .SUCCESS => {}, |
| 247 | 270 | .INVALID_PARAMETER => unreachable, |