2020-07-12 21:03:45 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// Aaru Data Preservation Suite
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : FromMmc.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.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-12-19 10:45:18 +00:00
|
|
|
// Copyright © 2011-2025 Natalia Portillo
|
2020-07-12 21:03:45 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
2025-08-17 05:50:25 +01:00
|
|
|
using Aaru.Logging;
|
2020-07-12 21:03:45 +01:00
|
|
|
|
2022-11-15 15:58:40 +00:00
|
|
|
namespace Aaru.CommonTypes;
|
|
|
|
|
|
2022-03-06 13:29:30 +00:00
|
|
|
/// <summary>Gets the media type from a real device</summary>
|
|
|
|
|
public static partial class MediaTypeFromDevice
|
2020-07-12 21:03:45 +01:00
|
|
|
{
|
2022-03-06 13:29:30 +00:00
|
|
|
/// <summary>Gets the media type from an SCSI MultiMedia Commands compliant device</summary>
|
|
|
|
|
/// <param name="model">Model string</param>
|
|
|
|
|
/// <param name="mediumType">Medium type from MODE SENSE</param>
|
|
|
|
|
/// <param name="densityCode">Density code from MODE SENSE</param>
|
|
|
|
|
/// <param name="blocks">Number of blocks in media</param>
|
|
|
|
|
/// <param name="blockSize">Size of a block in bytes</param>
|
|
|
|
|
/// <param name="isUsb">Is the device USB attached</param>
|
|
|
|
|
/// <param name="opticalDisc">Is the media an optical disc</param>
|
|
|
|
|
/// <returns>Media type</returns>
|
|
|
|
|
static MediaType GetFromMmc(string model, byte mediumType, byte densityCode, ulong blocks, uint blockSize,
|
2023-10-03 22:48:28 +01:00
|
|
|
bool isUsb, bool opticalDisc)
|
2020-07-12 21:03:45 +01:00
|
|
|
{
|
2022-03-06 13:29:30 +00:00
|
|
|
switch(mediumType)
|
2020-07-12 21:03:45 +01:00
|
|
|
{
|
2022-03-06 13:29:30 +00:00
|
|
|
case 0x00:
|
|
|
|
|
if(blockSize == 512)
|
2023-10-03 22:48:28 +01:00
|
|
|
{
|
2022-03-06 13:29:30 +00:00
|
|
|
if(blocks == 1281856)
|
|
|
|
|
{
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME,
|
2025-11-24 19:38:40 +00:00
|
|
|
Localization
|
|
|
|
|
.SCSI_medium_type_is_0_media_has_1_blocks_of_2_bytes_setting_media_type_to_WORM_PD_650,
|
|
|
|
|
mediumType,
|
|
|
|
|
blocks,
|
|
|
|
|
blockSize);
|
2020-07-12 21:03:45 +01:00
|
|
|
|
2022-03-06 13:29:30 +00:00
|
|
|
return MediaType.PD650_WORM;
|
|
|
|
|
}
|
2020-07-12 21:03:45 +01:00
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME,
|
2025-11-24 19:38:40 +00:00
|
|
|
Localization
|
|
|
|
|
.SCSI_medium_type_is_0_media_has_1_blocks_of_2_bytes_setting_media_type_to_PD_650,
|
|
|
|
|
mediumType,
|
|
|
|
|
blocks,
|
|
|
|
|
blockSize);
|
2023-10-04 08:45:41 +01:00
|
|
|
|
|
|
|
|
return MediaType.PD650;
|
2023-10-03 22:48:28 +01:00
|
|
|
}
|
2020-07-12 21:03:45 +01:00
|
|
|
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME,
|
2025-11-24 19:38:40 +00:00
|
|
|
Localization.SCSI_medium_type_is_0_setting_media_type_to_Compact_Disc,
|
|
|
|
|
mediumType);
|
2022-11-14 00:59:58 +00:00
|
|
|
|
|
|
|
|
return MediaType.CD;
|
2022-03-06 13:29:30 +00:00
|
|
|
case 0x01:
|
|
|
|
|
case 0x05:
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME,
|
2025-11-24 19:38:40 +00:00
|
|
|
Localization.SCSI_medium_type_is_0_setting_media_type_to_CD_ROM,
|
|
|
|
|
mediumType);
|
2022-03-06 13:29:30 +00:00
|
|
|
|
|
|
|
|
return MediaType.CDROM;
|
|
|
|
|
case 0x02:
|
|
|
|
|
case 0x06:
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME,
|
2025-11-24 19:38:40 +00:00
|
|
|
Localization.SCSI_medium_type_is_0_setting_media_type_to_Compact_Disc_Digital_Audio,
|
|
|
|
|
mediumType);
|
2022-03-06 13:29:30 +00:00
|
|
|
|
|
|
|
|
return MediaType.CDDA;
|
|
|
|
|
case 0x03:
|
|
|
|
|
case 0x07:
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME,
|
2025-11-24 19:38:40 +00:00
|
|
|
Localization.SCSI_medium_type_is_0_setting_media_type_to_CD_Plus,
|
|
|
|
|
mediumType);
|
2022-03-06 13:29:30 +00:00
|
|
|
|
|
|
|
|
return MediaType.CDPLUS;
|
|
|
|
|
case 0x04:
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME,
|
2025-11-24 19:38:40 +00:00
|
|
|
Localization.SCSI_medium_type_is_0_setting_media_type_to_Photo_CD,
|
|
|
|
|
mediumType);
|
2022-03-06 13:29:30 +00:00
|
|
|
|
|
|
|
|
return MediaType.PCD;
|
|
|
|
|
case 0x10:
|
|
|
|
|
case 0x11:
|
|
|
|
|
case 0x12:
|
|
|
|
|
case 0x13:
|
|
|
|
|
case 0x14:
|
|
|
|
|
case 0x15:
|
|
|
|
|
case 0x16:
|
|
|
|
|
case 0x17:
|
|
|
|
|
case 0x18:
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME,
|
2025-11-24 19:38:40 +00:00
|
|
|
Localization.SCSI_medium_type_is_0_setting_media_type_to_CDR,
|
|
|
|
|
mediumType);
|
2022-03-06 13:29:30 +00:00
|
|
|
|
|
|
|
|
return MediaType.CDR;
|
|
|
|
|
case 0x20:
|
|
|
|
|
case 0x21:
|
|
|
|
|
case 0x22:
|
|
|
|
|
case 0x23:
|
|
|
|
|
case 0x24:
|
|
|
|
|
case 0x25:
|
|
|
|
|
case 0x26:
|
|
|
|
|
case 0x27:
|
|
|
|
|
case 0x28:
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME,
|
2025-11-24 19:38:40 +00:00
|
|
|
Localization.SCSI_medium_type_is_0_setting_media_type_to_CDRW,
|
|
|
|
|
mediumType);
|
2022-03-06 13:29:30 +00:00
|
|
|
|
|
|
|
|
return MediaType.CDRW;
|
|
|
|
|
case 0x40 when isUsb && !opticalDisc:
|
|
|
|
|
case 0x41 when isUsb && !opticalDisc:
|
|
|
|
|
case 0x42 when isUsb && !opticalDisc:
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME,
|
2025-11-24 19:38:40 +00:00
|
|
|
Localization
|
|
|
|
|
.SCSI_medium_type_is_0_and_device_is_USB_setting_media_type_to_Flash_Drive,
|
|
|
|
|
mediumType);
|
2022-03-06 13:29:30 +00:00
|
|
|
|
|
|
|
|
return MediaType.FlashDrive;
|
|
|
|
|
case 0x80:
|
|
|
|
|
if(model.ToLowerInvariant().StartsWith("ult", StringComparison.Ordinal))
|
2023-10-03 22:48:28 +01:00
|
|
|
{
|
2022-03-06 13:29:30 +00:00
|
|
|
switch(densityCode)
|
|
|
|
|
{
|
|
|
|
|
case 0x42:
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME,
|
2025-11-24 19:38:40 +00:00
|
|
|
Localization
|
|
|
|
|
.SCSI_medium_type_is_0_density_code_is_1_drive_starts_with_ult_setting_media_type_to_LTO2,
|
|
|
|
|
mediumType,
|
|
|
|
|
densityCode);
|
2020-07-12 21:03:45 +01:00
|
|
|
|
2022-03-06 13:29:30 +00:00
|
|
|
return MediaType.LTO2;
|
|
|
|
|
case 0x44:
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME,
|
2025-11-24 19:38:40 +00:00
|
|
|
Localization
|
|
|
|
|
.SCSI_medium_type_is_0_density_code_is_1_drive_starts_with_ult_setting_media_type_to_LTO3,
|
|
|
|
|
mediumType,
|
|
|
|
|
densityCode);
|
2020-07-12 21:03:45 +01:00
|
|
|
|
2022-03-06 13:29:30 +00:00
|
|
|
return MediaType.LTO3;
|
|
|
|
|
case 0x46:
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME,
|
2025-11-24 19:38:40 +00:00
|
|
|
Localization
|
|
|
|
|
.SCSI_medium_type_is_0_density_code_is_1_drive_starts_with_ult_setting_media_type_to_LTO4,
|
|
|
|
|
mediumType,
|
|
|
|
|
densityCode);
|
2020-07-12 21:03:45 +01:00
|
|
|
|
2022-03-06 13:29:30 +00:00
|
|
|
return MediaType.LTO4;
|
|
|
|
|
case 0x58:
|
2025-08-17 06:11:22 +01:00
|
|
|
AaruLogging.Debug(MODULE_NAME,
|
2025-11-24 19:38:40 +00:00
|
|
|
Localization
|
|
|
|
|
.SCSI_medium_type_is_0_density_code_is_1_drive_starts_with_ult_setting_media_type_to_LTO5,
|
|
|
|
|
mediumType,
|
|
|
|
|
densityCode);
|
2020-07-12 21:03:45 +01:00
|
|
|
|
2022-03-06 13:29:30 +00:00
|
|
|
return MediaType.LTO5;
|
|
|
|
|
}
|
2023-10-03 22:48:28 +01:00
|
|
|
}
|
2020-12-03 18:19:05 +00:00
|
|
|
|
2022-03-06 13:29:30 +00:00
|
|
|
break;
|
2020-07-12 21:03:45 +01:00
|
|
|
}
|
2022-03-06 13:29:30 +00:00
|
|
|
|
|
|
|
|
return MediaType.Unknown;
|
2020-07-12 21:03:45 +01:00
|
|
|
}
|
|
|
|
|
}
|