Added READ DISC STRUCTURE.

This commit is contained in:
2015-11-02 19:12:19 +00:00
parent 45c390de67
commit ca8a152d8f
8 changed files with 584 additions and 195 deletions

View File

@@ -1,3 +1,9 @@
2015-11-02 Natalia Portillo <claunia@claunia.com>
* DiscImageChef.Decoders.csproj:
* SCSI/DiscStructureCapabilities.cs:
Added READ DISC STRUCTURE.
2015-11-01 Natalia Portillo <claunia@claunia.com> 2015-11-01 Natalia Portillo <claunia@claunia.com>
* SCSI/MMC/Features.cs: * SCSI/MMC/Features.cs:

View File

@@ -81,6 +81,7 @@
<Compile Include="SCSI\EVPD.cs" /> <Compile Include="SCSI\EVPD.cs" />
<Compile Include="SCSI\Modes.cs" /> <Compile Include="SCSI\Modes.cs" />
<Compile Include="SCSI\MMC\Features.cs" /> <Compile Include="SCSI\MMC\Features.cs" />
<Compile Include="SCSI\DiscStructureCapabilities.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>

View File

@@ -0,0 +1,86 @@
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : DiscStructureCapabilities.cs
// Version : 1.0
// Author(s) : Natalia Portillo
//
// Component : Component
//
// Revision : $Revision$
// Last change by : $Author$
// Date : $Date$
//
// --[ Description ] ----------------------------------------------------------
//
// Description
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
using System.Collections.Generic;
namespace DiscImageChef.Decoders.SCSI
{
public static class DiscStructureCapabilities
{
public struct Capability
{
/// <summary>
/// READ/SEND DISC STRUCTURE format code
/// </summary>
public byte FormatCode;
/// <summary>
/// Supported in SEND DISC STRUCTURE
/// </summary>
public bool SDS;
/// <summary>
/// Supported in READ DISC STRUCTURE
/// </summary>
public bool RDS;
}
public static Capability[] Decode(byte[] response)
{
ushort len = (ushort)((response[0] << 8) + response[1]);
if (len + 2 != response.Length)
return null;
List<Capability> caps = new List<Capability>();
uint offset = 4;
while (offset < response.Length)
{
Capability cap = new Capability();
cap.FormatCode = response[offset];
cap.SDS = (response[offset + 1] & 0x80) == 0x80;
cap.RDS = (response[offset + 1] & 0x40) == 0x40;
caps.Add(cap);
offset += 4;
}
return caps.ToArray();
}
}
}

View File

@@ -1,3 +1,9 @@
2015-11-02 Natalia Portillo <claunia@claunia.com>
* Enums.cs:
* Device/ScsiCommands.cs:
Added READ DISC STRUCTURE.
2015-11-01 Natalia Portillo <claunia@claunia.com> 2015-11-01 Natalia Portillo <claunia@claunia.com>
* Device/ScsiCommands.cs: * Device/ScsiCommands.cs:

View File

@@ -507,6 +507,45 @@ namespace DiscImageChef.Devices
return sense; return sense;
} }
public bool ReadDiscStructure(out byte[] buffer, out byte[] senseBuffer, MmcDiscStructureMediaType mediaType, uint address, byte layerNumber, MmcDiscStructureFormat format, byte AGID, uint timeout, out double duration)
{
senseBuffer = new byte[32];
byte[] cdb = new byte[12];
buffer = new byte[8];
bool sense;
cdb[0] = (byte)ScsiCommands.ReadDiscStructure;
cdb[1] = (byte)((byte)mediaType & 0x0F);
cdb[2] = (byte)((address & 0xFF000000) >> 24);
cdb[2] = (byte)((address & 0xFF0000) >> 16);
cdb[4] = (byte)((address & 0xFF00) >> 8);
cdb[5] = (byte)(address & 0xFF);
cdb[6] = layerNumber;
cdb[7] = (byte)format;
cdb[8] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[9] = (byte)(buffer.Length & 0xFF);
cdb[10] = (byte)((AGID & 0x03) << 6);
lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
if (sense)
return true;
ushort strctLength = (ushort)(((int)buffer[0] << 8) + buffer[1] + 2);
buffer = new byte[strctLength];
cdb[8] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[9] = (byte)(buffer.Length & 0xFF);
senseBuffer = new byte[32];
lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
DicConsole.DebugWriteLine("SCSI Device", "READ DISC STRUCTURE took {0} ms.", duration);
return sense;
}
} }
} }

View File

