Exemple #1
0
        public SCSIStatusCodeName Read(SCSICommandDescriptorBlock command, LUNStructure lun, out byte[] response)
        {
            if (lun >= m_disks.Count)
            {
                response = FormatSenseData(SenseDataParameter.GetIllegalRequestInvalidLUNSenseData());
                return(SCSIStatusCodeName.CheckCondition);
            }

            Disk disk        = m_disks[lun];
            int  sectorCount = (int)command.TransferLength;

            try
            {
                lock (IOLock)
                {
                    response = disk.ReadSectors((long)command.LogicalBlockAddress64, sectorCount);
                }
                return(SCSIStatusCodeName.Good);
            }
            catch (ArgumentOutOfRangeException)
            {
                ISCSIServer.Log("[Read] Read error: LBA out of range");
                response = FormatSenseData(SenseDataParameter.GetIllegalRequestLBAOutOfRangeSenseData());
                return(SCSIStatusCodeName.CheckCondition);
            }
            catch (IOException ex)
            {
                int error = Marshal.GetHRForException(ex);
                if (error == (int)Win32Error.ERROR_CRC)
                {
                    ISCSIServer.Log("[Read] Read error: CRC error");
                    response = FormatSenseData(SenseDataParameter.GetWriteFaultSenseData());
                    return(SCSIStatusCodeName.CheckCondition);
                }
                else
                {
                    ISCSIServer.Log("[Read] Read error: {0}", ex.ToString());
                    response = FormatSenseData(SenseDataParameter.GetMediumErrorUnrecoverableReadErrorSenseData());
                    return(SCSIStatusCodeName.CheckCondition);
                }
            }
        }
Exemple #2
0
        public SCSIStatusCodeName Write(SCSICommandDescriptorBlock command, LUNStructure lun, byte[] data, out byte[] response)
        {
            if (lun >= m_disks.Count)
            {
                response = FormatSenseData(SenseDataParameter.GetIllegalRequestInvalidLUNSenseData());
                return(SCSIStatusCodeName.CheckCondition);
            }

            Disk disk = m_disks[lun];

            if (disk.IsReadOnly)
            {
                SenseDataParameter senseData = SenseDataParameter.GetDataProtectSenseData();
                response = senseData.GetBytes();
                return(SCSIStatusCodeName.CheckCondition);
            }

            try
            {
                lock (IOLock)
                {
                    disk.WriteSectors((long)command.LogicalBlockAddress64, data);
                }
                response = new byte[0];
                return(SCSIStatusCodeName.Good);
            }
            catch (ArgumentOutOfRangeException)
            {
                ISCSIServer.Log("[Write] Write error: LBA out of range");
                response = FormatSenseData(SenseDataParameter.GetIllegalRequestLBAOutOfRangeSenseData());
                return(SCSIStatusCodeName.CheckCondition);
            }
            catch (IOException ex)
            {
                ISCSIServer.Log("[Write] Write error: {0}", ex.ToString());
                response = FormatSenseData(SenseDataParameter.GetMediumErrorWriteFaultSenseData());
                return(SCSIStatusCodeName.CheckCondition);
            }
        }