Home:ALL Converter>DeviceIoControl call fails with windows error code 183

DeviceIoControl call fails with windows error code 183

Ask Time:2012-11-14T11:19:33         Author:Kailash Akilesh

Json Formatter

I am trying to write buffer data to SCSI device, but when I fire the deviceIoControl call, I get the windows error code 183. The error code indicates File already exits but I am not able to understand the error with respect to the IOCTL call.

The CreateFile function passed as i was able to get the appropriate device Handle as shown below.

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

However, when i try to write the buffer I get the error :

 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.

Please provide some inputs as why this error is being caused and the soultion.

I am using Windows 2008 R2 (x64) and it is the iSCSI path.

Author:Kailash Akilesh,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/13372506/deviceiocontrol-call-fails-with-windows-error-code-183
yy