Ejemplo n.º 1
0
Archivo: SSC.cs Proyecto: paulyc/Aaru
        public TestedSequentialMedia ReportSscMedia()
        {
            var seqTest = new TestedSequentialMedia();

            Modes.DecodedMode?decMode = null;

            AaruConsole.WriteLine("Querying SCSI MODE SENSE (10)...");

            bool sense = _dev.ModeSense10(out byte[] buffer, out byte[] _, false, true,
                                          ScsiModeSensePageControl.Current, 0x3F, 0x00, _dev.Timeout, out _);

            if (!sense &&
                !_dev.Error)
            {
                decMode = Modes.DecodeMode10(buffer, _dev.ScsiType);
                seqTest.ModeSense10Data = buffer;
            }

            AaruConsole.WriteLine("Querying SCSI MODE SENSE...");
            sense = _dev.ModeSense(out buffer, out byte[] _, _dev.Timeout, out _);

            if (!sense &&
                !_dev.Error)
            {
                decMode ??= Modes.DecodeMode6(buffer, _dev.ScsiType);

                seqTest.ModeSense6Data = buffer;
            }

            if (decMode.HasValue)
            {
                seqTest.MediumType = (byte)decMode.Value.Header.MediumType;

                if (decMode.Value.Header.BlockDescriptors?.Length > 0)
                {
                    seqTest.Density = (byte)decMode.Value.Header.BlockDescriptors?[0].Density;
                }
            }

            AaruConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT for current media...");
            sense = _dev.ReportDensitySupport(out buffer, out byte[] _, false, true, _dev.Timeout, out _);

            if (!sense)
            {
                DensitySupport.DensitySupportHeader?dsh = DensitySupport.DecodeDensity(buffer);

                if (dsh.HasValue)
                {
                    SupportedDensity[] array = new SupportedDensity[dsh.Value.descriptors.Length];

                    for (int i = 0; i < dsh.Value.descriptors.Length; i++)
                    {
                        array[i] = new SupportedDensity
                        {
                            BitsPerMm      = dsh.Value.descriptors[i].bpmm,
                            Capacity       = dsh.Value.descriptors[i].capacity,
                            DefaultDensity = dsh.Value.descriptors[i].defaultDensity,
                            Description    = dsh.Value.descriptors[i].description,
                            Duplicate      = dsh.Value.descriptors[i].duplicate,
                            Name           = dsh.Value.descriptors[i].name,
                            Organization   = dsh.Value.descriptors[i].organization,
                            PrimaryCode    = dsh.Value.descriptors[i].primaryCode,
                            SecondaryCode  = dsh.Value.descriptors[i].secondaryCode,
                            Tracks         = dsh.Value.descriptors[i].tracks,
                            Width          = dsh.Value.descriptors[i].width,
                            Writable       = dsh.Value.descriptors[i].writable
                        }
                    }
                    ;

                    seqTest.SupportedDensities = array.ToList();
                }
            }

            AaruConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT for medium types for current media...");
            sense = _dev.ReportDensitySupport(out buffer, out byte[] _, true, true, _dev.Timeout, out _);

            if (!sense)
            {
                DensitySupport.MediaTypeSupportHeader?mtsh = DensitySupport.DecodeMediumType(buffer);

                if (mtsh.HasValue)
                {
                    SscSupportedMedia[] array = new SscSupportedMedia[mtsh.Value.descriptors.Length];

                    for (int i = 0; i < mtsh.Value.descriptors.Length; i++)
                    {
                        array[i] = new SscSupportedMedia
                        {
                            Description  = mtsh.Value.descriptors[i].description,
                            Length       = mtsh.Value.descriptors[i].length,
                            MediumType   = mtsh.Value.descriptors[i].mediumType,
                            Name         = mtsh.Value.descriptors[i].name,
                            Organization = mtsh.Value.descriptors[i].organization,
                            Width        = mtsh.Value.descriptors[i].width
                        };

                        if (mtsh.Value.descriptors[i].densityCodes == null)
                        {
                            continue;
                        }

                        DensityCode[] array2 = new DensityCode[mtsh.Value.descriptors[i].densityCodes.Length];

                        for (int j = 0; j < mtsh.Value.descriptors[i].densityCodes.Length; j++)
                        {
                            array2[j] = new DensityCode
                            {
                                Code = mtsh.Value.descriptors[i].densityCodes[j]
                            }
                        }
                        ;

                        array[i].DensityCodes = array2.Distinct().ToList();
                    }

                    seqTest.SupportedMediaTypes = array.ToList();
                }
            }

            AaruConsole.WriteLine("Trying SCSI READ MEDIA SERIAL NUMBER...");
            seqTest.CanReadMediaSerial = !_dev.ReadMediaSerialNumber(out buffer, out byte[] _, _dev.Timeout, out _);

            return(seqTest);
        }
    }
}
Ejemplo n.º 2
0
Archivo: SSC.cs Proyecto: paulyc/Aaru
        public Ssc ReportScsiSsc()
        {
            var report = new Ssc();

            AaruConsole.WriteLine("Querying SCSI READ BLOCK LIMITS...");
            bool sense = _dev.ReadBlockLimits(out byte[] buffer, out byte[] _, _dev.Timeout, out _);

            if (!sense)
            {
                BlockLimits.BlockLimitsData?decBl = BlockLimits.Decode(buffer);

                if (decBl?.granularity > 0)
                {
                    report.BlockSizeGranularity = decBl.Value.granularity;
                }

                if (decBl?.maxBlockLen > 0)
                {
                    report.MaxBlockLength = decBl.Value.maxBlockLen;
                }

                if (decBl?.minBlockLen > 0)
                {
                    report.MinBlockLength = decBl.Value.minBlockLen;
                }
            }

            AaruConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT...");
            sense = _dev.ReportDensitySupport(out buffer, out byte[] _, false, false, _dev.Timeout, out _);

            if (!sense)
            {
                DensitySupport.DensitySupportHeader?dsh = DensitySupport.DecodeDensity(buffer);

                if (dsh.HasValue)
                {
                    SupportedDensity[] array = new SupportedDensity[dsh.Value.descriptors.Length];

                    for (int i = 0; i < dsh.Value.descriptors.Length; i++)
                    {
                        array[i] = new SupportedDensity
                        {
                            BitsPerMm      = dsh.Value.descriptors[i].bpmm,
                            Capacity       = dsh.Value.descriptors[i].capacity,
                            DefaultDensity = dsh.Value.descriptors[i].defaultDensity,
                            Description    = dsh.Value.descriptors[i].description,
                            Duplicate      = dsh.Value.descriptors[i].duplicate,
                            Name           = dsh.Value.descriptors[i].name,
                            Organization   = dsh.Value.descriptors[i].organization,
                            PrimaryCode    = dsh.Value.descriptors[i].primaryCode,
                            SecondaryCode  = dsh.Value.descriptors[i].secondaryCode,
                            Tracks         = dsh.Value.descriptors[i].tracks,
                            Width          = dsh.Value.descriptors[i].width,
                            Writable       = dsh.Value.descriptors[i].writable
                        }
                    }
                    ;

                    report.SupportedDensities = array.ToList();
                }
            }

            AaruConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT for medium types...");
            sense = _dev.ReportDensitySupport(out buffer, out byte[] _, true, false, _dev.Timeout, out _);

            if (sense)
            {
                return(report);
            }

            DensitySupport.MediaTypeSupportHeader?mtsh = DensitySupport.DecodeMediumType(buffer);

            if (!mtsh.HasValue)
            {
                return(report);
            }

            SscSupportedMedia[] array2 = new SscSupportedMedia[mtsh.Value.descriptors.Length];

            for (int i = 0; i < mtsh.Value.descriptors.Length; i++)
            {
                array2[i] = new SscSupportedMedia
                {
                    Description  = mtsh.Value.descriptors[i].description,
                    Length       = mtsh.Value.descriptors[i].length,
                    MediumType   = mtsh.Value.descriptors[i].mediumType,
                    Name         = mtsh.Value.descriptors[i].name,
                    Organization = mtsh.Value.descriptors[i].organization,
                    Width        = mtsh.Value.descriptors[i].width
                };

                if (mtsh.Value.descriptors[i].densityCodes == null)
                {
                    continue;
                }

                DensityCode[] array3 = new DensityCode[mtsh.Value.descriptors[i].densityCodes.Length];

                for (int j = 0; j < mtsh.Value.descriptors[i].densityCodes.Length; j++)
                {
                    array3[j] = new DensityCode
                    {
                        Code = mtsh.Value.descriptors[i].densityCodes[j]
                    }
                }
                ;

                array2[i].DensityCodes = array3.Distinct().ToList();
            }

            report.SupportedMediaTypes = array2.ToList();

            return(report);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Fills a SCSI device report with parameters and media tests specific to a Streaming device
        /// </summary>
        /// <param name="dev">Device</param>
        /// <param name="report">Device report</param>
        /// <param name="debug">If debug is enabled</param>
        internal static void Report(Device dev, ref DeviceReport report, bool debug)
        {
            if (report == null)
            {
                return;
            }

            bool           sense;
            const uint     TIMEOUT = 5;
            ConsoleKeyInfo pressedKey;

            report.SCSI.SequentialDevice = new sscType();
            DicConsole.WriteLine("Querying SCSI READ BLOCK LIMITS...");
            sense = dev.ReadBlockLimits(out byte[] buffer, out byte[] senseBuffer, TIMEOUT, out _);
            if (!sense)
            {
                BlockLimits.BlockLimitsData?decBl = BlockLimits.Decode(buffer);
                if (decBl.HasValue)
                {
                    if (decBl.Value.granularity > 0)
                    {
                        report.SCSI.SequentialDevice.BlockSizeGranularitySpecified = true;
                        report.SCSI.SequentialDevice.BlockSizeGranularity          = decBl.Value.granularity;
                    }

                    if (decBl.Value.maxBlockLen > 0)
                    {
                        report.SCSI.SequentialDevice.MaxBlockLengthSpecified = true;
                        report.SCSI.SequentialDevice.MaxBlockLength          = decBl.Value.maxBlockLen;
                    }

                    if (decBl.Value.minBlockLen > 0)
                    {
                        report.SCSI.SequentialDevice.MinBlockLengthSpecified = true;
                        report.SCSI.SequentialDevice.MinBlockLength          = decBl.Value.minBlockLen;
                    }
                }
            }

            DicConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT...");
            sense = dev.ReportDensitySupport(out buffer, out senseBuffer, false, false, TIMEOUT, out _);
            if (!sense)
            {
                DensitySupport.DensitySupportHeader?dsh = DensitySupport.DecodeDensity(buffer);
                if (dsh.HasValue)
                {
                    report.SCSI.SequentialDevice.SupportedDensities =
                        new SupportedDensity[dsh.Value.descriptors.Length];
                    for (int i = 0; i < dsh.Value.descriptors.Length; i++)
                    {
                        report.SCSI.SequentialDevice.SupportedDensities[i].BitsPerMm = dsh.Value.descriptors[i].bpmm;
                        report.SCSI.SequentialDevice.SupportedDensities[i].Capacity  =
                            dsh.Value.descriptors[i].capacity;
                        report.SCSI.SequentialDevice.SupportedDensities[i].DefaultDensity =
                            dsh.Value.descriptors[i].defaultDensity;
                        report.SCSI.SequentialDevice.SupportedDensities[i].Description =
                            dsh.Value.descriptors[i].description;
                        report.SCSI.SequentialDevice.SupportedDensities[i].Duplicate =
                            dsh.Value.descriptors[i].duplicate;
                        report.SCSI.SequentialDevice.SupportedDensities[i].Name         = dsh.Value.descriptors[i].name;
                        report.SCSI.SequentialDevice.SupportedDensities[i].Organization =
                            dsh.Value.descriptors[i].organization;
                        report.SCSI.SequentialDevice.SupportedDensities[i].PrimaryCode =
                            dsh.Value.descriptors[i].primaryCode;
                        report.SCSI.SequentialDevice.SupportedDensities[i].SecondaryCode =
                            dsh.Value.descriptors[i].secondaryCode;
                        report.SCSI.SequentialDevice.SupportedDensities[i].Tracks   = dsh.Value.descriptors[i].tracks;
                        report.SCSI.SequentialDevice.SupportedDensities[i].Width    = dsh.Value.descriptors[i].width;
                        report.SCSI.SequentialDevice.SupportedDensities[i].Writable = dsh.Value.descriptors[i].writable;
                    }
                }
            }

            DicConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT for medium types...");
            sense = dev.ReportDensitySupport(out buffer, out senseBuffer, true, false, TIMEOUT, out _);
            if (!sense)
            {
                DensitySupport.MediaTypeSupportHeader?mtsh = DensitySupport.DecodeMediumType(buffer);
                if (mtsh.HasValue)
                {
                    report.SCSI.SequentialDevice.SupportedMediaTypes =
                        new SupportedMedia[mtsh.Value.descriptors.Length];
                    for (int i = 0; i < mtsh.Value.descriptors.Length; i++)
                    {
                        report.SCSI.SequentialDevice.SupportedMediaTypes[i].Description =
                            mtsh.Value.descriptors[i].description;
                        report.SCSI.SequentialDevice.SupportedMediaTypes[i].Length     = mtsh.Value.descriptors[i].length;
                        report.SCSI.SequentialDevice.SupportedMediaTypes[i].MediumType =
                            mtsh.Value.descriptors[i].mediumType;
                        report.SCSI.SequentialDevice.SupportedMediaTypes[i].Name         = mtsh.Value.descriptors[i].name;
                        report.SCSI.SequentialDevice.SupportedMediaTypes[i].Organization =
                            mtsh.Value.descriptors[i].organization;
                        report.SCSI.SequentialDevice.SupportedMediaTypes[i].Width = mtsh.Value.descriptors[i].width;
                        if (mtsh.Value.descriptors[i].densityCodes == null)
                        {
                            continue;
                        }

                        report.SCSI.SequentialDevice.SupportedMediaTypes[i].DensityCodes =
                            new int[mtsh.Value.descriptors[i].densityCodes.Length];
                        for (int j = 0; j < mtsh.Value.descriptors.Length; j++)
                        {
                            report.SCSI.SequentialDevice.SupportedMediaTypes[i].DensityCodes[j] =
                                mtsh.Value.descriptors[i].densityCodes[j];
                        }
                    }
                }
            }

            List <SequentialMedia> seqTests = new List <SequentialMedia>();

            pressedKey = new ConsoleKeyInfo();
            while (pressedKey.Key != ConsoleKey.N)
            {
                pressedKey = new ConsoleKeyInfo();
                while (pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N)
                {
                    DicConsole.Write("Do you have media that you can insert in the drive? (Y/N): ");
                    pressedKey = System.Console.ReadKey();
                    DicConsole.WriteLine();
                }

                if (pressedKey.Key != ConsoleKey.Y)
                {
                    continue;
                }

                DicConsole.WriteLine("Please insert it in the drive and press any key when it is ready.");
                System.Console.ReadKey(true);

                SequentialMedia seqTest = new SequentialMedia();
                DicConsole.Write("Please write a description of the media type and press enter: ");
                seqTest.MediumTypeName = System.Console.ReadLine();
                DicConsole.Write("Please write the media manufacturer and press enter: ");
                seqTest.Manufacturer = System.Console.ReadLine();
                DicConsole.Write("Please write the media model and press enter: ");
                seqTest.Model = System.Console.ReadLine();

                seqTest.MediaIsRecognized = true;

                dev.Load(out senseBuffer, TIMEOUT, out _);
                sense = dev.ScsiTestUnitReady(out senseBuffer, TIMEOUT, out _);
                if (sense)
                {
                    FixedSense?decSense = Sense.DecodeFixed(senseBuffer);
                    if (decSense.HasValue)
                    {
                        if (decSense.Value.ASC == 0x3A)
                        {
                            int leftRetries = 20;
                            while (leftRetries > 0)
                            {
                                DicConsole.Write("\rWaiting for drive to become ready");
                                Thread.Sleep(2000);
                                sense = dev.ScsiTestUnitReady(out senseBuffer, TIMEOUT, out _);
                                if (!sense)
                                {
                                    break;
                                }

                                leftRetries--;
                            }

                            seqTest.MediaIsRecognized &= !sense;
                        }
                        else if (decSense.Value.ASC == 0x04 && decSense.Value.ASCQ == 0x01)
                        {
                            int leftRetries = 20;
                            while (leftRetries > 0)
                            {
                                DicConsole.Write("\rWaiting for drive to become ready");
                                Thread.Sleep(2000);
                                sense = dev.ScsiTestUnitReady(out senseBuffer, TIMEOUT, out _);
                                if (!sense)
                                {
                                    break;
                                }

                                leftRetries--;
                            }

                            seqTest.MediaIsRecognized &= !sense;
                        }
                        else
                        {
                            seqTest.MediaIsRecognized = false;
                        }
                    }
                    else
                    {
                        seqTest.MediaIsRecognized = false;
                    }
                }

                if (seqTest.MediaIsRecognized)
                {
                    Modes.DecodedMode?decMode = null;

                    DicConsole.WriteLine("Querying SCSI MODE SENSE (10)...");
                    sense = dev.ModeSense10(out buffer, out senseBuffer, false, true, ScsiModeSensePageControl.Current,
                                            0x3F, 0x00, TIMEOUT, out _);
                    if (!sense && !dev.Error)
                    {
                        report.SCSI.SupportsModeSense10 = true;
                        decMode = Modes.DecodeMode10(buffer, dev.ScsiType);
                        if (debug)
                        {
                            seqTest.ModeSense10Data = buffer;
                        }
                    }

                    DicConsole.WriteLine("Querying SCSI MODE SENSE...");
                    sense = dev.ModeSense(out buffer, out senseBuffer, TIMEOUT, out _);
                    if (!sense && !dev.Error)
                    {
                        report.SCSI.SupportsModeSense6 = true;
                        if (!decMode.HasValue)
                        {
                            decMode = Modes.DecodeMode6(buffer, dev.ScsiType);
                        }
                        if (debug)
                        {
                            seqTest.ModeSense6Data = buffer;
                        }
                    }

                    if (decMode.HasValue)
                    {
                        seqTest.MediumType          = (byte)decMode.Value.Header.MediumType;
                        seqTest.MediumTypeSpecified = true;
                        if (decMode.Value.Header.BlockDescriptors != null &&
                            decMode.Value.Header.BlockDescriptors.Length > 0)
                        {
                            seqTest.Density          = (byte)decMode.Value.Header.BlockDescriptors[0].Density;
                            seqTest.DensitySpecified = true;
                        }
                    }
                }

                DicConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT for current media...");
                sense = dev.ReportDensitySupport(out buffer, out senseBuffer, false, true, TIMEOUT, out _);
                if (!sense)
                {
                    DensitySupport.DensitySupportHeader?dsh = DensitySupport.DecodeDensity(buffer);
                    if (dsh.HasValue)
                    {
                        seqTest.SupportedDensities = new SupportedDensity[dsh.Value.descriptors.Length];
                        for (int i = 0; i < dsh.Value.descriptors.Length; i++)
                        {
                            seqTest.SupportedDensities[i].BitsPerMm      = dsh.Value.descriptors[i].bpmm;
                            seqTest.SupportedDensities[i].Capacity       = dsh.Value.descriptors[i].capacity;
                            seqTest.SupportedDensities[i].DefaultDensity = dsh.Value.descriptors[i].defaultDensity;
                            seqTest.SupportedDensities[i].Description    = dsh.Value.descriptors[i].description;
                            seqTest.SupportedDensities[i].Duplicate      = dsh.Value.descriptors[i].duplicate;
                            seqTest.SupportedDensities[i].Name           = dsh.Value.descriptors[i].name;
                            seqTest.SupportedDensities[i].Organization   = dsh.Value.descriptors[i].organization;
                            seqTest.SupportedDensities[i].PrimaryCode    = dsh.Value.descriptors[i].primaryCode;
                            seqTest.SupportedDensities[i].SecondaryCode  = dsh.Value.descriptors[i].secondaryCode;
                            seqTest.SupportedDensities[i].Tracks         = dsh.Value.descriptors[i].tracks;
                            seqTest.SupportedDensities[i].Width          = dsh.Value.descriptors[i].width;
                            seqTest.SupportedDensities[i].Writable       = dsh.Value.descriptors[i].writable;
                        }
                    }
                }

                DicConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT for medium types for current media...");
                sense = dev.ReportDensitySupport(out buffer, out senseBuffer, true, true, TIMEOUT, out _);
                if (!sense)
                {
                    DensitySupport.MediaTypeSupportHeader?mtsh = DensitySupport.DecodeMediumType(buffer);
                    if (mtsh.HasValue)
                    {
                        seqTest.SupportedMediaTypes = new SupportedMedia[mtsh.Value.descriptors.Length];
                        for (int i = 0; i < mtsh.Value.descriptors.Length; i++)
                        {
                            seqTest.SupportedMediaTypes[i].Description  = mtsh.Value.descriptors[i].description;
                            seqTest.SupportedMediaTypes[i].Length       = mtsh.Value.descriptors[i].length;
                            seqTest.SupportedMediaTypes[i].MediumType   = mtsh.Value.descriptors[i].mediumType;
                            seqTest.SupportedMediaTypes[i].Name         = mtsh.Value.descriptors[i].name;
                            seqTest.SupportedMediaTypes[i].Organization = mtsh.Value.descriptors[i].organization;
                            seqTest.SupportedMediaTypes[i].Width        = mtsh.Value.descriptors[i].width;
                            if (mtsh.Value.descriptors[i].densityCodes == null)
                            {
                                continue;
                            }

                            seqTest.SupportedMediaTypes[i].DensityCodes =
                                new int[mtsh.Value.descriptors[i].densityCodes.Length];
                            for (int j = 0; j < mtsh.Value.descriptors.Length; j++)
                            {
                                seqTest.SupportedMediaTypes[i].DensityCodes[j] =
                                    mtsh.Value.descriptors[i].densityCodes[j];
                            }
                        }
                    }
                }

                seqTest.CanReadMediaSerialSpecified = true;
                DicConsole.WriteLine("Trying SCSI READ MEDIA SERIAL NUMBER...");
                seqTest.CanReadMediaSerial = !dev.ReadMediaSerialNumber(out buffer, out senseBuffer, TIMEOUT, out _);
                seqTests.Add(seqTest);
            }

            report.SCSI.SequentialDevice.TestedMedia = seqTests.ToArray();
        }