Files
Aaru/MediaTypeFromDevice/FromScsi.cs

131 lines
6.3 KiB
C#
Raw Normal View History

// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : FromScsi.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Aaru common types.
//
// --[ License ] --------------------------------------------------------------
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// ----------------------------------------------------------------------------
2022-02-18 10:02:16 +00:00
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
2022-03-07 07:36:32 +00:00
namespace Aaru.CommonTypes;
using System;
using Aaru.Console;
2022-03-06 13:29:30 +00:00
public static partial class MediaTypeFromDevice
{
2022-03-06 13:29:30 +00:00
/// <summary>Tries to guess, from SCSI information, the media type of a device and/or its inserted media</summary>
/// <param name="scsiPeripheralType">The SCSI Peripheral Type as indicated in the INQUIRY response</param>
/// <param name="vendor">The vendor string of the device</param>
/// <param name="model">The model string of the device</param>
/// <param name="mediumType">The medium type byte from MODE SENSE</param>
/// <param name="densityCode">The density type byte from MODE SENSE</param>
/// <param name="blocks">How many blocks are on the media</param>
/// <param name="blockSize">Size in bytes of each block</param>
/// <param name="isUsb">Device is USB</param>
/// <param name="opticalDisc">Is media an optical disc?</param>
/// <returns>The media type</returns>
public static MediaType GetFromScsi(byte scsiPeripheralType, string vendor, string model, byte mediumType,
2022-03-07 07:36:32 +00:00
byte densityCode, ulong blocks, uint blockSize, bool isUsb, bool opticalDisc)
{
2022-03-06 13:29:30 +00:00
switch(scsiPeripheralType)
{
2022-03-06 13:29:30 +00:00
// Direct access device
case 0x00:
// Simplified access device
case 0x0E:
if(mediumType == 0x03 ||
mediumType == 0x05 ||
mediumType == 0x07)
goto case 0x07;
return GetFromSbc(vendor, model, mediumType, blocks, blockSize);
// Sequential access device
2022-03-07 07:36:32 +00:00
case 0x01: return GetFromSsc(scsiPeripheralType, vendor, model, mediumType, densityCode, blocks, blockSize);
2022-03-06 13:29:30 +00:00
// Write-once device
case 0x04:
// Optical device
case 0x07: return GetFromOdc(mediumType, blocks, blockSize);
// MultiMedia Device
case 0x05: return GetFromMmc(model, mediumType, densityCode, blocks, blockSize, isUsb, opticalDisc);
// MD DATA drives
case 0x10 when model.StartsWith("MDM", StringComparison.Ordinal) ||
model.StartsWith("MDH", StringComparison.Ordinal):
if(blockSize == 2048)
{
AaruConsole.DebugWriteLine("Media detection",
"SCSI peripheral type is {0:X2}h, media has {1} blocks of {2} bytes, setting media type to MiniDisc for Data.",
scsiPeripheralType, blocks, blockSize);
2022-03-06 13:29:30 +00:00
return MediaType.MDData;
}
2022-03-06 13:29:30 +00:00
switch(blocks)
{
case 57312:
AaruConsole.DebugWriteLine("Media detection",
"SCSI peripheral type is {0:X2}h, media has {1} blocks of {2} bytes, setting media type to 60 minute MiniDisc.",
scsiPeripheralType, blocks, blockSize);
2022-03-06 13:29:30 +00:00
return MediaType.MD60;
case 70464:
AaruConsole.DebugWriteLine("Media detection",
"SCSI peripheral type is {0:X2}h, media has {1} blocks of {2} bytes, setting media type to 74 minute MiniDisc.",
scsiPeripheralType, blocks, blockSize);
2022-03-06 13:29:30 +00:00
return MediaType.MD74;
case 76096:
AaruConsole.DebugWriteLine("Media detection",
"SCSI peripheral type is {0:X2}h, media has {1} blocks of {2} bytes, setting media type to 80 minute MiniDisc.",
scsiPeripheralType, blocks, blockSize);
2022-03-06 13:29:30 +00:00
return MediaType.MD80;
}
2022-03-06 13:29:30 +00:00
AaruConsole.DebugWriteLine("Media detection",
"SCSI peripheral type is {0:X2}h, media has {1} blocks of {2} bytes, setting media type to 60 minute MiniDisc.",
scsiPeripheralType, blocks, blockSize);
2022-03-06 13:29:30 +00:00
return MediaType.MD;
2022-03-06 13:29:30 +00:00
// Host managed zoned block device
case 0x14:
AaruConsole.DebugWriteLine("Media detection",
"SCSI peripheral type is {0:X2}h, setting media type to host managed zoned block device.",
scsiPeripheralType, blocks, blockSize);
2022-03-06 13:29:30 +00:00
return MediaType.Zone_HDD;
}
2022-03-06 13:29:30 +00:00
return MediaType.Unknown;
}
}