示例#1
0
        public SCSIStatusCodeName Write(SCSICommandDescriptorBlock command, LUNStructure lun, byte[] data, out byte[] response)
        {
            Disk disk = m_disks[lun];

            if (disk.IsReadOnly)
            {
                Log(Severity.Verbose, "LUN {0}: Refused attempt to write to a read-only disk", lun);
                SenseDataParameter senseData = SenseDataParameter.GetDataProtectSenseData();
                response = senseData.GetBytes();
                return(SCSIStatusCodeName.CheckCondition);
            }

            Log(Severity.Verbose, "LUN {0}: Writing {1} blocks starting from LBA {2}", (ushort)lun, command.TransferLength, (long)command.LogicalBlockAddress64);
            try
            {
                disk.WriteSectors((long)command.LogicalBlockAddress64, data);
                response = new byte[0];
                return(SCSIStatusCodeName.Good);
            }
            catch (ArgumentOutOfRangeException)
            {
                Log(Severity.Error, "Write error: LBA out of range");
                response = FormatSenseData(SenseDataParameter.GetIllegalRequestLBAOutOfRangeSenseData());
                return(SCSIStatusCodeName.CheckCondition);
            }
            catch (IOException ex)
            {
                Log(Severity.Error, "Write error: {0}", ex.ToString());
                response = FormatSenseData(SenseDataParameter.GetMediumErrorWriteFaultSenseData());
                return(SCSIStatusCodeName.CheckCondition);
            }
        }
示例#2
0
        public SCSIStatusCodeName Read(SCSICommandDescriptorBlock command, LUNStructure lun, out byte[] response)
        {
            Disk disk        = m_disks[lun];
            int  sectorCount = (int)command.TransferLength;

            Log(Severity.Verbose, "LUN {0}: Reading {1} blocks starting from LBA {2}", (ushort)lun, sectorCount, (long)command.LogicalBlockAddress64);
            try
            {
                response = disk.ReadSectors((long)command.LogicalBlockAddress64, sectorCount);
                return(SCSIStatusCodeName.Good);
            }
            catch (ArgumentOutOfRangeException)
            {
                Log(Severity.Error, "Read error: LBA out of range");
                response = FormatSenseData(SenseDataParameter.GetIllegalRequestLBAOutOfRangeSenseData());
                return(SCSIStatusCodeName.CheckCondition);
            }
            catch (CyclicRedundancyCheckException)
            {
                Log(Severity.Error, "Read error: CRC error");
                response = FormatSenseData(SenseDataParameter.GetWriteFaultSenseData());
                return(SCSIStatusCodeName.CheckCondition);
            }
            catch (IOException ex)
            {
                Log(Severity.Error, "Read error: {0}", ex.ToString());
                response = FormatSenseData(SenseDataParameter.GetMediumErrorUnrecoverableReadErrorSenseData());
                return(SCSIStatusCodeName.CheckCondition);
            }
        }