// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // // Filename : Adaptec.cs // Author(s) : Natalia Portillo // // Component : Adaptec vendor commands. // // --[ Description ] ---------------------------------------------------------- // // Contains vendor commands for Adaptec ACB-4000A and // ACB-4070 ST-506 to SCSI controllers. // // --[ License ] -------------------------------------------------------------- // // This library is free software; you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation; either version 2.1 of the // License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, see . // // ---------------------------------------------------------------------------- // Copyright © 2011-2016 Natalia Portillo // ****************************************************************************/ using System; using DiscImageChef.Console; namespace DiscImageChef.Devices { public partial class Device { /// /// Gets the underlying drive cylinder, head and index bytes for the specified SCSI LBA. /// /// Buffer. /// Sense buffer. /// SCSI Logical Block Address. /// Timeout. /// Duration. public bool AdaptecTranslate(out byte[] buffer, out byte[] senseBuffer, uint lba, uint timeout, out double duration) { return AdaptecTranslate(out buffer, out senseBuffer, false, lba, timeout, out duration); } /// /// Gets the underlying drive cylinder, head and index bytes for the specified SCSI LBA. /// /// Buffer. /// Sense buffer. /// If set to true request the data from drive 1. /// SCSI Logical Block Address. /// Timeout. /// Duration. public bool AdaptecTranslate(out byte[] buffer, out byte[] senseBuffer, bool drive1, uint lba, uint timeout, out double duration) { buffer = new byte[8]; byte[] cdb = new byte[6]; senseBuffer = new byte[32]; bool sense; cdb[0] = (byte)ScsiCommands.Adaptec_Translate; cdb[1] = (byte)((lba & 0x1F0000) >> 16); cdb[2] = (byte)((lba & 0xFF00) >> 8); cdb[3] = (byte)(lba & 0xFF); if(drive1) cdb[1] += 0x20; lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense); error = lastError != 0; DicConsole.DebugWriteLine("SCSI Device", "ADAPTEC TRANSLATE took {0} ms.", duration); return sense; } /// /// Sets the error threshold /// /// true, if set error threshold was adapteced, false otherwise. /// Threshold. 0 to disable error reporting. /// Sense buffer. /// Timeout. /// Duration. public bool AdaptecSetErrorThreshold(byte threshold, out byte[] senseBuffer, uint timeout, out double duration) { return AdaptecSetErrorThreshold(threshold, out senseBuffer, false, timeout, out duration); } /// /// Sets the error threshold /// /// true, if set error threshold was adapteced, false otherwise. /// Threshold. 0 to disable error reporting. /// Sense buffer. /// If set to true set the threshold from drive 1. /// Timeout. /// Duration. public bool AdaptecSetErrorThreshold(byte threshold, out byte[] senseBuffer, bool drive1, uint timeout, out double duration) { byte[] buffer = new byte[1]; buffer[0] = threshold; byte[] cdb = new byte[6]; senseBuffer = new byte[32]; bool sense; cdb[0] = (byte)ScsiCommands.Adaptec_SetErrorThreshold; if(drive1) cdb[1] += 0x20; cdb[4] = 1; lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.Out, out duration, out sense); error = lastError != 0; DicConsole.DebugWriteLine("SCSI Device", "ADAPTEC SET ERROR THRESHOLD took {0} ms.", duration); return sense; } /// /// Requests the usage, seek and error counters, and resets them /// /// Buffer. /// Sense buffer. /// Timeout. /// Duration. public bool AdaptecReadUsageCounter(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration) { return AdaptecReadUsageCounter(out buffer, out senseBuffer, false, timeout, out duration); } /// /// Requests the usage, seek and error counters, and resets them /// /// Buffer. /// Sense buffer. /// If set to true get the counters from drive 1. /// Timeout. /// Duration. public bool AdaptecReadUsageCounter(out byte[] buffer, out byte[] senseBuffer, bool drive1, uint timeout, out double duration) { buffer = new byte[9]; byte[] cdb = new byte[6]; senseBuffer = new byte[32]; bool sense; cdb[0] = (byte)ScsiCommands.Adaptec_Translate; if(drive1) cdb[1] += 0x20; cdb[4] = (byte)buffer.Length; lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense); error = lastError != 0; DicConsole.DebugWriteLine("SCSI Device", "ADAPTEC READ/RESET USAGE COUNTER took {0} ms.", duration); return sense; } /// /// Fills the Adaptec controller RAM with 1K bytes of data /// /// Data to fill the buffer with. /// Sense buffer. /// Timeout. /// Duration. public bool AdaptecWriteBuffer(byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration) { byte[] oneKBuffer = new byte[1024]; if(buffer.Length < 1024) Array.Copy(buffer, 0, oneKBuffer, 0, buffer.Length); else Array.Copy(buffer, 0, oneKBuffer, 0, 1024); byte[] cdb = new byte[6]; senseBuffer = new byte[32]; bool sense; cdb[0] = (byte)ScsiCommands.Adaptec_WriteBuffer; lastError = SendScsiCommand(cdb, ref oneKBuffer, out senseBuffer, timeout, ScsiDirection.Out, out duration, out sense); error = lastError != 0; DicConsole.DebugWriteLine("SCSI Device", "ADAPTEC WRITE DATA BUFFER took {0} ms.", duration); return sense; } /// /// Reads 1K bytes of data from the Adaptec controller RAM /// /// Buffer. /// Sense buffer. /// Timeout. /// Duration. public bool AdaptecReadBuffer(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration) { buffer = new byte[1024]; byte[] cdb = new byte[6]; senseBuffer = new byte[32]; bool sense; cdb[0] = (byte)ScsiCommands.Adaptec_ReadBuffer; lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense); error = lastError != 0; DicConsole.DebugWriteLine("SCSI Device", "ADAPTEC READ DATA BUFFER took {0} ms.", duration); return sense; } } }