@@ -2760,5 +2760,207 @@ namespace DiscImageChef.Devices
Single = 0x02, Single = 0x02,
Reserved = 0x03 Reserved = 0x03
} }
public enum MmcDiscStructureMediaType : byte
{
/// <summary>
/// Disc Structures for DVD and HD DVD
/// </summary>
DVD = 0x00,
/// <summary>
/// Disc Structures for BD
/// </summary>
BD = 0x01
}
public enum MmcDiscStructureFormat : byte
{
// Generic Format Codes
/// <summary>
/// AACS Volume Identifier
/// </summary>
AACSVolId = 0x80,
/// <summary>
/// AACS Pre-recorded Media Serial Number
/// </summary>
AACSMediaSerial = 0x81,
/// <summary>
/// AACS Media Identifier
/// </summary>
AACSMediaId = 0x82,
/// <summary>
/// AACS Lead-in Media Key Block
/// </summary>
AACSMKB = 0x83,
/// <summary>
/// AACS Data Keys
/// </summary>
AACSDataKeys = 0x84,
/// <summary>
/// AACS LBA extents
/// </summary>
AACSLBAExtents = 0x85,
/// <summary>
/// CPRM Media Key Block specified by AACS
/// </summary>
AACSMKBCPRM = 0x86,
/// <summary>
/// Recognized format layers
/// </summary>
RecognizedFormatLayers = 0x90,
/// <summary>
/// Write protection status
/// </summary>
WriteProtectionStatus = 0xC0,
/// <summary>
/// READ/SEND DISC STRUCTURE capability list
/// </summary>
CapabilityList = 0xFF,
// DVD Disc Structures
/// <summary>
/// DVD Lead-in Physical Information
/// </summary>
PhysicalInformation = 0x00,
/// <summary>
/// DVD Lead-in Copyright Information
/// </summary>
CopyrightInformation = 0x01,
/// <summary>
/// CSS/CPPM Disc key
/// </summary>
DiscKey = 0x02,
/// <summary>
/// DVD Burst Cutting Area
/// </summary>
BurstCuttingArea = 0x03,
/// <summary>
/// DVD Lead-in Disc Manufacturing Information
/// </summary>
DiscManufacturingInformation = 0x04,
/// <summary>
/// DVD Copyright Information from specified sector
/// </summary>
SectorCopyrightInformation = 0x05,
/// <summary>
/// CSS/CPPM Media Identifier
/// </summary>
MediaIdentifier = 0x06,
/// <summary>
/// CSS/CPPM Media Key Block
/// </summary>
MediaKeyBlock = 0x07,
/// <summary>
/// DDS from DVD-RAM
/// </summary>
DVDRAM_DDS = 0x08,
/// <summary>
/// DVD-RAM Medium Status
/// </summary>
DVDRAM_MediumStatus = 0x09,
/// <summary>
/// DVD-RAM Spare Area Information
/// </summary>
DVDRAM_SpareAreaInformation = 0x0A,
/// <summary>
/// DVD-RAM Recording Type Information
/// </summary>
DVDRAM_RecordingType = 0x0B,
/// <summary>
/// DVD-R/-RW RMD in last Border-out
/// </summary>
LastBorderOutRMD = 0x0C,
/// <summary>
/// Specified RMD from last recorded Border-out
/// </summary>
SpecifiedRMD = 0x0D,
/// <summary>
/// DVD-R/-RW Lead-in pre-recorded information
/// </summary>
PreRecordedInfo = 0x0E,
/// <summary>
/// DVD-R/-RW Media Identifier
/// </summary>
DVDR_MediaIdentifier = 0x0F,
/// <summary>
/// DVD-R/-RW Physical Format Information
/// </summary>
DVDR_PhysicalInformation = 0x10,
/// <summary>
/// ADIP
/// </summary>
ADIP = 0x11,
/// <summary>
/// HD DVD Lead-in Copyright Protection Information
/// </summary>
HDDVD_CopyrightInformation = 0x12,
/// <summary>
/// AACS Lead-in Copyright Data Section
/// </summary>
DVD_AACS = 0x15,
/// <summary>
/// HD DVD-R Medium Status
/// </summary>
HDDVDR_MediumStatus = 0x19,
/// <summary>
/// HD DVD-R Last recorded RMD in the latest RMZ
/// </summary>
HDDVDR_LastRMD = 0x1A,
/// <summary>
/// DVD+/-R DL and DVD-Download DL layer capacity
/// </summary>
DVDR_LayerCapacity = 0x20,
/// <summary>
/// DVD-R DL Middle Zone start address
/// </summary>
MiddleZoneStart = 0x21,
/// <summary>
/// DVD-R DL Jump Interval Size
/// </summary>
JumpIntervalSize = 0x22,
/// <summary>
/// DVD-R DL Start LBA of the manual layer jump
/// </summary>
ManualLayerJumpStartLBA = 0x23,
/// <summary>
/// DVD-R DL Remapping information of the specified Anchor Point
/// </summary>
RemapAnchorPoint = 0x24,
/// <summary>
/// Disc Control Block
/// </summary>
DCB = 0x30,
// BD Disc Structures
/// <summary>
/// Blu-ray Disc Information
/// </summary>
DiscInformation = 0x00,
/// <summary>
/// Blu-ray Burst Cutting Area
/// </summary>
BD_BurstCuttingArea = 0x03,
/// <summary>
/// Blu-ray DDS
/// </summary>
BD_DDS = 0x08,
/// <summary>
/// Blu-ray Cartridge Status
/// </summary>
CartridgeStatus = 0x09,
/// <summary>
/// Blu-ray Spare Area Information
/// </summary>
BD_SpareAreaInformation = 0x0A,
/// <summary>
/// Unmodified DFL
/// </summary>
RawDFL = 0x12,
/// <summary>
/// Physical Access Control
/// </summary>
PAC = 0x30
}
} }

