/// <summary>Sends the Plextor READ CD-DA command</summary> /// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns> /// <param name="buffer">Buffer where the Plextor READ CD-DA response will be stored</param> /// <param name="senseBuffer">Sense buffer.</param> /// <param name="timeout">Timeout in seconds.</param> /// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param> /// <param name="lba">Start block address.</param> /// <param name="transferLength">How many blocks to read.</param> /// <param name="blockSize">Block size.</param> /// <param name="subchannel">Subchannel selection.</param> public bool PlextorReadCdDa(out byte[] buffer, out byte[] senseBuffer, uint lba, uint blockSize, uint transferLength, PlextorSubchannel subchannel, uint timeout, out double duration) { senseBuffer = new byte[32]; byte[] cdb = new byte[12]; cdb[0] = (byte)ScsiCommands.ReadCdDa; cdb[2] = (byte)((lba & 0xFF000000) >> 24); cdb[3] = (byte)((lba & 0xFF0000) >> 16); cdb[4] = (byte)((lba & 0xFF00) >> 8); cdb[5] = (byte)(lba & 0xFF); cdb[6] = (byte)((transferLength & 0xFF000000) >> 24); cdb[7] = (byte)((transferLength & 0xFF0000) >> 16); cdb[8] = (byte)((transferLength & 0xFF00) >> 8); cdb[9] = (byte)(transferLength & 0xFF); cdb[10] = (byte)subchannel; buffer = new byte[blockSize * transferLength]; LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out bool sense); Error = LastError != 0; DicConsole.DebugWriteLine("SCSI Device", "Plextor READ CD-DA (LBA: {1}, Block Size: {2}, Transfer Length: {3}, Subchannel: {4}, Sense: {5}, Last Error: {6}) took {0} ms.", duration, lba, blockSize, transferLength, subchannel, sense, LastError); return(sense); }
bool ReadPlextorWithSubchannel(out byte[] cmdBuf, out byte[] senseBuf, uint firstSectorToRead, uint blockSize, uint blocksToRead, PlextorSubchannel supportedPlextorSubchannel, out double cmdDuration) { bool sense; cmdBuf = null; if (supportedPlextorSubchannel == PlextorSubchannel.None) { sense = _dev.PlextorReadCdDa(out cmdBuf, out senseBuf, firstSectorToRead, blockSize, blocksToRead, supportedPlextorSubchannel, 0, out cmdDuration); if (!sense) { return(false); } // As a workaround for some firmware bugs, seek far away. _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); return(sense); } byte[] subBuf; uint subSize = supportedPlextorSubchannel == PlextorSubchannel.Q16 ? 16u : 96u; sense = _dev.PlextorReadCdDa(out byte[] dataBuf, out senseBuf, firstSectorToRead, 2352, blocksToRead, PlextorSubchannel.None, 0, out cmdDuration); if (!sense) { sense = _dev.PlextorReadCdDa(out subBuf, out senseBuf, firstSectorToRead, subSize, blocksToRead, supportedPlextorSubchannel, 0, out cmdDuration); if (!sense) { cmdBuf = new byte[(2352 * blocksToRead) + (subSize * blocksToRead)]; for (int b = 0; b < blocksToRead; b++) { Array.Copy(dataBuf, 2352 * b, cmdBuf, (2352 + subSize) * b, 2352); Array.Copy(subBuf, subSize * b, cmdBuf, ((2352 + subSize) * b) + 2352, subSize); } return(false); } } // As a workaround for some firmware bugs, seek far away. _dev.PlextorReadCdDa(out _, out senseBuf, firstSectorToRead - 32, blockSize, blocksToRead, supportedPlextorSubchannel, 0, out _); sense = _dev.PlextorReadCdDa(out dataBuf, out senseBuf, firstSectorToRead, 2352, blocksToRead, PlextorSubchannel.None, 0, out cmdDuration); if (sense) { return(true); } sense = _dev.PlextorReadCdDa(out subBuf, out senseBuf, firstSectorToRead, subSize, blocksToRead, supportedPlextorSubchannel, 0, out cmdDuration); if (sense) { return(true); } cmdBuf = new byte[(2352 * blocksToRead) + (subSize * blocksToRead)]; for (int b = 0; b < blocksToRead; b++) { Array.Copy(dataBuf, 2352 * b, cmdBuf, (2352 + subSize) * b, 2352); Array.Copy(subBuf, subSize * b, cmdBuf, ((2352 + subSize) * b) + 2352, subSize); } return(false); }