public static byte[] FormatSenseData(SenseDataParameter senseData) { byte[] senseDataBytes = senseData.GetBytes(); byte[] result = new byte[senseDataBytes.Length + 2]; Array.Copy(BigEndianConverter.GetBytes((ushort)senseDataBytes.Length), 0, result, 0, 2); Array.Copy(senseDataBytes, 0, result, 2, senseDataBytes.Length); return(result); }
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); } }