diff --git a/DiscImageChef.Devices/ChangeLog b/DiscImageChef.Devices/ChangeLog index 0459bb6c3..77104a9b8 100644 --- a/DiscImageChef.Devices/ChangeLog +++ b/DiscImageChef.Devices/ChangeLog @@ -1,3 +1,8 @@ +2015-11-23 Natalia Portillo + + * Device/ScsiCommands.cs: + Implemented SCSI READ CAPACITY(10). + 2015-11-23 Natalia Portillo * Device/ScsiCommands.cs: diff --git a/DiscImageChef.Devices/Device/ScsiCommands.cs b/DiscImageChef.Devices/Device/ScsiCommands.cs index f24d59f85..7482b04d7 100644 --- a/DiscImageChef.Devices/Device/ScsiCommands.cs +++ b/DiscImageChef.Devices/Device/ScsiCommands.cs @@ -550,6 +550,59 @@ namespace DiscImageChef.Devices return sense; } + + /// + /// Sends the SCSI READ CAPACITY command + /// + /// true if the command failed and contains the sense buffer. + /// Buffer where the SCSI GET CONFIGURATION response will be stored + /// Sense buffer. + /// Timeout in seconds. + /// Duration in milliseconds it took for the device to execute the command. + public bool ReadCapacity(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration) + { + return ReadCapacity(out buffer, out senseBuffer, false, 0, false, timeout, out duration); + } + + /// + /// Sends the SCSI READ CAPACITY command + /// + /// true if the command failed and contains the sense buffer. + /// Buffer where the SCSI GET CONFIGURATION response will be stored + /// Sense buffer. + /// Indicates that is relative to current medium position + /// Address where information is requested from, only valid if is set + /// If set, it is requesting partial media capacity + /// Timeout in seconds. + /// Duration in milliseconds it took for the device to execute the command. + public bool ReadCapacity(out byte[] buffer, out byte[] senseBuffer, bool RelAddr, uint address, bool PMI, uint timeout, out double duration) + { + senseBuffer = new byte[32]; + byte[] cdb = new byte[12]; + buffer = new byte[8]; + bool sense; + + cdb[0] = (byte)ScsiCommands.ReadCapacity; + + if (PMI) + { + cdb[8] = 0x01; + if (RelAddr) + cdb[1] = 0x01; + + cdb[2] = (byte)((address & 0xFF000000) >> 24); + cdb[3] = (byte)((address & 0xFF0000) >> 16); + cdb[4] = (byte)((address & 0xFF00) >> 8); + cdb[5] = (byte)(address & 0xFF); + } + + lastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense); + error = lastError != 0; + + DicConsole.DebugWriteLine("SCSI Device", "READ CAPACITY took {0} ms.", duration); + + return sense; + } } }