public Scsi ReportScsiInquiry() { DicConsole.WriteLine("Querying SCSI INQUIRY..."); bool sense = _dev.ScsiInquiry(out byte[] buffer, out byte[] senseBuffer); var report = new Scsi(); if (sense) { return(null); } Inquiry.SCSIInquiry?decodedNullable = Inquiry.Decode(buffer); if (!decodedNullable.HasValue) { return(null); } Inquiry.SCSIInquiry decoded = decodedNullable.Value; // Clear Seagate serial number if (decoded.SeagatePresent && StringHandlers.CToString(decoded.VendorIdentification)?.Trim().ToLowerInvariant() == "seagate") { for (int i = 36; i <= 43; i++) { buffer[i] = 0; } } report.InquiryData = buffer; return(report); }
public Scsi ReportScsiInquiry() { AaruConsole.WriteLine("Querying SCSI INQUIRY..."); bool sense = _dev.ScsiInquiry(out byte[] buffer, out _); var report = new Scsi(); if (sense) { return(null); } Inquiry?decodedNullable = Inquiry.Decode(buffer); if (!decodedNullable.HasValue) { return(null); } report.InquiryData = ClearInquiry(buffer); return(report); }
internal static void DoMediaScan(MediaScanOptions options) { DicConsole.DebugWriteLine("Media-Scan command", "--debug={0}", options.Debug); DicConsole.DebugWriteLine("Media-Scan command", "--verbose={0}", options.Verbose); DicConsole.DebugWriteLine("Media-Scan command", "--device={0}", options.DevicePath); DicConsole.DebugWriteLine("Media-Scan command", "--mhdd-log={0}", options.MhddLogPath); DicConsole.DebugWriteLine("Media-Scan command", "--ibg-log={0}", options.IbgLogPath); if (options.DevicePath.Length == 2 && options.DevicePath[1] == ':' && options.DevicePath[0] != '/' && char.IsLetter(options.DevicePath[0])) { options.DevicePath = "\\\\.\\" + char.ToUpper(options.DevicePath[0]) + ':'; } Device dev = new Device(options.DevicePath); if (dev.Error) { DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError); return; } Core.Statistics.AddDevice(dev); ScanResults results; switch (dev.Type) { case DeviceType.ATA: results = Ata.Scan(options.MhddLogPath, options.IbgLogPath, options.DevicePath, dev); break; case DeviceType.MMC: case DeviceType.SecureDigital: results = SecureDigital.Scan(options.MhddLogPath, options.IbgLogPath, options.DevicePath, dev); break; case DeviceType.NVMe: results = Nvme.Scan(options.MhddLogPath, options.IbgLogPath, options.DevicePath, dev); break; case DeviceType.ATAPI: case DeviceType.SCSI: results = Scsi.Scan(options.MhddLogPath, options.IbgLogPath, options.DevicePath, dev); break; default: throw new NotSupportedException("Unknown device type."); } DicConsole.WriteLine("Took a total of {0} seconds ({1} processing commands).", results.TotalTime, results.ProcessingTime); DicConsole.WriteLine("Avegare speed: {0:F3} MiB/sec.", results.AvgSpeed); DicConsole.WriteLine("Fastest speed burst: {0:F3} MiB/sec.", results.MaxSpeed); DicConsole.WriteLine("Slowest speed burst: {0:F3} MiB/sec.", results.MinSpeed); DicConsole.WriteLine("Summary:"); DicConsole.WriteLine("{0} sectors took less than 3 ms.", results.A); DicConsole.WriteLine("{0} sectors took less than 10 ms but more than 3 ms.", results.B); DicConsole.WriteLine("{0} sectors took less than 50 ms but more than 10 ms.", results.C); DicConsole.WriteLine("{0} sectors took less than 150 ms but more than 50 ms.", results.D); DicConsole.WriteLine("{0} sectors took less than 500 ms but more than 150 ms.", results.E); DicConsole.WriteLine("{0} sectors took more than 500 ms.", results.F); DicConsole.WriteLine("{0} sectors could not be read.", results.UnreadableSectors.Count); if (results.UnreadableSectors.Count > 0) { foreach (ulong bad in results.UnreadableSectors) { DicConsole.WriteLine("Sector {0} could not be read", bad); } } DicConsole.WriteLine(); #pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator if (results.SeekTotal != 0 || results.SeekMin != double.MaxValue || results.SeekMax != double.MinValue) #pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator { DicConsole.WriteLine("Testing {0} seeks, longest seek took {1:F3} ms, fastest one took {2:F3} ms. ({3:F3} ms average)", results.SeekTimes, results.SeekMax, results.SeekMin, results.SeekTotal / 1000); } Core.Statistics.AddMediaScan((long)results.A, (long)results.B, (long)results.C, (long)results.D, (long)results.E, (long)results.F, (long)results.Blocks, (long)results.Errored, (long)(results.Blocks - results.Errored)); Core.Statistics.AddCommand("media-scan"); }
public override void Run() { // Login VapiAuthHelper = new VapiAuthenticationHelper(); SessionStubConfiguration = VapiAuthHelper.LoginByUsernameAndPassword( Server, UserName, Password); this.scsiService = VapiAuthHelper.StubFactory.CreateStub <Scsi>( SessionStubConfiguration); Console.WriteLine("\n\n#### Setup: Get the virtual machine id"); this.vmId = VmHelper.GetVm(VapiAuthHelper.StubFactory, SessionStubConfiguration, VmName); Console.WriteLine("Using VM: " + VmName + " (vmId=" + this.vmId + ") for SCSI adapter configuration sample"); Console.WriteLine("\n\n#### Example: List of all SCSI adapters " + "on the VM"); List <ScsiTypes.Summary> scsiSummaries = this.scsiService.List(this.vmId); scsiSummaries.ForEach(i => Console.WriteLine(i)); Console.WriteLine("\n\n#### Display information about each " + "adapter"); foreach (ScsiTypes.Summary scsiSummary in scsiSummaries) { ScsiTypes.Info info = this.scsiService.Get(this.vmId, scsiSummary.GetAdapter()); Console.WriteLine(info); } Console.WriteLine("\n\n#### Example: Create SCSI adapter with " + "defaults."); ScsiTypes.CreateSpec scsiCreateSpec = new ScsiTypes.CreateSpec(); string scsiId = this.scsiService.Create(this.vmId, scsiCreateSpec); Console.WriteLine(scsiCreateSpec); ScsiTypes.Info scsiInfo = this.scsiService.Get(this.vmId, scsiId); Console.WriteLine("SCSI Adapter ID=" + scsiId); Console.WriteLine(scsiInfo); this.createdScsiAdapters.Add(scsiId); Console.WriteLine("\n\n#### Create SCSI adapter with specific " + "bus and sharing=true"); scsiCreateSpec = new ScsiTypes.CreateSpec(); scsiCreateSpec.SetBus(2L); scsiCreateSpec.SetSharing(ScsiTypes.Sharing.VIRTUAL); scsiId = this.scsiService.Create(this.vmId, scsiCreateSpec); Console.WriteLine(scsiCreateSpec); scsiInfo = this.scsiService.Get(this.vmId, scsiId); Console.WriteLine("SCSI Adapter ID=" + scsiId); Console.WriteLine(scsiInfo); this.createdScsiAdapters.Add(scsiId); Console.WriteLine("\n\n#### Update SCSI adapter by setting " + "sharing=false"); ScsiTypes.UpdateSpec scsiUpdateSpec = new ScsiTypes.UpdateSpec(); scsiUpdateSpec.SetSharing(ScsiTypes.Sharing.NONE); this.scsiService.Update(this.vmId, scsiId, scsiUpdateSpec); Console.WriteLine(scsiUpdateSpec); scsiInfo = this.scsiService.Get(this.vmId, scsiId); Console.WriteLine("SCSI Adapter ID=" + scsiId); Console.WriteLine(scsiInfo); // List all SCSI adapters for a VM Console.WriteLine("\n\n#### List all SCSI adapters on the VM"); scsiSummaries = this.scsiService.List(this.vmId); scsiSummaries.ForEach(i => Console.WriteLine(i)); }
internal static void DoDumpMedia(DumpMediaOptions options) { // TODO: Be able to cancel hashing Sidecar.InitProgressEvent += Progress.InitProgress; Sidecar.UpdateProgressEvent += Progress.UpdateProgress; Sidecar.EndProgressEvent += Progress.EndProgress; Sidecar.InitProgressEvent2 += Progress.InitProgress2; Sidecar.UpdateProgressEvent2 += Progress.UpdateProgress2; Sidecar.EndProgressEvent2 += Progress.EndProgress2; Sidecar.UpdateStatusEvent += Progress.UpdateStatus; DicConsole.DebugWriteLine("Dump-Media command", "--debug={0}", options.Debug); DicConsole.DebugWriteLine("Dump-Media command", "--verbose={0}", options.Verbose); DicConsole.DebugWriteLine("Dump-Media command", "--device={0}", options.DevicePath); DicConsole.DebugWriteLine("Dump-Media command", "--raw={0}", options.Raw); DicConsole.DebugWriteLine("Dump-Media command", "--stop-on-error={0}", options.StopOnError); DicConsole.DebugWriteLine("Dump-Media command", "--force={0}", options.Force); DicConsole.DebugWriteLine("Dump-Media command", "--retry-passes={0}", options.RetryPasses); DicConsole.DebugWriteLine("Dump-Media command", "--persistent={0}", options.Persistent); DicConsole.DebugWriteLine("Dump-Media command", "--resume={0}", options.Resume); DicConsole.DebugWriteLine("Dump-Media command", "--lead-in={0}", options.LeadIn); DicConsole.DebugWriteLine("Dump-Media command", "--encoding={0}", options.EncodingName); DicConsole.DebugWriteLine("Dump-Media command", "--output={0}", options.OutputFile); DicConsole.DebugWriteLine("Dump-Media command", "--format={0}", options.OutputFormat); DicConsole.DebugWriteLine("Dump-Media command", "--force={0}", options.Force); DicConsole.DebugWriteLine("Dump-Media command", "--options={0}", options.Options); DicConsole.DebugWriteLine("Dump-Media command", "--cicm-xml={0}", options.CicmXml); DicConsole.DebugWriteLine("Dump-Media command", "--skip={0}", options.Skip); DicConsole.DebugWriteLine("Dump-Media command", "--no-metadata={0}", options.NoMetadata); Dictionary <string, string> parsedOptions = Options.Parse(options.Options); DicConsole.DebugWriteLine("Dump-Media command", "Parsed options:"); foreach (KeyValuePair <string, string> parsedOption in parsedOptions) { DicConsole.DebugWriteLine("Dump-Media command", "{0} = {1}", parsedOption.Key, parsedOption.Value); } Encoding encoding = null; if (options.EncodingName != null) { try { encoding = Claunia.Encoding.Encoding.GetEncoding(options.EncodingName); if (options.Verbose) { DicConsole.VerboseWriteLine("Using encoding for {0}.", encoding.EncodingName); } } catch (ArgumentException) { DicConsole.ErrorWriteLine("Specified encoding is not supported."); return; } } if (options.DevicePath.Length == 2 && options.DevicePath[1] == ':' && options.DevicePath[0] != '/' && char.IsLetter(options.DevicePath[0])) { options.DevicePath = "\\\\.\\" + char.ToUpper(options.DevicePath[0]) + ':'; } Device dev = new Device(options.DevicePath); if (dev.Error) { DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError); return; } Core.Statistics.AddDevice(dev); string outputPrefix = Path.Combine(Path.GetDirectoryName(options.OutputFile), Path.GetFileNameWithoutExtension(options.OutputFile)); Resume resume = null; XmlSerializer xs = new XmlSerializer(typeof(Resume)); if (File.Exists(outputPrefix + ".resume.xml") && options.Resume) { try { StreamReader sr = new StreamReader(outputPrefix + ".resume.xml"); resume = (Resume)xs.Deserialize(sr); sr.Close(); } catch { DicConsole.ErrorWriteLine("Incorrect resume file, not continuing..."); return; } } if (resume != null && resume.NextBlock > resume.LastBlock && resume.BadBlocks.Count == 0) { DicConsole.WriteLine("Media already dumped correctly, not continuing..."); return; } CICMMetadataType sidecar = null; XmlSerializer sidecarXs = new XmlSerializer(typeof(CICMMetadataType)); if (options.CicmXml != null) { if (File.Exists(options.CicmXml)) { try { StreamReader sr = new StreamReader(options.CicmXml); sidecar = (CICMMetadataType)sidecarXs.Deserialize(sr); sr.Close(); } catch { DicConsole.ErrorWriteLine("Incorrect metadata sidecar file, not continuing..."); return; } } else { DicConsole.ErrorWriteLine("Could not find metadata sidecar, not continuing..."); return; } } PluginBase plugins = new PluginBase(); List <IWritableImage> candidates = new List <IWritableImage>(); // Try extension if (string.IsNullOrEmpty(options.OutputFormat)) { candidates.AddRange(plugins.WritableImages.Values.Where(t => t.KnownExtensions .Contains(Path.GetExtension(options .OutputFile)))); } // Try Id else if (Guid.TryParse(options.OutputFormat, out Guid outId)) { candidates.AddRange(plugins.WritableImages.Values.Where(t => t.Id.Equals(outId))); } // Try name else { candidates.AddRange(plugins.WritableImages.Values.Where(t => string.Equals(t.Name, options.OutputFormat, StringComparison .InvariantCultureIgnoreCase))); } if (candidates.Count == 0) { DicConsole.WriteLine("No plugin supports requested extension."); return; } if (candidates.Count > 1) { DicConsole.WriteLine("More than one plugin supports requested extension."); return; } IWritableImage outputFormat = candidates[0]; DumpLog dumpLog = new DumpLog(outputPrefix + ".log", dev); if (options.Verbose) { dumpLog.WriteLine("Output image format: {0} ({1}).", outputFormat.Name, outputFormat.Id); DicConsole.VerboseWriteLine("Output image format: {0} ({1}).", outputFormat.Name, outputFormat.Id); } else { dumpLog.WriteLine("Output image format: {0}.", outputFormat.Name); DicConsole.WriteLine("Output image format: {0}.", outputFormat.Name); } switch (dev.Type) { case DeviceType.ATA: Ata.Dump(dev, options.DevicePath, outputFormat, options.RetryPasses, options.Force, options.Raw, options.Persistent, options.StopOnError, ref resume, ref dumpLog, encoding, outputPrefix, options.OutputFile, parsedOptions, sidecar, (uint)options.Skip, options.NoMetadata, options.NoTrim); break; case DeviceType.MMC: case DeviceType.SecureDigital: SecureDigital.Dump(dev, options.DevicePath, outputFormat, options.RetryPasses, options.Force, options.Raw, options.Persistent, options.StopOnError, ref resume, ref dumpLog, encoding, outputPrefix, options.OutputFile, parsedOptions, sidecar, (uint)options.Skip, options.NoMetadata, options.NoTrim); break; case DeviceType.NVMe: NvMe.Dump(dev, options.DevicePath, outputFormat, options.RetryPasses, options.Force, options.Raw, options.Persistent, options.StopOnError, ref resume, ref dumpLog, encoding, outputPrefix, options.OutputFile, parsedOptions, sidecar, (uint)options.Skip, options.NoMetadata, options.NoTrim); break; case DeviceType.ATAPI: case DeviceType.SCSI: Scsi.Dump(dev, options.DevicePath, outputFormat, options.RetryPasses, options.Force, options.Raw, options.Persistent, options.StopOnError, ref resume, ref dumpLog, options.LeadIn, encoding, outputPrefix, options.OutputFile, parsedOptions, sidecar, (uint)options.Skip, options.NoMetadata, options.NoTrim); break; default: dumpLog.WriteLine("Unknown device type."); dumpLog.Close(); throw new NotSupportedException("Unknown device type."); } if (resume != null && options.Resume) { resume.LastWriteDate = DateTime.UtcNow; resume.BadBlocks.Sort(); if (File.Exists(outputPrefix + ".resume.xml")) { File.Delete(outputPrefix + ".resume.xml"); } FileStream fs = new FileStream(outputPrefix + ".resume.xml", FileMode.Create, FileAccess.ReadWrite); xs = new XmlSerializer(resume.GetType()); xs.Serialize(fs, resume); fs.Close(); } dumpLog.Close(); Core.Statistics.AddCommand("dump-media"); }