DeviceIoControl 调用失败并显示 Windows 错误代码 183

Kai*_*esh 5 c# windows ioctl iscsi

我正在尝试将缓冲区数据写入 SCSI 设备,但是当我触发 deviceIoControl 调用时,我收到 Windows 错误代码 183。错误代码指示文件已退出,但我无法理解与 IOCTL 调用相关的错误。

CreateFile 函数通过,因为我能够获得适当的设备句柄,如下所示。

int devHandle = DeviceIoControlHelper.CreateFile( deviceName, DeviceIoControlHelper.GENERIC_READ | DeviceIoControlHelper.GENERIC_WRITE, DeviceIoControlHelper.FILE_SHARE_READ | DeviceIoControlHelper.FILE_SHARE_WRITE, IntPtr.Zero, DeviceIoControlHelper.OPEN_EXISTING, Inttr.0Z

但是,当我尝试写入缓冲区时,出现错误:

 dwReturned = 0;
        int b = DeviceIoControlHelper.DeviceIoControl(
                devHandle,
                DeviceIoControlHelper.IOCTL_SCSI_PASS_THROUGH,
                inpBuffer,
                (uint)Marshal.SizeOf(info),
                inpBuffer, //out pDriveLayout,
                (uint)Marshal.SizeOf(info), //(uint)Marshal.SizeOf(typeof(DRIVE_LAYOUT_INFORMATION_EX)),
                out dwReturned,
                IntPtr.Zero);

        Log.Write(Log.TraceLevel_5,"ExecuteDeviceIoControl return pass_through scsistatus = " + info.spt.ScsiStatus);
        if (b == 0)
        {
            int win_err = this.GetWindowsErrorCode();
            Log.Write(Log.TraceLevel_5, "ExecuteDeviceIoControl failed, error =  " + win_err);
            LogMyTrace.Write(LogMyTrace.TraceLevel_5, "ExecuteDeviceIoControl failed, error =  " + win_err);

            this.CloseOpenHandle(devHandle);
            Marshal.FreeHGlobal(inpBuffer);
            throw new Exception("DeviceIoControl  failed " + deviceName +
                    " is '" + deviceName + "'. Windows Err is " + win_err);
        }
The error code is 183.
Run Code Online (Sandbox Code Playgroud)

请提供一些输入,说明导致此错误的原因和解决方案。

我使用的是 Windows 2008 R2 (x64),它是 iSCSI 路径。