View File

@@ -1,3 +1,8 @@
2015-11-02 Natalia Portillo <claunia@claunia.com>
* Commands/DeviceInfo.cs:
Added READ DISC STRUCTURE.
2015-11-01 Natalia Portillo <claunia@claunia.com> 2015-11-01 Natalia Portillo <claunia@claunia.com>
* Commands/DeviceInfo.cs: * Commands/DeviceInfo.cs:

View File

@@ -449,8 +449,6 @@ namespace DiscImageChef.Commands
if (devType == DiscImageChef.Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice) if (devType == DiscImageChef.Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice)
{ {
}
byte[] confBuf; byte[] confBuf;
sense = dev.GetConfiguration(out confBuf, out senseBuf, dev.Timeout, out duration); sense = dev.GetConfiguration(out confBuf, out senseBuf, dev.Timeout, out duration);
@@ -653,6 +651,52 @@ namespace DiscImageChef.Commands
DicConsole.DebugWriteLine("Device-Info command", "GET CONFIGURATION returned no feature descriptors"); DicConsole.DebugWriteLine("Device-Info command", "GET CONFIGURATION returned no feature descriptors");
} }
// TODO: DVD drives respond correctly to BD status.
// While specification says if no medium is present
// it should inform all possible capabilities,
// testing drives show only supported media capabilities.
/*
byte[] strBuf;
sense = dev.ReadDiscStructure(out strBuf, out senseBuf, MmcDiscStructureMediaType.DVD, 0, 0, MmcDiscStructureFormat.CapabilityList, 0, dev.Timeout, out duration);
if (!sense)
{
Decoders.SCSI.DiscStructureCapabilities.Capability[] caps = Decoders.SCSI.DiscStructureCapabilities.Decode(strBuf);
if (caps != null)
{
foreach (Decoders.SCSI.DiscStructureCapabilities.Capability cap in caps)
{
if (cap.SDS && cap.RDS)
DicConsole.WriteLine("Drive can READ/SEND DISC STRUCTURE format {0:X2}h", cap.FormatCode);
else if (cap.SDS)
DicConsole.WriteLine("Drive can SEND DISC STRUCTURE format {0:X2}h", cap.FormatCode);
else if (cap.RDS)
DicConsole.WriteLine("Drive can READ DISC STRUCTURE format {0:X2}h", cap.FormatCode);
}
}
}
sense = dev.ReadDiscStructure(out strBuf, out senseBuf, MmcDiscStructureMediaType.BD, 0, 0, MmcDiscStructureFormat.CapabilityList, 0, dev.Timeout, out duration);
if (!sense)
{
Decoders.SCSI.DiscStructureCapabilities.Capability[] caps = Decoders.SCSI.DiscStructureCapabilities.Decode(strBuf);
if (caps != null)
{
foreach (Decoders.SCSI.DiscStructureCapabilities.Capability cap in caps)
{
if (cap.SDS && cap.RDS)
DicConsole.WriteLine("Drive can READ/SEND DISC STRUCTURE format {0:X2}h", cap.FormatCode);
else if (cap.SDS)
DicConsole.WriteLine("Drive can SEND DISC STRUCTURE format {0:X2}h", cap.FormatCode);
else if (cap.RDS)
DicConsole.WriteLine("Drive can READ DISC STRUCTURE format {0:X2}h", cap.FormatCode);
}
}
}
*/
}
break; break;
} }
default: default: