Files
Aaru/Aaru.Core/Devices/Dumping/CompactDisc/Plextor.cs

151 lines
6.4 KiB
C#
Raw Normal View History

2020-03-11 21:56:55 +00:00
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Plextor.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : CompactDisc dumping.
//
// --[ Description ] ----------------------------------------------------------
//
// Enables reading subchannel using Plextor vendor command.
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2011-2025 Natalia Portillo
2020-03-11 21:56:55 +00:00
// ****************************************************************************/
using System;
using Aaru.Devices;
namespace Aaru.Core.Devices.Dumping;
2022-03-06 13:29:38 +00:00
partial class Dump
{
2022-03-06 13:29:38 +00:00
/// <summary>Reads a sector using Plextor's D8h READ CDDA command with subchannel</summary>
/// <param name="cmdBuf">Data buffer</param>
/// <param name="senseBuf">Sense buffer</param>
/// <param name="firstSectorToRead">Fix sector to read</param>
/// <param name="blockSize">Sector size in bytes</param>
/// <param name="blocksToRead">How many sectors to read</param>
/// <param name="supportedPlextorSubchannel">Supported subchannel type</param>
/// <param name="cmdDuration">Time spent sending commands to the drive</param>
/// <returns><c>true</c> if an error occured, <c>false</c> otherwise</returns>
2025-08-22 19:57:09 +01:00
bool ReadPlextorWithSubchannel(out byte[] cmdBuf, out ReadOnlySpan<byte> senseBuf, uint firstSectorToRead,
uint blockSize, uint blocksToRead, PlextorSubchannel supportedPlextorSubchannel,
2022-03-06 13:29:38 +00:00
out double cmdDuration)
{
2022-03-06 13:29:38 +00:00
bool sense;
cmdBuf = null;
2022-03-06 13:29:38 +00:00
if(supportedPlextorSubchannel == PlextorSubchannel.None)
{
2024-05-01 04:05:22 +01:00
sense = _dev.PlextorReadCdDa(out cmdBuf,
out senseBuf,
firstSectorToRead,
blockSize,
blocksToRead,
supportedPlextorSubchannel,
0,
out cmdDuration);
2024-05-01 04:05:22 +01:00
if(!sense) return false;
2022-03-06 13:29:38 +00:00
// As a workaround for some firmware bugs, seek far away.
2024-05-01 04:05:22 +01:00
_dev.PlextorReadCdDa(out _,
out senseBuf,
firstSectorToRead - 32,
blockSize,
blocksToRead,
supportedPlextorSubchannel,
0,
out _);
sense = _dev.PlextorReadCdDa(out cmdBuf,
out senseBuf,
firstSectorToRead,
blockSize,
blocksToRead,
supportedPlextorSubchannel,
_dev.Timeout,
out cmdDuration);
2022-03-06 13:29:38 +00:00
return sense;
}
2022-03-06 13:29:38 +00:00
uint subSize = supportedPlextorSubchannel == PlextorSubchannel.Q16 ? 16u : 96u;
2022-03-16 11:47:00 +00:00
if(supportedPlextorSubchannel is PlextorSubchannel.Q16 or PlextorSubchannel.Pack)
2022-03-06 13:29:38 +00:00
{
2024-05-01 04:05:22 +01:00
sense = _dev.PlextorReadCdDa(out cmdBuf,
out senseBuf,
firstSectorToRead,
2352 + subSize,
blocksToRead,
supportedPlextorSubchannel,
_dev.Timeout,
out cmdDuration);
if(!sense) return false;
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
// As a workaround for some firmware bugs, seek far away.
2024-05-01 04:05:22 +01:00
_dev.PlextorReadCdDa(out _,
out senseBuf,
firstSectorToRead - 32,
blockSize,
blocksToRead,
supportedPlextorSubchannel,
0,
out _);
sense = _dev.PlextorReadCdDa(out byte[] dataBuf,
out senseBuf,
firstSectorToRead,
2352,
blocksToRead,
PlextorSubchannel.None,
0,
out cmdDuration);
if(sense) return true;
sense = _dev.PlextorReadCdDa(out byte[] subBuf,
out senseBuf,
firstSectorToRead,
subSize,
blocksToRead,
2023-10-03 22:57:50 +01:00
supportedPlextorSubchannel == PlextorSubchannel.Pack
? PlextorSubchannel.All
2024-05-01 04:05:22 +01:00
: supportedPlextorSubchannel,
0,
out cmdDuration);
2024-05-01 04:05:22 +01:00
if(sense) return true;
2023-10-03 22:57:50 +01:00
cmdBuf = new byte[2352 * blocksToRead + subSize * blocksToRead];
2025-08-22 19:57:09 +01:00
for(int b = 0; b < blocksToRead; b++)
2022-03-06 13:29:38 +00:00
{
2023-10-03 22:57:50 +01:00
Array.Copy(dataBuf, 2352 * b, cmdBuf, (2352 + subSize) * b, 2352);
Array.Copy(subBuf, subSize * b, cmdBuf, (2352 + subSize) * b + 2352, subSize);
}
2022-03-06 13:29:38 +00:00
return false;
}
}