// /*************************************************************************** // Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : MiniDisc.cs // Author(s) : Natalia Portillo // // Component : MiniDisc vendor commands. // // --[ Description ] ---------------------------------------------------------- // // Contains vendor commands for MiniDisc drives. // // --[ 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-2025 Natalia Portillo // ****************************************************************************/ // ReSharper disable InconsistentNaming using System; using Aaru.Logging; // ReSharper disable UnusedMember.Global namespace Aaru.Devices; public partial class Device { /// Reads the data TOC from an MD-DATA /// Buffer where the response will be stored /// Sense buffer. /// Timeout in seconds. /// Duration in milliseconds it took for the device to execute the command. /// true if the command failed and contains the sense buffer. public bool MiniDiscReadDataTOC(out byte[] buffer, out ReadOnlySpan senseBuffer, uint timeout, out double duration) { const ushort transferLength = 2336; senseBuffer = SenseBuffer; Span cdb = CdbBuffer[..10]; cdb.Clear(); cdb[0] = (byte)ScsiCommands.MiniDiscReadDTOC; cdb[7] = (transferLength & 0xFF00) >> 8; cdb[8] = transferLength & 0xFF; buffer = new byte[transferLength]; LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.In, out duration, out bool sense); Error = LastError != 0; AaruLogging.Debug(SCSI_MODULE_NAME, Localization.MINIDISC_READ_DTOC_took_0_ms, duration); return sense; } /// Reads the user TOC from an MD-DATA /// Buffer where the response will be stored /// Sense buffer. /// TOC sector to read /// Timeout in seconds. /// Duration in milliseconds it took for the device to execute the command. /// true if the command failed and contains the sense buffer. public bool MiniDiscReadUserTOC(out byte[] buffer, out ReadOnlySpan senseBuffer, uint sector, uint timeout, out double duration) { const ushort transferLength = 2336; senseBuffer = SenseBuffer; Span cdb = CdbBuffer[..10]; cdb.Clear(); cdb[0] = (byte)ScsiCommands.MiniDiscReadUTOC; cdb[2] = (byte)((sector & 0xFF000000) >> 24); cdb[3] = (byte)((sector & 0xFF0000) >> 16); cdb[4] = (byte)((sector & 0xFF00) >> 8); cdb[5] = (byte)(sector & 0xFF); cdb[7] = (transferLength & 0xFF00) >> 8; cdb[8] = transferLength & 0xFF; buffer = new byte[transferLength]; LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.In, out duration, out bool sense); Error = LastError != 0; AaruLogging.Debug(SCSI_MODULE_NAME, Localization.MINIDISC_READ_UTOC_took_0_ms, duration); return sense; } /// Sends a D5h command to a MD-DATA drive (harmless) /// Buffer where the response will be stored /// Sense buffer. /// Timeout in seconds. /// Duration in milliseconds it took for the device to execute the command. /// true if the command failed and contains the sense buffer. public bool MiniDiscD5(out byte[] buffer, out ReadOnlySpan senseBuffer, uint timeout, out double duration) { const ushort transferLength = 4; senseBuffer = SenseBuffer; Span cdb = CdbBuffer[..10]; cdb.Clear(); cdb[0] = (byte)ScsiCommands.MiniDiscD5; cdb[7] = 0; cdb[8] = transferLength & 0xFF; buffer = new byte[transferLength]; LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.In, out duration, out bool sense); Error = LastError != 0; AaruLogging.Debug(SCSI_MODULE_NAME, Localization.MINIDISC_command_D5h_took_0_ms, duration); return sense; } /// Stops playing MiniDisc audio from an MD-DATA drive /// Buffer where the response will be stored /// Sense buffer. /// Timeout in seconds. /// Duration in milliseconds it took for the device to execute the command. /// true if the command failed and contains the sense buffer. public bool MiniDiscStopPlaying(out byte[] buffer, out ReadOnlySpan senseBuffer, uint timeout, out double duration) { senseBuffer = SenseBuffer; Span cdb = CdbBuffer[..10]; cdb.Clear(); cdb[0] = (byte)ScsiCommands.MiniDiscStopPlay; buffer = []; LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.None, out duration, out bool sense); Error = LastError != 0; AaruLogging.Debug(SCSI_MODULE_NAME, Localization.MINIDISC_STOP_PLAY_took_0_ms, duration); return sense; } /// Gets current position while playing MiniDisc audio from an MD-DATA drive /// Buffer where the response will be stored /// Sense buffer. /// Timeout in seconds. /// Duration in milliseconds it took for the device to execute the command. /// true if the command failed and contains the sense buffer. public bool MiniDiscReadPosition(out byte[] buffer, out ReadOnlySpan senseBuffer, uint timeout, out double duration) { const ushort transferLength = 4; senseBuffer = SenseBuffer; Span cdb = CdbBuffer[..10]; cdb.Clear(); cdb[0] = (byte)ScsiCommands.MiniDiscReadPosition; cdb[7] = 0; cdb[8] = transferLength & 0xFF; buffer = new byte[transferLength]; LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.In, out duration, out bool sense); Error = LastError != 0; AaruLogging.Debug(SCSI_MODULE_NAME, Localization.MINIDISC_READ_POSITION_took_0_ms, duration); return sense; } /// Gets MiniDisc type from an MD-DATA drive /// Buffer where the response will be stored /// Sense buffer. /// Timeout in seconds. /// Duration in milliseconds it took for the device to execute the command. /// true if the command failed and contains the sense buffer. public bool MiniDiscGetType(out byte[] buffer, out ReadOnlySpan senseBuffer, uint timeout, out double duration) { const ushort transferLength = 8; senseBuffer = SenseBuffer; Span cdb = CdbBuffer[..10]; cdb.Clear(); cdb[0] = (byte)ScsiCommands.MiniDiscGetType; cdb[7] = 0; cdb[8] = transferLength & 0xFF; buffer = new byte[transferLength]; LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.In, out duration, out bool sense); Error = LastError != 0; AaruLogging.Debug(SCSI_MODULE_NAME, Localization.MINIDISC_GET_TYPE_took_0_ms, duration); return sense; } }