2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2016-01-13 03:47:25 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : SMC.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2016-01-13 03:47:25 +00:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : SCSI Media-changer Commands.
|
2016-01-13 03:47:25 +00:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Contains SCSI commands defined in SMC standards.
|
2016-01-13 03:47:25 +00:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// 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
|
2016-01-13 03:47:25 +00:00
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// 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.
|
2016-01-13 03:47:25 +00:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2016-01-13 03:47:25 +00:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-02-18 10:02:53 +00:00
|
|
|
// Copyright © 2011-2022 Natalia Portillo
|
2016-01-13 03:47:25 +00:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
namespace Aaru.Devices;
|
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
using Aaru.Console;
|
|
|
|
|
|
2022-03-26 18:31:04 +00:00
|
|
|
public partial class Device
|
2016-01-13 03:47:25 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <summary>Reads an attribute from the medium auxiliary memory, or reports which elements in the changer contain one</summary>
|
|
|
|
|
/// <param name="buffer">Buffer.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="action">What to do, <see cref="ScsiAttributeAction" />.</param>
|
|
|
|
|
/// <param name="element">Element address.</param>
|
|
|
|
|
/// <param name="elementType">Element type.</param>
|
|
|
|
|
/// <param name="volume">Volume number.</param>
|
|
|
|
|
/// <param name="partition">Partition number.</param>
|
|
|
|
|
/// <param name="firstAttribute">First attribute identificator.</param>
|
|
|
|
|
/// <param name="cache">If set to <c>true</c> device can return cached data.</param>
|
|
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
|
|
|
|
public bool ReadAttribute(out byte[] buffer, out byte[] senseBuffer, ScsiAttributeAction action, ushort element,
|
|
|
|
|
byte elementType, byte volume, byte partition, ushort firstAttribute, bool cache,
|
|
|
|
|
uint timeout, out double duration)
|
2016-01-13 03:47:25 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
buffer = new byte[256];
|
2022-03-07 07:36:44 +00:00
|
|
|
var cdb = new byte[16];
|
2022-03-06 13:29:38 +00:00
|
|
|
senseBuffer = new byte[64];
|
2016-01-13 03:47:25 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
cdb[0] = (byte)ScsiCommands.ReadAttribute;
|
|
|
|
|
cdb[1] = (byte)((byte)action & 0x1F);
|
|
|
|
|
cdb[2] = (byte)((element & 0xFF00) >> 8);
|
|
|
|
|
cdb[3] = (byte)(element & 0xFF);
|
|
|
|
|
cdb[4] = (byte)(elementType & 0x0F);
|
|
|
|
|
cdb[5] = volume;
|
|
|
|
|
cdb[7] = partition;
|
|
|
|
|
cdb[8] = (byte)((firstAttribute & 0xFF00) >> 8);
|
|
|
|
|
cdb[9] = (byte)(firstAttribute & 0xFF);
|
|
|
|
|
cdb[10] = (byte)((buffer.Length & 0xFF000000) >> 24);
|
|
|
|
|
cdb[11] = (byte)((buffer.Length & 0xFF0000) >> 16);
|
|
|
|
|
cdb[12] = (byte)((buffer.Length & 0xFF00) >> 8);
|
|
|
|
|
cdb[13] = (byte)(buffer.Length & 0xFF);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(cache)
|
|
|
|
|
cdb[14] += 0x01;
|
2016-01-13 03:47:25 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
|
|
|
|
out bool sense);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Error = LastError != 0;
|
2016-01-13 03:47:25 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(sense)
|
|
|
|
|
return true;
|
2016-01-13 03:47:25 +00:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
var attrLen = (uint)((buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3] + 4);
|
2022-03-06 13:29:38 +00:00
|
|
|
buffer = new byte[attrLen];
|
|
|
|
|
cdb[10] = (byte)((buffer.Length & 0xFF000000) >> 24);
|
|
|
|
|
cdb[11] = (byte)((buffer.Length & 0xFF0000) >> 16);
|
|
|
|
|
cdb[12] = (byte)((buffer.Length & 0xFF00) >> 8);
|
|
|
|
|
cdb[13] = (byte)(buffer.Length & 0xFF);
|
|
|
|
|
senseBuffer = new byte[64];
|
2016-01-13 03:47:25 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
|
|
|
|
out sense);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Error = LastError != 0;
|
2016-01-13 03:47:25 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
AaruConsole.DebugWriteLine("SCSI Device", "READ ATTRIBUTE took {0} ms.", duration);
|
2016-01-13 03:47:25 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return sense;
|
2016-01-13 03:47:25 +00:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|