diff --git a/DiscImageChef.Checksums/CDChecksums.cs b/DiscImageChef.Checksums/CDChecksums.cs index 1b1b5f02e..0a5c118c9 100644 --- a/DiscImageChef.Checksums/CDChecksums.cs +++ b/DiscImageChef.Checksums/CDChecksums.cs @@ -61,8 +61,13 @@ namespace DiscImageChef.Checksums if(channelStatus == null && subchannelStatus == null) status = null; if(channelStatus == false || subchannelStatus == false) status = false; - if(channelStatus == null && subchannelStatus == true) status = true; - if(channelStatus == true && subchannelStatus == null) status = true; + switch(channelStatus) { + case null when subchannelStatus == true: status = true; + break; + case true when subchannelStatus == null: status = true; + break; + } + if(channelStatus == true && subchannelStatus == true) status = true; return status; diff --git a/DiscImageChef.Core/Devices/Dumping/ATA.cs b/DiscImageChef.Core/Devices/Dumping/ATA.cs index cd1438854..a5e6c0ffb 100644 --- a/DiscImageChef.Core/Devices/Dumping/ATA.cs +++ b/DiscImageChef.Core/Devices/Dumping/ATA.cs @@ -118,31 +118,31 @@ namespace DiscImageChef.Core.Devices.Dumping Decoders.PCMCIA.Tuple[] tuples = CIS.GetTuples(dev.Cis); if(tuples != null) foreach(Decoders.PCMCIA.Tuple tuple in tuples) - if(tuple.Code == TupleCodes.CISTPL_MANFID) - { - ManufacturerIdentificationTuple manfid = - CIS.DecodeManufacturerIdentificationTuple(tuple); + switch(tuple.Code) { + case TupleCodes.CISTPL_MANFID: + ManufacturerIdentificationTuple manfid = + CIS.DecodeManufacturerIdentificationTuple(tuple); - if(manfid != null) - { - sidecar.BlockMedia[0].PCMCIA.ManufacturerCode = manfid.ManufacturerID; - sidecar.BlockMedia[0].PCMCIA.CardCode = manfid.CardID; - sidecar.BlockMedia[0].PCMCIA.ManufacturerCodeSpecified = true; - sidecar.BlockMedia[0].PCMCIA.CardCodeSpecified = true; - } - } - else if(tuple.Code == TupleCodes.CISTPL_VERS_1) - { - Level1VersionTuple vers = CIS.DecodeLevel1VersionTuple(tuple); + if(manfid != null) + { + sidecar.BlockMedia[0].PCMCIA.ManufacturerCode = manfid.ManufacturerID; + sidecar.BlockMedia[0].PCMCIA.CardCode = manfid.CardID; + sidecar.BlockMedia[0].PCMCIA.ManufacturerCodeSpecified = true; + sidecar.BlockMedia[0].PCMCIA.CardCodeSpecified = true; + } + break; + case TupleCodes.CISTPL_VERS_1: + Level1VersionTuple vers = CIS.DecodeLevel1VersionTuple(tuple); - if(vers != null) - { - sidecar.BlockMedia[0].PCMCIA.Manufacturer = vers.Manufacturer; - sidecar.BlockMedia[0].PCMCIA.ProductName = vers.Product; - sidecar.BlockMedia[0].PCMCIA.Compliance = - string.Format("{0}.{1}", vers.MajorVersion, vers.MinorVersion); - sidecar.BlockMedia[0].PCMCIA.AdditionalInformation = vers.AdditionalInformation; - } + if(vers != null) + { + sidecar.BlockMedia[0].PCMCIA.Manufacturer = vers.Manufacturer; + sidecar.BlockMedia[0].PCMCIA.ProductName = vers.Product; + sidecar.BlockMedia[0].PCMCIA.Compliance = + string.Format("{0}.{1}", vers.MajorVersion, vers.MinorVersion); + sidecar.BlockMedia[0].PCMCIA.AdditionalInformation = vers.AdditionalInformation; + } + break; } } diff --git a/DiscImageChef.Core/Devices/Dumping/MMC.cs b/DiscImageChef.Core/Devices/Dumping/MMC.cs index babd78d6e..27fedfdcb 100644 --- a/DiscImageChef.Core/Devices/Dumping/MMC.cs +++ b/DiscImageChef.Core/Devices/Dumping/MMC.cs @@ -179,166 +179,179 @@ namespace DiscImageChef.Core.Devices.Dumping dumpLog.WriteLine("Device reports disc has {0} blocks", blocks); #region Nintendo - if(dskType == MediaType.Unknown && blocks > 0) - { - dumpLog.WriteLine("Reading Physical Format Information"); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.PhysicalInformation, 0, dev.Timeout, out duration); - if(!sense) - { - Decoders.DVD.PFI.PhysicalFormatInformation? nintendoPfi = Decoders.DVD.PFI.Decode(cmdBuf); - if(nintendoPfi != null) - if(nintendoPfi.Value.DiskCategory == Decoders.DVD.DiskCategory.Nintendo && - nintendoPfi.Value.PartVersion == 15) + switch(dskType) { + case MediaType.Unknown when blocks > 0: + dumpLog.WriteLine("Reading Physical Format Information"); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.PhysicalInformation, 0, dev.Timeout, out duration); + if(!sense) + { + Decoders.DVD.PFI.PhysicalFormatInformation? nintendoPfi = Decoders.DVD.PFI.Decode(cmdBuf); + if(nintendoPfi != null) + if(nintendoPfi.Value.DiskCategory == Decoders.DVD.DiskCategory.Nintendo && + nintendoPfi.Value.PartVersion == 15) + { + dumpLog.WriteLine("Dumping Nintendo GameCube or Wii discs is not yet implemented."); + throw new + NotImplementedException("Dumping Nintendo GameCube or Wii discs is not yet implemented."); + } + } + + break; + case MediaType.DVDDownload: + case MediaType.DVDPR: + case MediaType.DVDPRDL: + case MediaType.DVDPRW: + case MediaType.DVDPRWDL: + case MediaType.DVDR: + case MediaType.DVDRAM: + case MediaType.DVDRDL: + case MediaType.DVDROM: + case MediaType.DVDRW: + case MediaType.DVDRWDL: + case MediaType.HDDVDR: + case MediaType.HDDVDRAM: + case MediaType.HDDVDRDL: + case MediaType.HDDVDROM: + case MediaType.HDDVDRW: + case MediaType.HDDVDRWDL: + dumpLog.WriteLine("Reading Physical Format Information"); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.PhysicalInformation, 0, dev.Timeout, out duration); + if(!sense) + { + alcohol.AddPfi(cmdBuf); + if(Decoders.DVD.PFI.Decode(cmdBuf).HasValue) { - dumpLog.WriteLine("Dumping Nintendo GameCube or Wii discs is not yet implemented."); - throw new - NotImplementedException("Dumping Nintendo GameCube or Wii discs is not yet implemented."); + tmpBuf = new byte[cmdBuf.Length - 4]; + Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); + sidecar.OpticalDisc[0].PFI = new DumpType + { + Image = outputPrefix + ".pfi.bin", + Size = tmpBuf.Length, + Checksums = Checksum.GetChecksums(tmpBuf).ToArray() + }; + DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].PFI.Image, tmpBuf); + + Decoders.DVD.PFI.PhysicalFormatInformation decPfi = Decoders.DVD.PFI.Decode(cmdBuf).Value; + DicConsole.WriteLine("PFI:\n{0}", Decoders.DVD.PFI.Prettify(decPfi)); + + // False book types + if(dskType == MediaType.DVDROM) + switch(decPfi.DiskCategory) + { + case Decoders.DVD.DiskCategory.DVDPR: + dskType = MediaType.DVDPR; + break; + case Decoders.DVD.DiskCategory.DVDPRDL: + dskType = MediaType.DVDPRDL; + break; + case Decoders.DVD.DiskCategory.DVDPRW: + dskType = MediaType.DVDPRW; + break; + case Decoders.DVD.DiskCategory.DVDPRWDL: + dskType = MediaType.DVDPRWDL; + break; + case Decoders.DVD.DiskCategory.DVDR: + if(decPfi.PartVersion == 6) dskType = MediaType.DVDRDL; + else dskType = MediaType.DVDR; + break; + case Decoders.DVD.DiskCategory.DVDRAM: + dskType = MediaType.DVDRAM; + break; + default: + dskType = MediaType.DVDROM; + break; + case Decoders.DVD.DiskCategory.DVDRW: + if(decPfi.PartVersion == 3) dskType = MediaType.DVDRWDL; + else dskType = MediaType.DVDRW; + break; + case Decoders.DVD.DiskCategory.HDDVDR: + dskType = MediaType.HDDVDR; + break; + case Decoders.DVD.DiskCategory.HDDVDRAM: + dskType = MediaType.HDDVDRAM; + break; + case Decoders.DVD.DiskCategory.HDDVDROM: + dskType = MediaType.HDDVDROM; + break; + case Decoders.DVD.DiskCategory.HDDVDRW: + dskType = MediaType.HDDVDRW; + break; + case Decoders.DVD.DiskCategory.Nintendo: + if(decPfi.DiscSize == Decoders.DVD.DVDSize.Eighty) dskType = MediaType.GOD; + else dskType = MediaType.WOD; + break; + case Decoders.DVD.DiskCategory.UMD: + dskType = MediaType.UMD; + break; + } } - } + } + + dumpLog.WriteLine("Reading Disc Manufacturing Information"); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.DiscManufacturingInformation, 0, dev.Timeout, + out duration); + if(!sense) + { + if(Decoders.Xbox.DMI.IsXbox(cmdBuf) || Decoders.Xbox.DMI.IsXbox360(cmdBuf)) + { + if(Decoders.Xbox.DMI.IsXbox(cmdBuf)) dskType = MediaType.XGD; + else if(Decoders.Xbox.DMI.IsXbox360(cmdBuf)) + { + dskType = MediaType.XGD2; + + // All XGD3 all have the same number of blocks + if(blocks == 25063 || // Locked (or non compatible drive) + blocks == 4229664 || // Xtreme unlock + blocks == 4246304) // Wxripper unlock + dskType = MediaType.XGD3; + } + + sense = dev.ScsiInquiry(out byte[] inqBuf, out senseBuf); + + if(sense || !Decoders.SCSI.Inquiry.Decode(inqBuf).HasValue || + Decoders.SCSI.Inquiry.Decode(inqBuf).HasValue && + !Decoders.SCSI.Inquiry.Decode(inqBuf).Value.KreonPresent) + { + dumpLog.WriteLine("Dumping Xbox Game Discs requires a drive with Kreon firmware."); + throw new + NotImplementedException("Dumping Xbox Game Discs requires a drive with Kreon firmware."); + } + + if(dumpRaw && !force) + { + DicConsole + .ErrorWriteLine("Not continuing. If you want to continue reading cooked data when raw is not available use the force option."); + // TODO: Exit more gracefully + return; + } + + isXbox = true; + } + + alcohol.AddDmi(cmdBuf); + + if(cmdBuf.Length == 2052) + { + tmpBuf = new byte[cmdBuf.Length - 4]; + Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); + sidecar.OpticalDisc[0].DMI = new DumpType + { + Image = outputPrefix + ".dmi.bin", + Size = tmpBuf.Length, + Checksums = Checksum.GetChecksums(tmpBuf).ToArray() + }; + DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].DMI.Image, tmpBuf); + } + } + + break; } #endregion Nintendo #region All DVD and HD DVD types - if(dskType == MediaType.DVDDownload || dskType == MediaType.DVDPR || dskType == MediaType.DVDPRDL || - dskType == MediaType.DVDPRW || dskType == MediaType.DVDPRWDL || dskType == MediaType.DVDR || - dskType == MediaType.DVDRAM || dskType == MediaType.DVDRDL || dskType == MediaType.DVDROM || - dskType == MediaType.DVDRW || dskType == MediaType.DVDRWDL || dskType == MediaType.HDDVDR || - dskType == MediaType.HDDVDRAM || dskType == MediaType.HDDVDRDL || dskType == MediaType.HDDVDROM || - dskType == MediaType.HDDVDRW || dskType == MediaType.HDDVDRWDL) - { - dumpLog.WriteLine("Reading Physical Format Information"); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.PhysicalInformation, 0, dev.Timeout, out duration); - if(!sense) - { - alcohol.AddPfi(cmdBuf); - if(Decoders.DVD.PFI.Decode(cmdBuf).HasValue) - { - tmpBuf = new byte[cmdBuf.Length - 4]; - Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); - sidecar.OpticalDisc[0].PFI = new DumpType - { - Image = outputPrefix + ".pfi.bin", - Size = tmpBuf.Length, - Checksums = Checksum.GetChecksums(tmpBuf).ToArray() - }; - DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].PFI.Image, tmpBuf); - - Decoders.DVD.PFI.PhysicalFormatInformation decPfi = Decoders.DVD.PFI.Decode(cmdBuf).Value; - DicConsole.WriteLine("PFI:\n{0}", Decoders.DVD.PFI.Prettify(decPfi)); - - // False book types - if(dskType == MediaType.DVDROM) - switch(decPfi.DiskCategory) - { - case Decoders.DVD.DiskCategory.DVDPR: - dskType = MediaType.DVDPR; - break; - case Decoders.DVD.DiskCategory.DVDPRDL: - dskType = MediaType.DVDPRDL; - break; - case Decoders.DVD.DiskCategory.DVDPRW: - dskType = MediaType.DVDPRW; - break; - case Decoders.DVD.DiskCategory.DVDPRWDL: - dskType = MediaType.DVDPRWDL; - break; - case Decoders.DVD.DiskCategory.DVDR: - if(decPfi.PartVersion == 6) dskType = MediaType.DVDRDL; - else dskType = MediaType.DVDR; - break; - case Decoders.DVD.DiskCategory.DVDRAM: - dskType = MediaType.DVDRAM; - break; - default: - dskType = MediaType.DVDROM; - break; - case Decoders.DVD.DiskCategory.DVDRW: - if(decPfi.PartVersion == 3) dskType = MediaType.DVDRWDL; - else dskType = MediaType.DVDRW; - break; - case Decoders.DVD.DiskCategory.HDDVDR: - dskType = MediaType.HDDVDR; - break; - case Decoders.DVD.DiskCategory.HDDVDRAM: - dskType = MediaType.HDDVDRAM; - break; - case Decoders.DVD.DiskCategory.HDDVDROM: - dskType = MediaType.HDDVDROM; - break; - case Decoders.DVD.DiskCategory.HDDVDRW: - dskType = MediaType.HDDVDRW; - break; - case Decoders.DVD.DiskCategory.Nintendo: - if(decPfi.DiscSize == Decoders.DVD.DVDSize.Eighty) dskType = MediaType.GOD; - else dskType = MediaType.WOD; - break; - case Decoders.DVD.DiskCategory.UMD: - dskType = MediaType.UMD; - break; - } - } - } - - dumpLog.WriteLine("Reading Disc Manufacturing Information"); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.DiscManufacturingInformation, 0, dev.Timeout, - out duration); - if(!sense) - { - if(Decoders.Xbox.DMI.IsXbox(cmdBuf) || Decoders.Xbox.DMI.IsXbox360(cmdBuf)) - { - if(Decoders.Xbox.DMI.IsXbox(cmdBuf)) dskType = MediaType.XGD; - else if(Decoders.Xbox.DMI.IsXbox360(cmdBuf)) - { - dskType = MediaType.XGD2; - - // All XGD3 all have the same number of blocks - if(blocks == 25063 || // Locked (or non compatible drive) - blocks == 4229664 || // Xtreme unlock - blocks == 4246304) // Wxripper unlock - dskType = MediaType.XGD3; - } - - sense = dev.ScsiInquiry(out byte[] inqBuf, out senseBuf); - - if(sense || !Decoders.SCSI.Inquiry.Decode(inqBuf).HasValue || - Decoders.SCSI.Inquiry.Decode(inqBuf).HasValue && - !Decoders.SCSI.Inquiry.Decode(inqBuf).Value.KreonPresent) - { - dumpLog.WriteLine("Dumping Xbox Game Discs requires a drive with Kreon firmware."); - throw new - NotImplementedException("Dumping Xbox Game Discs requires a drive with Kreon firmware."); - } - - if(dumpRaw && !force) - { - DicConsole - .ErrorWriteLine("Not continuing. If you want to continue reading cooked data when raw is not available use the force option."); - // TODO: Exit more gracefully - return; - } - - isXbox = true; - } - - alcohol.AddDmi(cmdBuf); - - if(cmdBuf.Length == 2052) - { - tmpBuf = new byte[cmdBuf.Length - 4]; - Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); - sidecar.OpticalDisc[0].DMI = new DumpType - { - Image = outputPrefix + ".dmi.bin", - Size = tmpBuf.Length, - Checksums = Checksum.GetChecksums(tmpBuf).ToArray() - }; - DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].DMI.Image, tmpBuf); - } - } - } #endregion All DVD and HD DVD types #region DVD-ROM @@ -369,36 +382,260 @@ namespace DiscImageChef.Core.Devices.Dumping } #endregion DVD-ROM - #region DVD-ROM and HD DVD-ROM - if(dskType == MediaType.DVDDownload || dskType == MediaType.DVDROM || dskType == MediaType.HDDVDROM) - { - dumpLog.WriteLine("Reading Burst Cutting Area."); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.BurstCuttingArea, 0, dev.Timeout, out duration); - if(!sense) - { - tmpBuf = new byte[cmdBuf.Length - 4]; - Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); - alcohol.AddBca(tmpBuf); - sidecar.OpticalDisc[0].BCA = new DumpType + switch(dskType) { + #region DVD-ROM and HD DVD-ROM + case MediaType.DVDDownload: + case MediaType.DVDROM: + case MediaType.HDDVDROM: + dumpLog.WriteLine("Reading Burst Cutting Area."); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.BurstCuttingArea, 0, dev.Timeout, out duration); + if(!sense) { - Image = outputPrefix + ".bca.bin", - Size = tmpBuf.Length, - Checksums = Checksum.GetChecksums(tmpBuf).ToArray() - }; - DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].BCA.Image, tmpBuf); - } - } - #endregion DVD-ROM and HD DVD-ROM + tmpBuf = new byte[cmdBuf.Length - 4]; + Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); + alcohol.AddBca(tmpBuf); + sidecar.OpticalDisc[0].BCA = new DumpType + { + Image = outputPrefix + ".bca.bin", + Size = tmpBuf.Length, + Checksums = Checksum.GetChecksums(tmpBuf).ToArray() + }; + DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].BCA.Image, tmpBuf); + } + break; + #endregion DVD-ROM and HD DVD-ROM + #region DVD-RAM and HD DVD-RAM + case MediaType.DVDRAM: + case MediaType.HDDVDRAM: + dumpLog.WriteLine("Reading Disc Description Structure."); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.DvdramDds, 0, dev.Timeout, out duration); + if(!sense) + if(Decoders.DVD.DDS.Decode(cmdBuf).HasValue) + { + tmpBuf = new byte[cmdBuf.Length - 4]; + Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); + sidecar.OpticalDisc[0].DDS = new DumpType + { + Image = outputPrefix + ".dds.bin", + Size = tmpBuf.Length, + Checksums = Checksum.GetChecksums(tmpBuf).ToArray() + }; + DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].DDS.Image, tmpBuf); + } - #region DVD-RAM and HD DVD-RAM - if(dskType == MediaType.DVDRAM || dskType == MediaType.HDDVDRAM) - { - dumpLog.WriteLine("Reading Disc Description Structure."); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.DvdramDds, 0, dev.Timeout, out duration); - if(!sense) - if(Decoders.DVD.DDS.Decode(cmdBuf).HasValue) + dumpLog.WriteLine("Reading Spare Area Information."); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.DvdramSpareAreaInformation, 0, dev.Timeout, + out duration); + if(!sense) + if(Decoders.DVD.Spare.Decode(cmdBuf).HasValue) + { + tmpBuf = new byte[cmdBuf.Length - 4]; + Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); + sidecar.OpticalDisc[0].SAI = new DumpType + { + Image = outputPrefix + ".sai.bin", + Size = tmpBuf.Length, + Checksums = Checksum.GetChecksums(tmpBuf).ToArray() + }; + DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].SAI.Image, tmpBuf); + } + break; + #endregion DVD-RAM and HD DVD-RAM + #region DVD-R and DVD-RW + case MediaType.DVDR: + case MediaType.DVDRW: + dumpLog.WriteLine("Reading Pre-Recorded Information."); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.PreRecordedInfo, 0, dev.Timeout, out duration); + if(!sense) + { + tmpBuf = new byte[cmdBuf.Length - 4]; + Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); + sidecar.OpticalDisc[0].PRI = new DumpType + { + Image = outputPrefix + ".pri.bin", + Size = tmpBuf.Length, + Checksums = Checksum.GetChecksums(tmpBuf).ToArray() + }; + DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].SAI.Image, tmpBuf); + } + break; + #endregion DVD-R and DVD-RW + } + + switch(dskType) { + #region DVD-R, DVD-RW and HD DVD-R + case MediaType.DVDR: + case MediaType.DVDRW: + case MediaType.HDDVDR: + dumpLog.WriteLine("Reading Media Identifier."); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.DvdrMediaIdentifier, 0, dev.Timeout, + out duration); + if(!sense) + { + tmpBuf = new byte[cmdBuf.Length - 4]; + Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); + sidecar.OpticalDisc[0].MediaID = new DumpType + { + Image = outputPrefix + ".mid.bin", + Size = tmpBuf.Length, + Checksums = Checksum.GetChecksums(tmpBuf).ToArray() + }; + DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].MediaID.Image, tmpBuf); + } + + dumpLog.WriteLine("Reading Recordable Physical Information."); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.DvdrPhysicalInformation, 0, dev.Timeout, + out duration); + if(!sense) + { + tmpBuf = new byte[cmdBuf.Length - 4]; + Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); + sidecar.OpticalDisc[0].PFIR = new DumpType + { + Image = outputPrefix + ".pfir.bin", + Size = tmpBuf.Length, + Checksums = Checksum.GetChecksums(tmpBuf).ToArray() + }; + DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].PFIR.Image, tmpBuf); + } + break; + #endregion DVD-R, DVD-RW and HD DVD-R + #region All DVD+ + case MediaType.DVDPR: + case MediaType.DVDPRDL: + case MediaType.DVDPRW: + case MediaType.DVDPRWDL: + dumpLog.WriteLine("Reading ADdress In Pregroove."); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.Adip, 0, dev.Timeout, out duration); + if(!sense) + { + tmpBuf = new byte[cmdBuf.Length - 4]; + Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); + sidecar.OpticalDisc[0].ADIP = new DumpType + { + Image = outputPrefix + ".adip.bin", + Size = tmpBuf.Length, + Checksums = Checksum.GetChecksums(tmpBuf).ToArray() + }; + DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].ADIP.Image, tmpBuf); + } + + dumpLog.WriteLine("Reading Disc Control Blocks."); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.Dcb, 0, dev.Timeout, out duration); + if(!sense) + { + tmpBuf = new byte[cmdBuf.Length - 4]; + Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); + sidecar.OpticalDisc[0].DCB = new DumpType + { + Image = outputPrefix + ".dcb.bin", + Size = tmpBuf.Length, + Checksums = Checksum.GetChecksums(tmpBuf).ToArray() + }; + DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].DCB.Image, tmpBuf); + } + break; + #endregion All DVD+ + #region HD DVD-ROM + case MediaType.HDDVDROM: + dumpLog.WriteLine("Reading Lead-in Copyright Information."); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.HddvdCopyrightInformation, 0, dev.Timeout, + out duration); + if(!sense) + { + tmpBuf = new byte[cmdBuf.Length - 4]; + Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); + sidecar.OpticalDisc[0].CMI = new DumpType + { + Image = outputPrefix + ".cmi.bin", + Size = tmpBuf.Length, + Checksums = Checksum.GetChecksums(tmpBuf).ToArray() + }; + DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].CMI.Image, tmpBuf); + } + break; + #endregion HD DVD-ROM + #region All Blu-ray + case MediaType.BDR: + case MediaType.BDRE: + case MediaType.BDROM: + case MediaType.BDRXL: + case MediaType.BDREXL: + dumpLog.WriteLine("Reading Disc Information."); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, + MmcDiscStructureFormat.DiscInformation, 0, dev.Timeout, out duration); + if(!sense) + if(Decoders.Bluray.DI.Decode(cmdBuf).HasValue) + { + tmpBuf = new byte[cmdBuf.Length - 4]; + Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); + sidecar.OpticalDisc[0].DI = new DumpType + { + Image = outputPrefix + ".di.bin", + Size = tmpBuf.Length, + Checksums = Checksum.GetChecksums(tmpBuf).ToArray() + }; + DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].DI.Image, tmpBuf); + } + + dumpLog.WriteLine("Reading PAC."); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, + MmcDiscStructureFormat.Pac, 0, dev.Timeout, out duration); + if(!sense) + { + tmpBuf = new byte[cmdBuf.Length - 4]; + Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); + sidecar.OpticalDisc[0].PAC = new DumpType + { + Image = outputPrefix + ".pac.bin", + Size = tmpBuf.Length, + Checksums = Checksum.GetChecksums(tmpBuf).ToArray() + }; + DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].PAC.Image, tmpBuf); + } + break; + #endregion All Blu-ray + } + + switch(dskType) { + #region BD-ROM only + case MediaType.BDROM: + dumpLog.WriteLine("Reading Burst Cutting Area."); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, + MmcDiscStructureFormat.BdBurstCuttingArea, 0, dev.Timeout, out duration); + if(!sense) + { + tmpBuf = new byte[cmdBuf.Length - 4]; + Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); + alcohol.AddBca(tmpBuf); + sidecar.OpticalDisc[0].BCA = new DumpType + { + Image = outputPrefix + ".bca.bin", + Size = tmpBuf.Length, + Checksums = Checksum.GetChecksums(tmpBuf).ToArray() + }; + DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].BCA.Image, tmpBuf); + } + break; + #endregion BD-ROM only + #region Writable Blu-ray only + case MediaType.BDR: + case MediaType.BDRE: + case MediaType.BDRXL: + case MediaType.BDREXL: + dumpLog.WriteLine("Reading Disc Definition Structure."); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, + MmcDiscStructureFormat.BdDds, 0, dev.Timeout, out duration); + if(!sense) { tmpBuf = new byte[cmdBuf.Length - 4]; Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); @@ -411,12 +648,11 @@ namespace DiscImageChef.Core.Devices.Dumping DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].DDS.Image, tmpBuf); } - dumpLog.WriteLine("Reading Spare Area Information."); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.DvdramSpareAreaInformation, 0, dev.Timeout, - out duration); - if(!sense) - if(Decoders.DVD.Spare.Decode(cmdBuf).HasValue) + dumpLog.WriteLine("Reading Spare Area Information."); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, + MmcDiscStructureFormat.BdSpareAreaInformation, 0, dev.Timeout, + out duration); + if(!sense) { tmpBuf = new byte[cmdBuf.Length - 4]; Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); @@ -428,228 +664,9 @@ namespace DiscImageChef.Core.Devices.Dumping }; DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].SAI.Image, tmpBuf); } + break; + #endregion Writable Blu-ray only } - #endregion DVD-RAM and HD DVD-RAM - - #region DVD-R and DVD-RW - if(dskType == MediaType.DVDR || dskType == MediaType.DVDRW) - { - dumpLog.WriteLine("Reading Pre-Recorded Information."); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.PreRecordedInfo, 0, dev.Timeout, out duration); - if(!sense) - { - tmpBuf = new byte[cmdBuf.Length - 4]; - Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); - sidecar.OpticalDisc[0].PRI = new DumpType - { - Image = outputPrefix + ".pri.bin", - Size = tmpBuf.Length, - Checksums = Checksum.GetChecksums(tmpBuf).ToArray() - }; - DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].SAI.Image, tmpBuf); - } - } - #endregion DVD-R and DVD-RW - - #region DVD-R, DVD-RW and HD DVD-R - if(dskType == MediaType.DVDR || dskType == MediaType.DVDRW || dskType == MediaType.HDDVDR) - { - dumpLog.WriteLine("Reading Media Identifier."); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.DvdrMediaIdentifier, 0, dev.Timeout, - out duration); - if(!sense) - { - tmpBuf = new byte[cmdBuf.Length - 4]; - Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); - sidecar.OpticalDisc[0].MediaID = new DumpType - { - Image = outputPrefix + ".mid.bin", - Size = tmpBuf.Length, - Checksums = Checksum.GetChecksums(tmpBuf).ToArray() - }; - DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].MediaID.Image, tmpBuf); - } - - dumpLog.WriteLine("Reading Recordable Physical Information."); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.DvdrPhysicalInformation, 0, dev.Timeout, - out duration); - if(!sense) - { - tmpBuf = new byte[cmdBuf.Length - 4]; - Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); - sidecar.OpticalDisc[0].PFIR = new DumpType - { - Image = outputPrefix + ".pfir.bin", - Size = tmpBuf.Length, - Checksums = Checksum.GetChecksums(tmpBuf).ToArray() - }; - DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].PFIR.Image, tmpBuf); - } - } - #endregion DVD-R, DVD-RW and HD DVD-R - - #region All DVD+ - if(dskType == MediaType.DVDPR || dskType == MediaType.DVDPRDL || dskType == MediaType.DVDPRW || - dskType == MediaType.DVDPRWDL) - { - dumpLog.WriteLine("Reading ADdress In Pregroove."); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.Adip, 0, dev.Timeout, out duration); - if(!sense) - { - tmpBuf = new byte[cmdBuf.Length - 4]; - Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); - sidecar.OpticalDisc[0].ADIP = new DumpType - { - Image = outputPrefix + ".adip.bin", - Size = tmpBuf.Length, - Checksums = Checksum.GetChecksums(tmpBuf).ToArray() - }; - DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].ADIP.Image, tmpBuf); - } - - dumpLog.WriteLine("Reading Disc Control Blocks."); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.Dcb, 0, dev.Timeout, out duration); - if(!sense) - { - tmpBuf = new byte[cmdBuf.Length - 4]; - Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); - sidecar.OpticalDisc[0].DCB = new DumpType - { - Image = outputPrefix + ".dcb.bin", - Size = tmpBuf.Length, - Checksums = Checksum.GetChecksums(tmpBuf).ToArray() - }; - DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].DCB.Image, tmpBuf); - } - } - #endregion All DVD+ - - #region HD DVD-ROM - if(dskType == MediaType.HDDVDROM) - { - dumpLog.WriteLine("Reading Lead-in Copyright Information."); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.HddvdCopyrightInformation, 0, dev.Timeout, - out duration); - if(!sense) - { - tmpBuf = new byte[cmdBuf.Length - 4]; - Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); - sidecar.OpticalDisc[0].CMI = new DumpType - { - Image = outputPrefix + ".cmi.bin", - Size = tmpBuf.Length, - Checksums = Checksum.GetChecksums(tmpBuf).ToArray() - }; - DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].CMI.Image, tmpBuf); - } - } - #endregion HD DVD-ROM - - #region All Blu-ray - if(dskType == MediaType.BDR || dskType == MediaType.BDRE || dskType == MediaType.BDROM || - dskType == MediaType.BDRXL || dskType == MediaType.BDREXL) - { - dumpLog.WriteLine("Reading Disc Information."); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, - MmcDiscStructureFormat.DiscInformation, 0, dev.Timeout, out duration); - if(!sense) - if(Decoders.Bluray.DI.Decode(cmdBuf).HasValue) - { - tmpBuf = new byte[cmdBuf.Length - 4]; - Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); - sidecar.OpticalDisc[0].DI = new DumpType - { - Image = outputPrefix + ".di.bin", - Size = tmpBuf.Length, - Checksums = Checksum.GetChecksums(tmpBuf).ToArray() - }; - DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].DI.Image, tmpBuf); - } - - dumpLog.WriteLine("Reading PAC."); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, - MmcDiscStructureFormat.Pac, 0, dev.Timeout, out duration); - if(!sense) - { - tmpBuf = new byte[cmdBuf.Length - 4]; - Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); - sidecar.OpticalDisc[0].PAC = new DumpType - { - Image = outputPrefix + ".pac.bin", - Size = tmpBuf.Length, - Checksums = Checksum.GetChecksums(tmpBuf).ToArray() - }; - DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].PAC.Image, tmpBuf); - } - } - #endregion All Blu-ray - - #region BD-ROM only - if(dskType == MediaType.BDROM) - { - dumpLog.WriteLine("Reading Burst Cutting Area."); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, - MmcDiscStructureFormat.BdBurstCuttingArea, 0, dev.Timeout, out duration); - if(!sense) - { - tmpBuf = new byte[cmdBuf.Length - 4]; - Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); - alcohol.AddBca(tmpBuf); - sidecar.OpticalDisc[0].BCA = new DumpType - { - Image = outputPrefix + ".bca.bin", - Size = tmpBuf.Length, - Checksums = Checksum.GetChecksums(tmpBuf).ToArray() - }; - DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].BCA.Image, tmpBuf); - } - } - #endregion BD-ROM only - - #region Writable Blu-ray only - if(dskType == MediaType.BDR || dskType == MediaType.BDRE || dskType == MediaType.BDRXL || - dskType == MediaType.BDREXL) - { - dumpLog.WriteLine("Reading Disc Definition Structure."); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, - MmcDiscStructureFormat.BdDds, 0, dev.Timeout, out duration); - if(!sense) - { - tmpBuf = new byte[cmdBuf.Length - 4]; - Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); - sidecar.OpticalDisc[0].DDS = new DumpType - { - Image = outputPrefix + ".dds.bin", - Size = tmpBuf.Length, - Checksums = Checksum.GetChecksums(tmpBuf).ToArray() - }; - DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].DDS.Image, tmpBuf); - } - - dumpLog.WriteLine("Reading Spare Area Information."); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, - MmcDiscStructureFormat.BdSpareAreaInformation, 0, dev.Timeout, - out duration); - if(!sense) - { - tmpBuf = new byte[cmdBuf.Length - 4]; - Array.Copy(cmdBuf, 4, tmpBuf, 0, cmdBuf.Length - 4); - sidecar.OpticalDisc[0].SAI = new DumpType - { - Image = outputPrefix + ".sai.bin", - Size = tmpBuf.Length, - Checksums = Checksum.GetChecksums(tmpBuf).ToArray() - }; - DataFile.WriteTo("SCSI Dump", sidecar.OpticalDisc[0].SAI.Image, tmpBuf); - } - } - #endregion Writable Blu-ray only if(isXbox) { diff --git a/DiscImageChef.Core/Devices/Dumping/SBC.cs b/DiscImageChef.Core/Devices/Dumping/SBC.cs index 506d571b7..7fef95faf 100644 --- a/DiscImageChef.Core/Devices/Dumping/SBC.cs +++ b/DiscImageChef.Core/Devices/Dumping/SBC.cs @@ -658,12 +658,16 @@ namespace DiscImageChef.Core.Devices.Dumping Statistics.AddFilesystem(plugin.XmlFSType.Type); dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); - if(plugin.XmlFSType.Type == "Opera") dskType = MediaType.ThreeDO; - if(plugin.XmlFSType.Type == "PC Engine filesystem") - dskType = MediaType.SuperCDROM2; - if(plugin.XmlFSType.Type == "Nintendo Wii filesystem") dskType = MediaType.WOD; - if(plugin.XmlFSType.Type == "Nintendo Gamecube filesystem") - dskType = MediaType.GOD; + switch(plugin.XmlFSType.Type) { + case "Opera": dskType = MediaType.ThreeDO; + break; + case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; + break; + case "Nintendo Wii filesystem": dskType = MediaType.WOD; + break; + case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; + break; + } } } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body @@ -696,10 +700,16 @@ namespace DiscImageChef.Core.Devices.Dumping Statistics.AddFilesystem(plugin.XmlFSType.Type); dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); - if(plugin.XmlFSType.Type == "Opera") dskType = MediaType.ThreeDO; - if(plugin.XmlFSType.Type == "PC Engine filesystem") dskType = MediaType.SuperCDROM2; - if(plugin.XmlFSType.Type == "Nintendo Wii filesystem") dskType = MediaType.WOD; - if(plugin.XmlFSType.Type == "Nintendo Gamecube filesystem") dskType = MediaType.GOD; + switch(plugin.XmlFSType.Type) { + case "Opera": dskType = MediaType.ThreeDO; + break; + case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; + break; + case "Nintendo Wii filesystem": dskType = MediaType.WOD; + break; + case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; + break; + } } } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body diff --git a/DiscImageChef.Core/Devices/Dumping/SCSI.cs b/DiscImageChef.Core/Devices/Dumping/SCSI.cs index 44b26a370..7b19594a3 100644 --- a/DiscImageChef.Core/Devices/Dumping/SCSI.cs +++ b/DiscImageChef.Core/Devices/Dumping/SCSI.cs @@ -173,23 +173,21 @@ namespace DiscImageChef.Core.Devices.Dumping CICMMetadataType sidecar = new CICMMetadataType(); - if(dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess) - { - if(dumpRaw) throw new ArgumentException("Tapes cannot be dumped raw."); + switch(dev.ScsiType) { + case Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess: + if(dumpRaw) throw new ArgumentException("Tapes cannot be dumped raw."); - Ssc.Dump(dev, outputPrefix, devicePath, ref sidecar, ref resume, ref dumpLog); - return; + Ssc.Dump(dev, outputPrefix, devicePath, ref sidecar, ref resume, ref dumpLog); + return; + case Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice: + Mmc.Dump(dev, devicePath, outputPrefix, retryPasses, force, dumpRaw, persistent, stopOnError, + ref sidecar, ref dskType, separateSubchannel, ref resume, ref dumpLog, dumpLeadIn, encoding); + return; + default: + Sbc.Dump(dev, devicePath, outputPrefix, retryPasses, force, dumpRaw, persistent, stopOnError, ref sidecar, + ref dskType, false, ref resume, ref dumpLog, encoding); + break; } - - if(dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice) - { - Mmc.Dump(dev, devicePath, outputPrefix, retryPasses, force, dumpRaw, persistent, stopOnError, - ref sidecar, ref dskType, separateSubchannel, ref resume, ref dumpLog, dumpLeadIn, encoding); - return; - } - - Sbc.Dump(dev, devicePath, outputPrefix, retryPasses, force, dumpRaw, persistent, stopOnError, ref sidecar, - ref dskType, false, ref resume, ref dumpLog, encoding); } } } \ No newline at end of file diff --git a/DiscImageChef.Core/Devices/Dumping/SecureDigital.cs b/DiscImageChef.Core/Devices/Dumping/SecureDigital.cs index 8d566eeae..9d2c1e274 100644 --- a/DiscImageChef.Core/Devices/Dumping/SecureDigital.cs +++ b/DiscImageChef.Core/Devices/Dumping/SecureDigital.cs @@ -89,72 +89,76 @@ namespace DiscImageChef.Core.Devices.Dumping int physicalBlockSize = 0; bool byteAddressed = true; - if(dev.Type == DeviceType.MMC) - { - ExtendedCSD ecsdDecoded = new ExtendedCSD(); - CSD csdDecoded = new CSD(); - - dumpLog.WriteLine("Reading Extended CSD"); - sense = dev.ReadExtendedCsd(out ecsd, out response, timeout, out duration); - if(!sense) + switch(dev.Type) { + case DeviceType.MMC: { - ecsdDecoded = Decoders.MMC.Decoders.DecodeExtendedCSD(ecsd); - blocksToRead = ecsdDecoded.OptimalReadSize; - blocks = ecsdDecoded.SectorCount; - blockSize = (uint)(ecsdDecoded.SectorSize == 1 ? 4096 : 512); - if(ecsdDecoded.NativeSectorSize == 0) physicalBlockSize = 512; - else if(ecsdDecoded.NativeSectorSize == 1) physicalBlockSize = 4096; - // Supposing it's high-capacity MMC if it has Extended CSD... - byteAddressed = false; - } - else ecsd = null; + ExtendedCSD ecsdDecoded = new ExtendedCSD(); + CSD csdDecoded = new CSD(); - dumpLog.WriteLine("Reading CSD"); - sense = dev.ReadCsd(out csd, out response, timeout, out duration); - if(!sense) - { - if(blocks == 0) + dumpLog.WriteLine("Reading Extended CSD"); + sense = dev.ReadExtendedCsd(out ecsd, out response, timeout, out duration); + if(!sense) { - csdDecoded = Decoders.MMC.Decoders.DecodeCSD(csd); - blocks = (ulong)((csdDecoded.Size + 1) * Math.Pow(2, csdDecoded.SizeMultiplier + 2)); - blockSize = (uint)Math.Pow(2, csdDecoded.ReadBlockLength); + ecsdDecoded = Decoders.MMC.Decoders.DecodeExtendedCSD(ecsd); + blocksToRead = ecsdDecoded.OptimalReadSize; + blocks = ecsdDecoded.SectorCount; + blockSize = (uint)(ecsdDecoded.SectorSize == 1 ? 4096 : 512); + if(ecsdDecoded.NativeSectorSize == 0) physicalBlockSize = 512; + else if(ecsdDecoded.NativeSectorSize == 1) physicalBlockSize = 4096; + // Supposing it's high-capacity MMC if it has Extended CSD... + byteAddressed = false; } + else ecsd = null; + + dumpLog.WriteLine("Reading CSD"); + sense = dev.ReadCsd(out csd, out response, timeout, out duration); + if(!sense) + { + if(blocks == 0) + { + csdDecoded = Decoders.MMC.Decoders.DecodeCSD(csd); + blocks = (ulong)((csdDecoded.Size + 1) * Math.Pow(2, csdDecoded.SizeMultiplier + 2)); + blockSize = (uint)Math.Pow(2, csdDecoded.ReadBlockLength); + } + } + else csd = null; + + dumpLog.WriteLine("Reading OCR"); + sense = dev.ReadOcr(out ocr, out response, timeout, out duration); + if(sense) ocr = null; + + sidecar.BlockMedia[0].MultiMediaCard = new MultiMediaCardType(); + break; } - else csd = null; - - dumpLog.WriteLine("Reading OCR"); - sense = dev.ReadOcr(out ocr, out response, timeout, out duration); - if(sense) ocr = null; - - sidecar.BlockMedia[0].MultiMediaCard = new MultiMediaCardType(); - } - else if(dev.Type == DeviceType.SecureDigital) - { - Decoders.SecureDigital.CSD csdDecoded = new Decoders.SecureDigital.CSD(); - - dumpLog.WriteLine("Reading CSD"); - sense = dev.ReadCsd(out csd, out response, timeout, out duration); - if(!sense) + case DeviceType.SecureDigital: { - csdDecoded = Decoders.SecureDigital.Decoders.DecodeCSD(csd); - blocks = (ulong)(csdDecoded.Structure == 0 - ? (csdDecoded.Size + 1) * Math.Pow(2, csdDecoded.SizeMultiplier + 2) - : (csdDecoded.Size + 1) * 1024); - blockSize = (uint)Math.Pow(2, csdDecoded.ReadBlockLength); - // Structure >=1 for SDHC/SDXC, so that's block addressed - byteAddressed = csdDecoded.Structure == 0; + Decoders.SecureDigital.CSD csdDecoded = new Decoders.SecureDigital.CSD(); + + dumpLog.WriteLine("Reading CSD"); + sense = dev.ReadCsd(out csd, out response, timeout, out duration); + if(!sense) + { + csdDecoded = Decoders.SecureDigital.Decoders.DecodeCSD(csd); + blocks = (ulong)(csdDecoded.Structure == 0 + ? (csdDecoded.Size + 1) * Math.Pow(2, csdDecoded.SizeMultiplier + 2) + : (csdDecoded.Size + 1) * 1024); + blockSize = (uint)Math.Pow(2, csdDecoded.ReadBlockLength); + // Structure >=1 for SDHC/SDXC, so that's block addressed + byteAddressed = csdDecoded.Structure == 0; + } + else csd = null; + + dumpLog.WriteLine("Reading OCR"); + sense = dev.ReadSdocr(out ocr, out response, timeout, out duration); + if(sense) ocr = null; + + dumpLog.WriteLine("Reading SCR"); + sense = dev.ReadScr(out scr, out response, timeout, out duration); + if(sense) scr = null; + + sidecar.BlockMedia[0].SecureDigital = new SecureDigitalType(); + break; } - else csd = null; - - dumpLog.WriteLine("Reading OCR"); - sense = dev.ReadSdocr(out ocr, out response, timeout, out duration); - if(sense) ocr = null; - - dumpLog.WriteLine("Reading SCR"); - sense = dev.ReadScr(out scr, out response, timeout, out duration); - if(sense) scr = null; - - sidecar.BlockMedia[0].SecureDigital = new SecureDigitalType(); } dumpLog.WriteLine("Reading CID"); @@ -222,17 +226,17 @@ namespace DiscImageChef.Core.Devices.Dumping } ; - if(dev.Type == DeviceType.MMC) - { - sidecar.BlockMedia[0].MultiMediaCard.CID = cidDump; - sidecar.BlockMedia[0].MultiMediaCard.CSD = csdDump; - sidecar.BlockMedia[0].MultiMediaCard.OCR = ocrDump; - } - else if(dev.Type == DeviceType.SecureDigital) - { - sidecar.BlockMedia[0].SecureDigital.CID = cidDump; - sidecar.BlockMedia[0].SecureDigital.CSD = csdDump; - sidecar.BlockMedia[0].SecureDigital.OCR = ocrDump; + switch(dev.Type) { + case DeviceType.MMC: + sidecar.BlockMedia[0].MultiMediaCard.CID = cidDump; + sidecar.BlockMedia[0].MultiMediaCard.CSD = csdDump; + sidecar.BlockMedia[0].MultiMediaCard.OCR = ocrDump; + break; + case DeviceType.SecureDigital: + sidecar.BlockMedia[0].SecureDigital.CID = cidDump; + sidecar.BlockMedia[0].SecureDigital.CSD = csdDump; + sidecar.BlockMedia[0].SecureDigital.OCR = ocrDump; + break; } DateTime start; @@ -544,15 +548,15 @@ namespace DiscImageChef.Core.Devices.Dumping sidecar.BlockMedia[0].Checksums = dataChk.End().ToArray(); string xmlDskTyp = null, xmlDskSubTyp = null; - if(dev.Type == DeviceType.MMC) - { - Metadata.MediaType.MediaTypeToString(MediaType.MMC, out xmlDskTyp, out xmlDskSubTyp); - sidecar.BlockMedia[0].Dimensions = Metadata.Dimensions.DimensionsFromMediaType(MediaType.MMC); - } - else if(dev.Type == DeviceType.SecureDigital) - { - Metadata.MediaType.MediaTypeToString(MediaType.SecureDigital, out xmlDskTyp, out xmlDskSubTyp); - sidecar.BlockMedia[0].Dimensions = Metadata.Dimensions.DimensionsFromMediaType(MediaType.SecureDigital); + switch(dev.Type) { + case DeviceType.MMC: + Metadata.MediaType.MediaTypeToString(MediaType.MMC, out xmlDskTyp, out xmlDskSubTyp); + sidecar.BlockMedia[0].Dimensions = Metadata.Dimensions.DimensionsFromMediaType(MediaType.MMC); + break; + case DeviceType.SecureDigital: + Metadata.MediaType.MediaTypeToString(MediaType.SecureDigital, out xmlDskTyp, out xmlDskSubTyp); + sidecar.BlockMedia[0].Dimensions = Metadata.Dimensions.DimensionsFromMediaType(MediaType.SecureDigital); + break; } sidecar.BlockMedia[0].DiskType = xmlDskTyp; sidecar.BlockMedia[0].DiskSubType = xmlDskSubTyp; @@ -562,8 +566,12 @@ namespace DiscImageChef.Core.Devices.Dumping format = "Raw disk image (sector by sector copy)", Value = outputPrefix + ".bin" }; - if(dev.Type == DeviceType.MMC) sidecar.BlockMedia[0].Interface = "MultiMediaCard"; - else if(dev.Type == DeviceType.SecureDigital) sidecar.BlockMedia[0].Interface = "SecureDigital"; + switch(dev.Type) { + case DeviceType.MMC: sidecar.BlockMedia[0].Interface = "MultiMediaCard"; + break; + case DeviceType.SecureDigital: sidecar.BlockMedia[0].Interface = "SecureDigital"; + break; + } sidecar.BlockMedia[0].LogicalBlocks = (long)blocks; sidecar.BlockMedia[0].PhysicalBlockSize = physicalBlockSize > 0 ? physicalBlockSize : (int)blockSize; sidecar.BlockMedia[0].LogicalBlockSize = (int)blockSize; @@ -597,8 +605,12 @@ namespace DiscImageChef.Core.Devices.Dumping xmlFs.Close(); } - if(dev.Type == DeviceType.MMC) Statistics.AddMedia(MediaType.MMC, true); - else if(dev.Type == DeviceType.SecureDigital) Statistics.AddMedia(MediaType.SecureDigital, true); + switch(dev.Type) { + case DeviceType.MMC: Statistics.AddMedia(MediaType.MMC, true); + break; + case DeviceType.SecureDigital: Statistics.AddMedia(MediaType.SecureDigital, true); + break; + } } } } \ No newline at end of file diff --git a/DiscImageChef.Core/Devices/Dumping/XGD.cs b/DiscImageChef.Core/Devices/Dumping/XGD.cs index 7093a5d13..caa37517f 100644 --- a/DiscImageChef.Core/Devices/Dumping/XGD.cs +++ b/DiscImageChef.Core/Devices/Dumping/XGD.cs @@ -857,12 +857,16 @@ namespace DiscImageChef.Core.Devices.Dumping Statistics.AddFilesystem(plugin.XmlFSType.Type); dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); - if(plugin.XmlFSType.Type == "Opera") dskType = MediaType.ThreeDO; - if(plugin.XmlFSType.Type == "PC Engine filesystem") - dskType = MediaType.SuperCDROM2; - if(plugin.XmlFSType.Type == "Nintendo Wii filesystem") dskType = MediaType.WOD; - if(plugin.XmlFSType.Type == "Nintendo Gamecube filesystem") - dskType = MediaType.GOD; + switch(plugin.XmlFSType.Type) { + case "Opera": dskType = MediaType.ThreeDO; + break; + case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; + break; + case "Nintendo Wii filesystem": dskType = MediaType.WOD; + break; + case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; + break; + } } } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body @@ -895,10 +899,16 @@ namespace DiscImageChef.Core.Devices.Dumping Statistics.AddFilesystem(plugin.XmlFSType.Type); dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); - if(plugin.XmlFSType.Type == "Opera") dskType = MediaType.ThreeDO; - if(plugin.XmlFSType.Type == "PC Engine filesystem") dskType = MediaType.SuperCDROM2; - if(plugin.XmlFSType.Type == "Nintendo Wii filesystem") dskType = MediaType.WOD; - if(plugin.XmlFSType.Type == "Nintendo Gamecube filesystem") dskType = MediaType.GOD; + switch(plugin.XmlFSType.Type) { + case "Opera": dskType = MediaType.ThreeDO; + break; + case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; + break; + case "Nintendo Wii filesystem": dskType = MediaType.WOD; + break; + case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; + break; + } } } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body diff --git a/DiscImageChef.Core/Devices/ReaderSCSI.cs b/DiscImageChef.Core/Devices/ReaderSCSI.cs index 9820f71b7..f8e37e82b 100644 --- a/DiscImageChef.Core/Devices/ReaderSCSI.cs +++ b/DiscImageChef.Core/Devices/ReaderSCSI.cs @@ -337,13 +337,16 @@ namespace DiscImageChef.Core.Devices } else { - if(dev.Manufacturer == "HL-DT-ST") - hldtstReadRaw = - !dev.HlDtStReadRawDvd(out readBuffer, out senseBuf, 0, 1, timeout, out duration); - - if(dev.Manufacturer == "PLEXTOR") - plextorReadRaw = - !dev.PlextorReadRawDvd(out readBuffer, out senseBuf, 0, 1, timeout, out duration); + switch(dev.Manufacturer) { + case "HL-DT-ST": + hldtstReadRaw = + !dev.HlDtStReadRawDvd(out readBuffer, out senseBuf, 0, 1, timeout, out duration); + break; + case "PLEXTOR": + plextorReadRaw = + !dev.PlextorReadRawDvd(out readBuffer, out senseBuf, 0, 1, timeout, out duration); + break; + } if(hldtstReadRaw || plextorReadRaw) { diff --git a/DiscImageChef.Core/Devices/Report/PCMCIA.cs b/DiscImageChef.Core/Devices/Report/PCMCIA.cs index 34172f5d5..12c2455dd 100644 --- a/DiscImageChef.Core/Devices/Report/PCMCIA.cs +++ b/DiscImageChef.Core/Devices/Report/PCMCIA.cs @@ -45,29 +45,29 @@ namespace DiscImageChef.Core.Devices.Report Tuple[] tuples = CIS.GetTuples(dev.Cis); if(tuples != null) foreach(Tuple tuple in tuples) - if(tuple.Code == TupleCodes.CISTPL_MANFID) - { - ManufacturerIdentificationTuple manfid = CIS.DecodeManufacturerIdentificationTuple(tuple); + switch(tuple.Code) { + case TupleCodes.CISTPL_MANFID: + ManufacturerIdentificationTuple manfid = CIS.DecodeManufacturerIdentificationTuple(tuple); - if(manfid != null) - { - report.PCMCIA.ManufacturerCode = manfid.ManufacturerID; - report.PCMCIA.CardCode = manfid.CardID; - report.PCMCIA.ManufacturerCodeSpecified = true; - report.PCMCIA.CardCodeSpecified = true; - } - } - else if(tuple.Code == TupleCodes.CISTPL_VERS_1) - { - Level1VersionTuple vers = CIS.DecodeLevel1VersionTuple(tuple); + if(manfid != null) + { + report.PCMCIA.ManufacturerCode = manfid.ManufacturerID; + report.PCMCIA.CardCode = manfid.CardID; + report.PCMCIA.ManufacturerCodeSpecified = true; + report.PCMCIA.CardCodeSpecified = true; + } + break; + case TupleCodes.CISTPL_VERS_1: + Level1VersionTuple vers = CIS.DecodeLevel1VersionTuple(tuple); - if(vers != null) - { - report.PCMCIA.Manufacturer = vers.Manufacturer; - report.PCMCIA.ProductName = vers.Product; - report.PCMCIA.Compliance = string.Format("{0}.{1}", vers.MajorVersion, vers.MinorVersion); - report.PCMCIA.AdditionalInformation = vers.AdditionalInformation; - } + if(vers != null) + { + report.PCMCIA.Manufacturer = vers.Manufacturer; + report.PCMCIA.ProductName = vers.Product; + report.PCMCIA.Compliance = string.Format("{0}.{1}", vers.MajorVersion, vers.MinorVersion); + report.PCMCIA.AdditionalInformation = vers.AdditionalInformation; + } + break; } } } diff --git a/DiscImageChef.Core/Devices/Report/SCSI/General.cs b/DiscImageChef.Core/Devices/Report/SCSI/General.cs index ecfc7d933..0a8c9fcd6 100644 --- a/DiscImageChef.Core/Devices/Report/SCSI/General.cs +++ b/DiscImageChef.Core/Devices/Report/SCSI/General.cs @@ -204,16 +204,16 @@ namespace DiscImageChef.Core.Devices.Report.SCSI if(removable) { - if(dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice) - { - dev.AllowMediumRemoval(out senseBuffer, timeout, out duration); - dev.EjectTray(out senseBuffer, timeout, out duration); - } - else if(dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess) - { - dev.SpcAllowMediumRemoval(out senseBuffer, timeout, out duration); - DicConsole.WriteLine("Asking drive to unload tape (can take a few minutes)..."); - dev.Unload(out senseBuffer, timeout, out duration); + switch(dev.ScsiType) { + case Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice: + dev.AllowMediumRemoval(out senseBuffer, timeout, out duration); + dev.EjectTray(out senseBuffer, timeout, out duration); + break; + case Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess: + dev.SpcAllowMediumRemoval(out senseBuffer, timeout, out duration); + DicConsole.WriteLine("Asking drive to unload tape (can take a few minutes)..."); + dev.Unload(out senseBuffer, timeout, out duration); + break; } DicConsole.WriteLine("Please remove any media from the device and press any key when it is out."); System.Console.ReadKey(true); @@ -309,619 +309,621 @@ namespace DiscImageChef.Core.Devices.Report.SCSI List mediaTypes = new List(); - if(dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice) - Mmc.Report(dev, ref report, debug, ref cdromMode, ref mediaTypes); - else if(dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess) - Ssc.Report(dev, ref report, debug); - else - { - if(removable) - { - List mediaTests = new List(); - - pressedKey = new ConsoleKeyInfo(); - while(pressedKey.Key != ConsoleKey.N) + switch(dev.ScsiType) { + case Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice: Mmc.Report(dev, ref report, debug, ref cdromMode, ref mediaTypes); + break; + case Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess: Ssc.Report(dev, ref report, debug); + break; + default: + if(removable) { + List mediaTests = new List(); + pressedKey = new ConsoleKeyInfo(); - while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N) + while(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) - { - DicConsole.WriteLine("Please insert it in the drive and press any key when it is ready."); - System.Console.ReadKey(true); - - testedMediaType mediaTest = new testedMediaType(); - DicConsole.Write("Please write a description of the media type and press enter: "); - mediaTest.MediumTypeName = System.Console.ReadLine(); - DicConsole.Write("Please write the media manufacturer and press enter: "); - mediaTest.Manufacturer = System.Console.ReadLine(); - DicConsole.Write("Please write the media model and press enter: "); - mediaTest.Model = System.Console.ReadLine(); - - mediaTest.ManufacturerSpecified = true; - mediaTest.ModelSpecified = true; - mediaTest.MediaIsRecognized = true; - - sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); - if(sense) + pressedKey = new ConsoleKeyInfo(); + while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N) { - Decoders.SCSI.FixedSense? decSense = Decoders.SCSI.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"); - System.Threading.Thread.Sleep(2000); - sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); - if(!sense) break; - - leftRetries--; - } - - mediaTest.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"); - System.Threading.Thread.Sleep(2000); - sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); - if(!sense) break; - - leftRetries--; - } - - mediaTest.MediaIsRecognized &= !sense; - } - else mediaTest.MediaIsRecognized = false; - else mediaTest.MediaIsRecognized = false; + DicConsole.Write("Do you have media that you can insert in the drive? (Y/N): "); + pressedKey = System.Console.ReadKey(); + DicConsole.WriteLine(); } - if(mediaTest.MediaIsRecognized) + if(pressedKey.Key == ConsoleKey.Y) { - mediaTest.SupportsReadCapacitySpecified = true; - mediaTest.SupportsReadCapacity16Specified = true; + DicConsole.WriteLine("Please insert it in the drive and press any key when it is ready."); + System.Console.ReadKey(true); - DicConsole.WriteLine("Querying SCSI READ CAPACITY..."); - sense = dev.ReadCapacity(out buffer, out senseBuffer, timeout, out duration); - if(!sense && !dev.Error) - { - mediaTest.SupportsReadCapacity = true; - mediaTest.Blocks = - (ulong)((buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + - buffer[3]) + 1; - mediaTest.BlockSize = - (uint)((buffer[4] << 24) + (buffer[5] << 16) + (buffer[6] << 8) + buffer[7]); - mediaTest.BlocksSpecified = true; - mediaTest.BlockSizeSpecified = true; - } + testedMediaType mediaTest = new testedMediaType(); + DicConsole.Write("Please write a description of the media type and press enter: "); + mediaTest.MediumTypeName = System.Console.ReadLine(); + DicConsole.Write("Please write the media manufacturer and press enter: "); + mediaTest.Manufacturer = System.Console.ReadLine(); + DicConsole.Write("Please write the media model and press enter: "); + mediaTest.Model = System.Console.ReadLine(); - DicConsole.WriteLine("Querying SCSI READ CAPACITY (16)..."); - sense = dev.ReadCapacity16(out buffer, out buffer, timeout, out duration); - if(!sense && !dev.Error) - { - mediaTest.SupportsReadCapacity16 = true; - byte[] temp = new byte[8]; - Array.Copy(buffer, 0, temp, 0, 8); - Array.Reverse(temp); - mediaTest.Blocks = BitConverter.ToUInt64(temp, 0) + 1; - mediaTest.BlockSize = - (uint)((buffer[8] << 24) + (buffer[9] << 16) + (buffer[10] << 8) + - buffer[11]); - mediaTest.BlocksSpecified = true; - mediaTest.BlockSizeSpecified = true; - } + mediaTest.ManufacturerSpecified = true; + mediaTest.ModelSpecified = true; + mediaTest.MediaIsRecognized = true; - decMode = null; - - DicConsole.WriteLine("Querying SCSI MODE SENSE (10)..."); - sense = dev.ModeSense10(out buffer, out senseBuffer, false, true, - ScsiModeSensePageControl.Current, 0x3F, 0x00, timeout, - out duration); - if(!sense && !dev.Error) - { - report.SCSI.SupportsModeSense10 = true; - decMode = Decoders.SCSI.Modes.DecodeMode10(buffer, dev.ScsiType); - if(debug) mediaTest.ModeSense10Data = buffer; - } - - DicConsole.WriteLine("Querying SCSI MODE SENSE..."); - sense = dev.ModeSense(out buffer, out senseBuffer, timeout, out duration); - if(!sense && !dev.Error) - { - report.SCSI.SupportsModeSense6 = true; - if(!decMode.HasValue) - decMode = Decoders.SCSI.Modes.DecodeMode6(buffer, dev.ScsiType); - if(debug) mediaTest.ModeSense6Data = buffer; - } - - if(decMode.HasValue) - { - mediaTest.MediumType = (byte)decMode.Value.Header.MediumType; - mediaTest.MediumTypeSpecified = true; - if(decMode.Value.Header.BlockDescriptors != null && - decMode.Value.Header.BlockDescriptors.Length > 0) - { - mediaTest.Density = (byte)decMode.Value.Header.BlockDescriptors[0].Density; - mediaTest.DensitySpecified = true; - } - } - - mediaTest.SupportsReadSpecified = true; - mediaTest.SupportsRead10Specified = true; - mediaTest.SupportsRead12Specified = true; - mediaTest.SupportsRead16Specified = true; - mediaTest.SupportsReadLongSpecified = true; - - DicConsole.WriteLine("Trying SCSI READ (6)..."); - mediaTest.SupportsRead = !dev.Read6(out buffer, out senseBuffer, 0, mediaTest.BlockSize, - timeout, out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead); - if(debug) - DataFile.WriteTo("SCSI Report", "read6", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - buffer); - - DicConsole.WriteLine("Trying SCSI READ (10)..."); - mediaTest.SupportsRead10 = - !dev.Read10(out buffer, out senseBuffer, 0, false, true, false, false, 0, - mediaTest.BlockSize, 0, 1, timeout, out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead10); - if(debug) - DataFile.WriteTo("SCSI Report", "read10", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - buffer); - - DicConsole.WriteLine("Trying SCSI READ (12)..."); - mediaTest.SupportsRead12 = - !dev.Read12(out buffer, out senseBuffer, 0, false, true, false, false, 0, - mediaTest.BlockSize, 0, 1, false, timeout, out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead12); - if(debug) - DataFile.WriteTo("SCSI Report", "read12", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - buffer); - - DicConsole.WriteLine("Trying SCSI READ (16)..."); - mediaTest.SupportsRead16 = - !dev.Read16(out buffer, out senseBuffer, 0, false, true, false, 0, - mediaTest.BlockSize, 0, 1, false, timeout, out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead16); - if(debug) - DataFile.WriteTo("SCSI Report", "read16", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - buffer); - - mediaTest.LongBlockSize = mediaTest.BlockSize; - DicConsole.WriteLine("Trying SCSI READ LONG (10)..."); - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 0xFFFF, timeout, - out duration); - if(sense && !dev.Error) + sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); + if(sense) { Decoders.SCSI.FixedSense? decSense = Decoders.SCSI.Sense.DecodeFixed(senseBuffer); if(decSense.HasValue) - if(decSense.Value.SenseKey == Decoders.SCSI.SenseKeys.IllegalRequest && - decSense.Value.ASC == 0x24 && decSense.Value.ASCQ == 0x00) + if(decSense.Value.ASC == 0x3A) { - mediaTest.SupportsReadLong = true; - if(decSense.Value.InformationValid && decSense.Value.ILI) + int leftRetries = 20; + while(leftRetries > 0) { - mediaTest.LongBlockSize = - 0xFFFF - (decSense.Value.Information & 0xFFFF); - mediaTest.LongBlockSizeSpecified = true; + DicConsole.Write("\rWaiting for drive to become ready"); + System.Threading.Thread.Sleep(2000); + sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); + if(!sense) break; + + leftRetries--; } + + mediaTest.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"); + System.Threading.Thread.Sleep(2000); + sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); + if(!sense) break; + + leftRetries--; + } + + mediaTest.MediaIsRecognized &= !sense; + } + else mediaTest.MediaIsRecognized = false; + else mediaTest.MediaIsRecognized = false; } - if(mediaTest.SupportsReadLong && mediaTest.LongBlockSize == mediaTest.BlockSize) - if(mediaTest.BlockSize == 512) - foreach(ushort testSize in new[] - { - // Long sector sizes for floppies - 514, - // Long sector sizes for SuperDisk - 536, 558, - // Long sector sizes for 512-byte magneto-opticals - 600, 610, 630 - }) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, - testSize, timeout, out duration); - if(!sense && !dev.Error) - { - mediaTest.SupportsReadLong = true; - mediaTest.LongBlockSize = testSize; - mediaTest.LongBlockSizeSpecified = true; - break; - } - } - else if(mediaTest.BlockSize == 1024) - foreach(ushort testSize in new[] - { - // Long sector sizes for floppies - 1026, - // Long sector sizes for 1024-byte magneto-opticals - 1200 - }) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, - testSize, timeout, out duration); - if(!sense && !dev.Error) - { - mediaTest.SupportsReadLong = true; - mediaTest.LongBlockSize = testSize; - mediaTest.LongBlockSizeSpecified = true; - break; - } - } - else if(mediaTest.BlockSize == 2048) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 2380, - timeout, out duration); - if(!sense && !dev.Error) - { - mediaTest.SupportsReadLong = true; - mediaTest.LongBlockSize = 2380; - mediaTest.LongBlockSizeSpecified = true; - } - } - else if(mediaTest.BlockSize == 4096) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 4760, - timeout, out duration); - if(!sense && !dev.Error) - { - mediaTest.SupportsReadLong = true; - mediaTest.LongBlockSize = 4760; - mediaTest.LongBlockSizeSpecified = true; - } - } - else if(mediaTest.BlockSize == 8192) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 9424, - timeout, out duration); - if(!sense && !dev.Error) - { - mediaTest.SupportsReadLong = true; - mediaTest.LongBlockSize = 9424; - mediaTest.LongBlockSizeSpecified = true; - } - } - - if(mediaTest.SupportsReadLong && mediaTest.LongBlockSize == mediaTest.BlockSize) + if(mediaTest.MediaIsRecognized) { - pressedKey = new ConsoleKeyInfo(); - while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N) + mediaTest.SupportsReadCapacitySpecified = true; + mediaTest.SupportsReadCapacity16Specified = true; + + DicConsole.WriteLine("Querying SCSI READ CAPACITY..."); + sense = dev.ReadCapacity(out buffer, out senseBuffer, timeout, out duration); + if(!sense && !dev.Error) { - DicConsole - .Write("Drive supports SCSI READ LONG but I cannot find the correct size. Do you want me to try? (This can take hours) (Y/N): "); - pressedKey = System.Console.ReadKey(); - DicConsole.WriteLine(); + mediaTest.SupportsReadCapacity = true; + mediaTest.Blocks = + (ulong)((buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + + buffer[3]) + 1; + mediaTest.BlockSize = + (uint)((buffer[4] << 24) + (buffer[5] << 16) + (buffer[6] << 8) + buffer[7]); + mediaTest.BlocksSpecified = true; + mediaTest.BlockSizeSpecified = true; } - if(pressedKey.Key == ConsoleKey.Y) + DicConsole.WriteLine("Querying SCSI READ CAPACITY (16)..."); + sense = dev.ReadCapacity16(out buffer, out buffer, timeout, out duration); + if(!sense && !dev.Error) { - for(ushort i = (ushort)mediaTest.BlockSize; i <= ushort.MaxValue; i++) + mediaTest.SupportsReadCapacity16 = true; + byte[] temp = new byte[8]; + Array.Copy(buffer, 0, temp, 0, 8); + Array.Reverse(temp); + mediaTest.Blocks = BitConverter.ToUInt64(temp, 0) + 1; + mediaTest.BlockSize = + (uint)((buffer[8] << 24) + (buffer[9] << 16) + (buffer[10] << 8) + + buffer[11]); + mediaTest.BlocksSpecified = true; + mediaTest.BlockSizeSpecified = true; + } + + decMode = null; + + DicConsole.WriteLine("Querying SCSI MODE SENSE (10)..."); + sense = dev.ModeSense10(out buffer, out senseBuffer, false, true, + ScsiModeSensePageControl.Current, 0x3F, 0x00, timeout, + out duration); + if(!sense && !dev.Error) + { + report.SCSI.SupportsModeSense10 = true; + decMode = Decoders.SCSI.Modes.DecodeMode10(buffer, dev.ScsiType); + if(debug) mediaTest.ModeSense10Data = buffer; + } + + DicConsole.WriteLine("Querying SCSI MODE SENSE..."); + sense = dev.ModeSense(out buffer, out senseBuffer, timeout, out duration); + if(!sense && !dev.Error) + { + report.SCSI.SupportsModeSense6 = true; + if(!decMode.HasValue) + decMode = Decoders.SCSI.Modes.DecodeMode6(buffer, dev.ScsiType); + if(debug) mediaTest.ModeSense6Data = buffer; + } + + if(decMode.HasValue) + { + mediaTest.MediumType = (byte)decMode.Value.Header.MediumType; + mediaTest.MediumTypeSpecified = true; + if(decMode.Value.Header.BlockDescriptors != null && + decMode.Value.Header.BlockDescriptors.Length > 0) { - DicConsole.Write("\rTrying to READ LONG with a size of {0} bytes...", i); - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, i, - timeout, out duration); - if(!sense) - { - mediaTest.LongBlockSize = i; - mediaTest.LongBlockSizeSpecified = true; - break; - } - - if(i == ushort.MaxValue) break; + mediaTest.Density = (byte)decMode.Value.Header.BlockDescriptors[0].Density; + mediaTest.DensitySpecified = true; } - - DicConsole.WriteLine(); } - } - if(debug && mediaTest.SupportsReadLong && mediaTest.LongBlockSizeSpecified && - mediaTest.LongBlockSize != mediaTest.BlockSize) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, - (ushort)mediaTest.LongBlockSize, timeout, out duration); - if(!sense) - DataFile.WriteTo("SCSI Report", "readlong10", + mediaTest.SupportsReadSpecified = true; + mediaTest.SupportsRead10Specified = true; + mediaTest.SupportsRead12Specified = true; + mediaTest.SupportsRead16Specified = true; + mediaTest.SupportsReadLongSpecified = true; + + DicConsole.WriteLine("Trying SCSI READ (6)..."); + mediaTest.SupportsRead = !dev.Read6(out buffer, out senseBuffer, 0, mediaTest.BlockSize, + timeout, out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead); + if(debug) + DataFile.WriteTo("SCSI Report", "read6", "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", buffer); - } - mediaTest.CanReadMediaSerialSpecified = true; - DicConsole.WriteLine("Trying SCSI READ MEDIA SERIAL NUMBER..."); - mediaTest.CanReadMediaSerial = - !dev.ReadMediaSerialNumber(out buffer, out senseBuffer, timeout, out duration); - } - - mediaTests.Add(mediaTest); - } - } - - report.SCSI.RemovableMedias = mediaTests.ToArray(); - } - else - { - report.SCSI.ReadCapabilities = new testedMediaType(); - report.SCSI.ReadCapabilitiesSpecified = true; - report.SCSI.ReadCapabilities.MediaIsRecognized = true; - - report.SCSI.ReadCapabilities.SupportsReadCapacitySpecified = true; - report.SCSI.ReadCapabilities.SupportsReadCapacity16Specified = true; - - DicConsole.WriteLine("Querying SCSI READ CAPACITY..."); - sense = dev.ReadCapacity(out buffer, out senseBuffer, timeout, out duration); - if(!sense && !dev.Error) - { - report.SCSI.ReadCapabilities.SupportsReadCapacity = true; - report.SCSI.ReadCapabilities.Blocks = - (ulong)((buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3]) + 1; - report.SCSI.ReadCapabilities.BlockSize = - (uint)((buffer[4] << 24) + (buffer[5] << 16) + (buffer[6] << 8) + buffer[7]); - report.SCSI.ReadCapabilities.BlocksSpecified = true; - report.SCSI.ReadCapabilities.BlockSizeSpecified = true; - } - - DicConsole.WriteLine("Querying SCSI READ CAPACITY (16)..."); - sense = dev.ReadCapacity16(out buffer, out buffer, timeout, out duration); - if(!sense && !dev.Error) - { - report.SCSI.ReadCapabilities.SupportsReadCapacity16 = true; - byte[] temp = new byte[8]; - Array.Copy(buffer, 0, temp, 0, 8); - Array.Reverse(temp); - report.SCSI.ReadCapabilities.Blocks = BitConverter.ToUInt64(temp, 0) + 1; - report.SCSI.ReadCapabilities.BlockSize = - (uint)((buffer[8] << 24) + (buffer[9] << 16) + (buffer[10] << 8) + buffer[11]); - report.SCSI.ReadCapabilities.BlocksSpecified = true; - report.SCSI.ReadCapabilities.BlockSizeSpecified = true; - } - - decMode = null; - - DicConsole.WriteLine("Querying SCSI MODE SENSE (10)..."); - sense = dev.ModeSense10(out buffer, out senseBuffer, false, true, ScsiModeSensePageControl.Current, - 0x3F, 0x00, timeout, out duration); - if(!sense && !dev.Error) - { - report.SCSI.SupportsModeSense10 = true; - decMode = Decoders.SCSI.Modes.DecodeMode10(buffer, dev.ScsiType); - if(debug) report.SCSI.ReadCapabilities.ModeSense10Data = buffer; - } - - DicConsole.WriteLine("Querying SCSI MODE SENSE..."); - sense = dev.ModeSense(out buffer, out senseBuffer, timeout, out duration); - if(!sense && !dev.Error) - { - report.SCSI.SupportsModeSense6 = true; - if(!decMode.HasValue) decMode = Decoders.SCSI.Modes.DecodeMode6(buffer, dev.ScsiType); - if(debug) report.SCSI.ReadCapabilities.ModeSense6Data = buffer; - } - - if(decMode.HasValue) - { - report.SCSI.ReadCapabilities.MediumType = (byte)decMode.Value.Header.MediumType; - report.SCSI.ReadCapabilities.MediumTypeSpecified = true; - if(decMode.Value.Header.BlockDescriptors != null && - decMode.Value.Header.BlockDescriptors.Length > 0) - { - report.SCSI.ReadCapabilities.Density = - (byte)decMode.Value.Header.BlockDescriptors[0].Density; - report.SCSI.ReadCapabilities.DensitySpecified = true; - } - } - - report.SCSI.ReadCapabilities.SupportsReadSpecified = true; - report.SCSI.ReadCapabilities.SupportsRead10Specified = true; - report.SCSI.ReadCapabilities.SupportsRead12Specified = true; - report.SCSI.ReadCapabilities.SupportsRead16Specified = true; - report.SCSI.ReadCapabilities.SupportsReadLongSpecified = true; - - DicConsole.WriteLine("Trying SCSI READ (6)..."); - report.SCSI.ReadCapabilities.SupportsRead = !dev.Read6(out buffer, out senseBuffer, 0, - report.SCSI.ReadCapabilities.BlockSize, - timeout, out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !report.SCSI.ReadCapabilities.SupportsRead); - if(debug) - DataFile.WriteTo("SCSI Report", "read6", - "_debug_" + report.SCSI.Inquiry.ProductIdentification + ".bin", "read results", - buffer); - - DicConsole.WriteLine("Trying SCSI READ (10)..."); - report.SCSI.ReadCapabilities.SupportsRead10 = - !dev.Read10(out buffer, out senseBuffer, 0, false, true, false, false, 0, - report.SCSI.ReadCapabilities.BlockSize, 0, 1, timeout, out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", - !report.SCSI.ReadCapabilities.SupportsRead10); - if(debug) - DataFile.WriteTo("SCSI Report", "read10", - "_debug_" + report.SCSI.Inquiry.ProductIdentification + ".bin", "read results", - buffer); - - DicConsole.WriteLine("Trying SCSI READ (12)..."); - report.SCSI.ReadCapabilities.SupportsRead12 = - !dev.Read12(out buffer, out senseBuffer, 0, false, true, false, false, 0, - report.SCSI.ReadCapabilities.BlockSize, 0, 1, false, timeout, out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", - !report.SCSI.ReadCapabilities.SupportsRead12); - if(debug) - DataFile.WriteTo("SCSI Report", "read12", - "_debug_" + report.SCSI.Inquiry.ProductIdentification + ".bin", "read results", - buffer); - - DicConsole.WriteLine("Trying SCSI READ (16)..."); - report.SCSI.ReadCapabilities.SupportsRead16 = - !dev.Read16(out buffer, out senseBuffer, 0, false, true, false, 0, - report.SCSI.ReadCapabilities.BlockSize, 0, 1, false, timeout, out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", - !report.SCSI.ReadCapabilities.SupportsRead16); - if(debug) - DataFile.WriteTo("SCSI Report", "read16", - "_debug_" + report.SCSI.Inquiry.ProductIdentification + ".bin", "read results", - buffer); - - report.SCSI.ReadCapabilities.LongBlockSize = report.SCSI.ReadCapabilities.BlockSize; - DicConsole.WriteLine("Trying SCSI READ LONG (10)..."); - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 0xFFFF, timeout, out duration); - if(sense && !dev.Error) - { - Decoders.SCSI.FixedSense? decSense = Decoders.SCSI.Sense.DecodeFixed(senseBuffer); - if(decSense.HasValue) - if(decSense.Value.SenseKey == Decoders.SCSI.SenseKeys.IllegalRequest && - decSense.Value.ASC == 0x24 && decSense.Value.ASCQ == 0x00) - { - report.SCSI.ReadCapabilities.SupportsReadLong = true; - if(decSense.Value.InformationValid && decSense.Value.ILI) - { - report.SCSI.ReadCapabilities.LongBlockSize = - 0xFFFF - (decSense.Value.Information & 0xFFFF); - report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; - } - } - } - - if(report.SCSI.ReadCapabilities.SupportsReadLong && report.SCSI.ReadCapabilities.LongBlockSize == - report.SCSI.ReadCapabilities.BlockSize) - if(report.SCSI.ReadCapabilities.BlockSize == 512) - foreach(ushort testSize in new[] - { - // Long sector sizes for floppies - 514, - // Long sector sizes for SuperDisk - 536, 558, - // Long sector sizes for 512-byte magneto-opticals - 600, 610, 630 - }) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, testSize, timeout, - out duration); - if(!sense && !dev.Error) - { - report.SCSI.ReadCapabilities.SupportsReadLong = true; - report.SCSI.ReadCapabilities.LongBlockSize = testSize; - report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; - break; - } - } - else if(report.SCSI.ReadCapabilities.BlockSize == 1024) - foreach(ushort testSize in new[] - { - // Long sector sizes for floppies - 1026, - // Long sector sizes for 1024-byte magneto-opticals - 1200 - }) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, testSize, timeout, - out duration); - if(!sense && !dev.Error) - { - report.SCSI.ReadCapabilities.SupportsReadLong = true; - report.SCSI.ReadCapabilities.LongBlockSize = testSize; - report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; - break; - } - } - else if(report.SCSI.ReadCapabilities.BlockSize == 2048) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 2380, timeout, - out duration); - if(!sense && !dev.Error) - { - report.SCSI.ReadCapabilities.SupportsReadLong = true; - report.SCSI.ReadCapabilities.LongBlockSize = 2380; - report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; - } - } - else if(report.SCSI.ReadCapabilities.BlockSize == 4096) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 4760, timeout, - out duration); - if(!sense && !dev.Error) - { - report.SCSI.ReadCapabilities.SupportsReadLong = true; - report.SCSI.ReadCapabilities.LongBlockSize = 4760; - report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; - } - } - else if(report.SCSI.ReadCapabilities.BlockSize == 8192) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 9424, timeout, - out duration); - if(!sense && !dev.Error) - { - report.SCSI.ReadCapabilities.SupportsReadLong = true; - report.SCSI.ReadCapabilities.LongBlockSize = 9424; - report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; - } - } - - if(report.SCSI.ReadCapabilities.SupportsReadLong && report.SCSI.ReadCapabilities.LongBlockSize == - report.SCSI.ReadCapabilities.BlockSize) - { - pressedKey = new ConsoleKeyInfo(); - while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N) - { - DicConsole - .Write("Drive supports SCSI READ LONG but I cannot find the correct size. Do you want me to try? (This can take hours) (Y/N): "); - pressedKey = System.Console.ReadKey(); - DicConsole.WriteLine(); - } - - if(pressedKey.Key == ConsoleKey.Y) - { - for(ushort i = (ushort)report.SCSI.ReadCapabilities.BlockSize; i <= ushort.MaxValue; i++) - { - DicConsole.Write("\rTrying to READ LONG with a size of {0} bytes...", i); - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, i, timeout, - out duration); - if(!sense) - { + DicConsole.WriteLine("Trying SCSI READ (10)..."); + mediaTest.SupportsRead10 = + !dev.Read10(out buffer, out senseBuffer, 0, false, true, false, false, 0, + mediaTest.BlockSize, 0, 1, timeout, out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead10); if(debug) + DataFile.WriteTo("SCSI Report", "read10", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + buffer); + + DicConsole.WriteLine("Trying SCSI READ (12)..."); + mediaTest.SupportsRead12 = + !dev.Read12(out buffer, out senseBuffer, 0, false, true, false, false, 0, + mediaTest.BlockSize, 0, 1, false, timeout, out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead12); + if(debug) + DataFile.WriteTo("SCSI Report", "read12", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + buffer); + + DicConsole.WriteLine("Trying SCSI READ (16)..."); + mediaTest.SupportsRead16 = + !dev.Read16(out buffer, out senseBuffer, 0, false, true, false, 0, + mediaTest.BlockSize, 0, 1, false, timeout, out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead16); + if(debug) + DataFile.WriteTo("SCSI Report", "read16", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + buffer); + + mediaTest.LongBlockSize = mediaTest.BlockSize; + DicConsole.WriteLine("Trying SCSI READ LONG (10)..."); + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 0xFFFF, timeout, + out duration); + if(sense && !dev.Error) { - FileStream bingo = - new FileStream(string.Format("{0}_readlong.bin", dev.Model), - FileMode.Create); - bingo.Write(buffer, 0, buffer.Length); - bingo.Close(); + Decoders.SCSI.FixedSense? decSense = Decoders.SCSI.Sense.DecodeFixed(senseBuffer); + if(decSense.HasValue) + if(decSense.Value.SenseKey == Decoders.SCSI.SenseKeys.IllegalRequest && + decSense.Value.ASC == 0x24 && decSense.Value.ASCQ == 0x00) + { + mediaTest.SupportsReadLong = true; + if(decSense.Value.InformationValid && decSense.Value.ILI) + { + mediaTest.LongBlockSize = + 0xFFFF - (decSense.Value.Information & 0xFFFF); + mediaTest.LongBlockSizeSpecified = true; + } + } } - report.SCSI.ReadCapabilities.LongBlockSize = i; - report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; - break; + + if(mediaTest.SupportsReadLong && mediaTest.LongBlockSize == mediaTest.BlockSize) + if(mediaTest.BlockSize == 512) + foreach(ushort testSize in new[] + { + // Long sector sizes for floppies + 514, + // Long sector sizes for SuperDisk + 536, 558, + // Long sector sizes for 512-byte magneto-opticals + 600, 610, 630 + }) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, + testSize, timeout, out duration); + if(!sense && !dev.Error) + { + mediaTest.SupportsReadLong = true; + mediaTest.LongBlockSize = testSize; + mediaTest.LongBlockSizeSpecified = true; + break; + } + } + else if(mediaTest.BlockSize == 1024) + foreach(ushort testSize in new[] + { + // Long sector sizes for floppies + 1026, + // Long sector sizes for 1024-byte magneto-opticals + 1200 + }) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, + testSize, timeout, out duration); + if(!sense && !dev.Error) + { + mediaTest.SupportsReadLong = true; + mediaTest.LongBlockSize = testSize; + mediaTest.LongBlockSizeSpecified = true; + break; + } + } + else if(mediaTest.BlockSize == 2048) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 2380, + timeout, out duration); + if(!sense && !dev.Error) + { + mediaTest.SupportsReadLong = true; + mediaTest.LongBlockSize = 2380; + mediaTest.LongBlockSizeSpecified = true; + } + } + else if(mediaTest.BlockSize == 4096) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 4760, + timeout, out duration); + if(!sense && !dev.Error) + { + mediaTest.SupportsReadLong = true; + mediaTest.LongBlockSize = 4760; + mediaTest.LongBlockSizeSpecified = true; + } + } + else if(mediaTest.BlockSize == 8192) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 9424, + timeout, out duration); + if(!sense && !dev.Error) + { + mediaTest.SupportsReadLong = true; + mediaTest.LongBlockSize = 9424; + mediaTest.LongBlockSizeSpecified = true; + } + } + + if(mediaTest.SupportsReadLong && mediaTest.LongBlockSize == mediaTest.BlockSize) + { + pressedKey = new ConsoleKeyInfo(); + while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N) + { + DicConsole + .Write("Drive supports SCSI READ LONG but I cannot find the correct size. Do you want me to try? (This can take hours) (Y/N): "); + pressedKey = System.Console.ReadKey(); + DicConsole.WriteLine(); + } + + if(pressedKey.Key == ConsoleKey.Y) + { + for(ushort i = (ushort)mediaTest.BlockSize; i <= ushort.MaxValue; i++) + { + DicConsole.Write("\rTrying to READ LONG with a size of {0} bytes...", i); + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, i, + timeout, out duration); + if(!sense) + { + mediaTest.LongBlockSize = i; + mediaTest.LongBlockSizeSpecified = true; + break; + } + + if(i == ushort.MaxValue) break; + } + + DicConsole.WriteLine(); + } + } + + if(debug && mediaTest.SupportsReadLong && mediaTest.LongBlockSizeSpecified && + mediaTest.LongBlockSize != mediaTest.BlockSize) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, + (ushort)mediaTest.LongBlockSize, timeout, out duration); + if(!sense) + DataFile.WriteTo("SCSI Report", "readlong10", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + buffer); + } + + mediaTest.CanReadMediaSerialSpecified = true; + DicConsole.WriteLine("Trying SCSI READ MEDIA SERIAL NUMBER..."); + mediaTest.CanReadMediaSerial = + !dev.ReadMediaSerialNumber(out buffer, out senseBuffer, timeout, out duration); } - if(i == ushort.MaxValue) break; + mediaTests.Add(mediaTest); + } + } + + report.SCSI.RemovableMedias = mediaTests.ToArray(); + } + else + { + report.SCSI.ReadCapabilities = new testedMediaType(); + report.SCSI.ReadCapabilitiesSpecified = true; + report.SCSI.ReadCapabilities.MediaIsRecognized = true; + + report.SCSI.ReadCapabilities.SupportsReadCapacitySpecified = true; + report.SCSI.ReadCapabilities.SupportsReadCapacity16Specified = true; + + DicConsole.WriteLine("Querying SCSI READ CAPACITY..."); + sense = dev.ReadCapacity(out buffer, out senseBuffer, timeout, out duration); + if(!sense && !dev.Error) + { + report.SCSI.ReadCapabilities.SupportsReadCapacity = true; + report.SCSI.ReadCapabilities.Blocks = + (ulong)((buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3]) + 1; + report.SCSI.ReadCapabilities.BlockSize = + (uint)((buffer[4] << 24) + (buffer[5] << 16) + (buffer[6] << 8) + buffer[7]); + report.SCSI.ReadCapabilities.BlocksSpecified = true; + report.SCSI.ReadCapabilities.BlockSizeSpecified = true; + } + + DicConsole.WriteLine("Querying SCSI READ CAPACITY (16)..."); + sense = dev.ReadCapacity16(out buffer, out buffer, timeout, out duration); + if(!sense && !dev.Error) + { + report.SCSI.ReadCapabilities.SupportsReadCapacity16 = true; + byte[] temp = new byte[8]; + Array.Copy(buffer, 0, temp, 0, 8); + Array.Reverse(temp); + report.SCSI.ReadCapabilities.Blocks = BitConverter.ToUInt64(temp, 0) + 1; + report.SCSI.ReadCapabilities.BlockSize = + (uint)((buffer[8] << 24) + (buffer[9] << 16) + (buffer[10] << 8) + buffer[11]); + report.SCSI.ReadCapabilities.BlocksSpecified = true; + report.SCSI.ReadCapabilities.BlockSizeSpecified = true; + } + + decMode = null; + + DicConsole.WriteLine("Querying SCSI MODE SENSE (10)..."); + sense = dev.ModeSense10(out buffer, out senseBuffer, false, true, ScsiModeSensePageControl.Current, + 0x3F, 0x00, timeout, out duration); + if(!sense && !dev.Error) + { + report.SCSI.SupportsModeSense10 = true; + decMode = Decoders.SCSI.Modes.DecodeMode10(buffer, dev.ScsiType); + if(debug) report.SCSI.ReadCapabilities.ModeSense10Data = buffer; + } + + DicConsole.WriteLine("Querying SCSI MODE SENSE..."); + sense = dev.ModeSense(out buffer, out senseBuffer, timeout, out duration); + if(!sense && !dev.Error) + { + report.SCSI.SupportsModeSense6 = true; + if(!decMode.HasValue) decMode = Decoders.SCSI.Modes.DecodeMode6(buffer, dev.ScsiType); + if(debug) report.SCSI.ReadCapabilities.ModeSense6Data = buffer; + } + + if(decMode.HasValue) + { + report.SCSI.ReadCapabilities.MediumType = (byte)decMode.Value.Header.MediumType; + report.SCSI.ReadCapabilities.MediumTypeSpecified = true; + if(decMode.Value.Header.BlockDescriptors != null && + decMode.Value.Header.BlockDescriptors.Length > 0) + { + report.SCSI.ReadCapabilities.Density = + (byte)decMode.Value.Header.BlockDescriptors[0].Density; + report.SCSI.ReadCapabilities.DensitySpecified = true; + } + } + + report.SCSI.ReadCapabilities.SupportsReadSpecified = true; + report.SCSI.ReadCapabilities.SupportsRead10Specified = true; + report.SCSI.ReadCapabilities.SupportsRead12Specified = true; + report.SCSI.ReadCapabilities.SupportsRead16Specified = true; + report.SCSI.ReadCapabilities.SupportsReadLongSpecified = true; + + DicConsole.WriteLine("Trying SCSI READ (6)..."); + report.SCSI.ReadCapabilities.SupportsRead = !dev.Read6(out buffer, out senseBuffer, 0, + report.SCSI.ReadCapabilities.BlockSize, + timeout, out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !report.SCSI.ReadCapabilities.SupportsRead); + if(debug) + DataFile.WriteTo("SCSI Report", "read6", + "_debug_" + report.SCSI.Inquiry.ProductIdentification + ".bin", "read results", + buffer); + + DicConsole.WriteLine("Trying SCSI READ (10)..."); + report.SCSI.ReadCapabilities.SupportsRead10 = + !dev.Read10(out buffer, out senseBuffer, 0, false, true, false, false, 0, + report.SCSI.ReadCapabilities.BlockSize, 0, 1, timeout, out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", + !report.SCSI.ReadCapabilities.SupportsRead10); + if(debug) + DataFile.WriteTo("SCSI Report", "read10", + "_debug_" + report.SCSI.Inquiry.ProductIdentification + ".bin", "read results", + buffer); + + DicConsole.WriteLine("Trying SCSI READ (12)..."); + report.SCSI.ReadCapabilities.SupportsRead12 = + !dev.Read12(out buffer, out senseBuffer, 0, false, true, false, false, 0, + report.SCSI.ReadCapabilities.BlockSize, 0, 1, false, timeout, out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", + !report.SCSI.ReadCapabilities.SupportsRead12); + if(debug) + DataFile.WriteTo("SCSI Report", "read12", + "_debug_" + report.SCSI.Inquiry.ProductIdentification + ".bin", "read results", + buffer); + + DicConsole.WriteLine("Trying SCSI READ (16)..."); + report.SCSI.ReadCapabilities.SupportsRead16 = + !dev.Read16(out buffer, out senseBuffer, 0, false, true, false, 0, + report.SCSI.ReadCapabilities.BlockSize, 0, 1, false, timeout, out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", + !report.SCSI.ReadCapabilities.SupportsRead16); + if(debug) + DataFile.WriteTo("SCSI Report", "read16", + "_debug_" + report.SCSI.Inquiry.ProductIdentification + ".bin", "read results", + buffer); + + report.SCSI.ReadCapabilities.LongBlockSize = report.SCSI.ReadCapabilities.BlockSize; + DicConsole.WriteLine("Trying SCSI READ LONG (10)..."); + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 0xFFFF, timeout, out duration); + if(sense && !dev.Error) + { + Decoders.SCSI.FixedSense? decSense = Decoders.SCSI.Sense.DecodeFixed(senseBuffer); + if(decSense.HasValue) + if(decSense.Value.SenseKey == Decoders.SCSI.SenseKeys.IllegalRequest && + decSense.Value.ASC == 0x24 && decSense.Value.ASCQ == 0x00) + { + report.SCSI.ReadCapabilities.SupportsReadLong = true; + if(decSense.Value.InformationValid && decSense.Value.ILI) + { + report.SCSI.ReadCapabilities.LongBlockSize = + 0xFFFF - (decSense.Value.Information & 0xFFFF); + report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; + } + } + } + + if(report.SCSI.ReadCapabilities.SupportsReadLong && report.SCSI.ReadCapabilities.LongBlockSize == + report.SCSI.ReadCapabilities.BlockSize) + if(report.SCSI.ReadCapabilities.BlockSize == 512) + foreach(ushort testSize in new[] + { + // Long sector sizes for floppies + 514, + // Long sector sizes for SuperDisk + 536, 558, + // Long sector sizes for 512-byte magneto-opticals + 600, 610, 630 + }) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, testSize, timeout, + out duration); + if(!sense && !dev.Error) + { + report.SCSI.ReadCapabilities.SupportsReadLong = true; + report.SCSI.ReadCapabilities.LongBlockSize = testSize; + report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; + break; + } + } + else if(report.SCSI.ReadCapabilities.BlockSize == 1024) + foreach(ushort testSize in new[] + { + // Long sector sizes for floppies + 1026, + // Long sector sizes for 1024-byte magneto-opticals + 1200 + }) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, testSize, timeout, + out duration); + if(!sense && !dev.Error) + { + report.SCSI.ReadCapabilities.SupportsReadLong = true; + report.SCSI.ReadCapabilities.LongBlockSize = testSize; + report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; + break; + } + } + else if(report.SCSI.ReadCapabilities.BlockSize == 2048) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 2380, timeout, + out duration); + if(!sense && !dev.Error) + { + report.SCSI.ReadCapabilities.SupportsReadLong = true; + report.SCSI.ReadCapabilities.LongBlockSize = 2380; + report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; + } + } + else if(report.SCSI.ReadCapabilities.BlockSize == 4096) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 4760, timeout, + out duration); + if(!sense && !dev.Error) + { + report.SCSI.ReadCapabilities.SupportsReadLong = true; + report.SCSI.ReadCapabilities.LongBlockSize = 4760; + report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; + } + } + else if(report.SCSI.ReadCapabilities.BlockSize == 8192) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 9424, timeout, + out duration); + if(!sense && !dev.Error) + { + report.SCSI.ReadCapabilities.SupportsReadLong = true; + report.SCSI.ReadCapabilities.LongBlockSize = 9424; + report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; + } } - DicConsole.WriteLine(); + if(report.SCSI.ReadCapabilities.SupportsReadLong && report.SCSI.ReadCapabilities.LongBlockSize == + report.SCSI.ReadCapabilities.BlockSize) + { + pressedKey = new ConsoleKeyInfo(); + while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N) + { + DicConsole + .Write("Drive supports SCSI READ LONG but I cannot find the correct size. Do you want me to try? (This can take hours) (Y/N): "); + pressedKey = System.Console.ReadKey(); + DicConsole.WriteLine(); + } + + if(pressedKey.Key == ConsoleKey.Y) + { + for(ushort i = (ushort)report.SCSI.ReadCapabilities.BlockSize; i <= ushort.MaxValue; i++) + { + DicConsole.Write("\rTrying to READ LONG with a size of {0} bytes...", i); + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, i, timeout, + out duration); + if(!sense) + { + if(debug) + { + FileStream bingo = + new FileStream(string.Format("{0}_readlong.bin", dev.Model), + FileMode.Create); + bingo.Write(buffer, 0, buffer.Length); + bingo.Close(); + } + report.SCSI.ReadCapabilities.LongBlockSize = i; + report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; + break; + } + + if(i == ushort.MaxValue) break; + } + + DicConsole.WriteLine(); + } + } + + if(debug && report.SCSI.ReadCapabilities.SupportsReadLong && + report.SCSI.ReadCapabilities.LongBlockSizeSpecified && + report.SCSI.ReadCapabilities.LongBlockSize != report.SCSI.ReadCapabilities.BlockSize) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, + (ushort)report.SCSI.ReadCapabilities.LongBlockSize, timeout, + out duration); + if(!sense) + DataFile.WriteTo("SCSI Report", "readlong10", + "_debug_" + report.SCSI.Inquiry.ProductIdentification + ".bin", + "read results", buffer); } } - if(debug && report.SCSI.ReadCapabilities.SupportsReadLong && - report.SCSI.ReadCapabilities.LongBlockSizeSpecified && - report.SCSI.ReadCapabilities.LongBlockSize != report.SCSI.ReadCapabilities.BlockSize) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, - (ushort)report.SCSI.ReadCapabilities.LongBlockSize, timeout, - out duration); - if(!sense) - DataFile.WriteTo("SCSI Report", "readlong10", - "_debug_" + report.SCSI.Inquiry.ProductIdentification + ".bin", - "read results", buffer); - } - } + break; } } } diff --git a/DiscImageChef.Core/Devices/Report/SCSI/MMC.cs b/DiscImageChef.Core/Devices/Report/SCSI/MMC.cs index e3866d333..df146b629 100644 --- a/DiscImageChef.Core/Devices/Report/SCSI/MMC.cs +++ b/DiscImageChef.Core/Devices/Report/SCSI/MMC.cs @@ -959,68 +959,67 @@ namespace DiscImageChef.Core.Devices.Report.SCSI mediaType + ".bin", "read results", buffer); } - if(mediaType == "DVD-ROM" || mediaType == "HD DVD-ROM") - { - mediaTest.CanReadBCASpecified = true; - DicConsole.WriteLine("Querying DVD BCA..."); - mediaTest.CanReadBCA = - !dev.ReadDiscStructure(out buffer, out senseBuffer, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.BurstCuttingArea, 0, timeout, - out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.CanReadBCA); - if(debug) - DataFile.WriteTo("SCSI Report", "bca", - "_debug_" + report.SCSI.Inquiry.ProductIdentification + "_" + - mediaType + ".bin", "read results", buffer); - mediaTest.CanReadAACSSpecified = true; - DicConsole.WriteLine("Querying DVD AACS..."); - mediaTest.CanReadAACS = - !dev.ReadDiscStructure(out buffer, out senseBuffer, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.DvdAacs, 0, timeout, out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.CanReadAACS); - if(debug) - DataFile.WriteTo("SCSI Report", "aacs", - "_debug_" + report.SCSI.Inquiry.ProductIdentification + "_" + - mediaType + ".bin", "read results", buffer); - } - - if(mediaType == "BD-ROM") - { - mediaTest.CanReadBCASpecified = true; - DicConsole.WriteLine("Querying BD BCA..."); - mediaTest.CanReadBCA = - !dev.ReadDiscStructure(out buffer, out senseBuffer, MmcDiscStructureMediaType.Bd, 0, 0, - MmcDiscStructureFormat.BdBurstCuttingArea, 0, timeout, - out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.CanReadBCA); - if(debug) - DataFile.WriteTo("SCSI Report", "bdbca", - "_debug_" + report.SCSI.Inquiry.ProductIdentification + "_" + - mediaType + ".bin", "read results", buffer); - } - - if(mediaType == "DVD-RAM" || mediaType == "HD DVD-RAM") - { - mediaTest.CanReadDDSSpecified = true; - mediaTest.CanReadSpareAreaInformationSpecified = true; - mediaTest.CanReadDDS = - !dev.ReadDiscStructure(out buffer, out senseBuffer, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.DvdramDds, 0, timeout, out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.CanReadDDS); - if(debug) - DataFile.WriteTo("SCSI Report", "dds", - "_debug_" + report.SCSI.Inquiry.ProductIdentification + "_" + - mediaType + ".bin", "read results", buffer); - mediaTest.CanReadSpareAreaInformation = - !dev.ReadDiscStructure(out buffer, out senseBuffer, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.DvdramSpareAreaInformation, 0, timeout, - out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", - !mediaTest.CanReadSpareAreaInformation); - if(debug) - DataFile.WriteTo("SCSI Report", "sai", - "_debug_" + report.SCSI.Inquiry.ProductIdentification + "_" + - mediaType + ".bin", "read results", buffer); + switch(mediaType) { + case "DVD-ROM": + case "HD DVD-ROM": + mediaTest.CanReadBCASpecified = true; + DicConsole.WriteLine("Querying DVD BCA..."); + mediaTest.CanReadBCA = + !dev.ReadDiscStructure(out buffer, out senseBuffer, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.BurstCuttingArea, 0, timeout, + out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.CanReadBCA); + if(debug) + DataFile.WriteTo("SCSI Report", "bca", + "_debug_" + report.SCSI.Inquiry.ProductIdentification + "_" + + mediaType + ".bin", "read results", buffer); + mediaTest.CanReadAACSSpecified = true; + DicConsole.WriteLine("Querying DVD AACS..."); + mediaTest.CanReadAACS = + !dev.ReadDiscStructure(out buffer, out senseBuffer, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.DvdAacs, 0, timeout, out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.CanReadAACS); + if(debug) + DataFile.WriteTo("SCSI Report", "aacs", + "_debug_" + report.SCSI.Inquiry.ProductIdentification + "_" + + mediaType + ".bin", "read results", buffer); + break; + case "BD-ROM": + mediaTest.CanReadBCASpecified = true; + DicConsole.WriteLine("Querying BD BCA..."); + mediaTest.CanReadBCA = + !dev.ReadDiscStructure(out buffer, out senseBuffer, MmcDiscStructureMediaType.Bd, 0, 0, + MmcDiscStructureFormat.BdBurstCuttingArea, 0, timeout, + out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.CanReadBCA); + if(debug) + DataFile.WriteTo("SCSI Report", "bdbca", + "_debug_" + report.SCSI.Inquiry.ProductIdentification + "_" + + mediaType + ".bin", "read results", buffer); + break; + case "DVD-RAM": + case "HD DVD-RAM": + mediaTest.CanReadDDSSpecified = true; + mediaTest.CanReadSpareAreaInformationSpecified = true; + mediaTest.CanReadDDS = + !dev.ReadDiscStructure(out buffer, out senseBuffer, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.DvdramDds, 0, timeout, out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.CanReadDDS); + if(debug) + DataFile.WriteTo("SCSI Report", "dds", + "_debug_" + report.SCSI.Inquiry.ProductIdentification + "_" + + mediaType + ".bin", "read results", buffer); + mediaTest.CanReadSpareAreaInformation = + !dev.ReadDiscStructure(out buffer, out senseBuffer, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.DvdramSpareAreaInformation, 0, timeout, + out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", + !mediaTest.CanReadSpareAreaInformation); + if(debug) + DataFile.WriteTo("SCSI Report", "sai", + "_debug_" + report.SCSI.Inquiry.ProductIdentification + "_" + + mediaType + ".bin", "read results", buffer); + break; } if(mediaType.StartsWith("BD-R", StringComparison.Ordinal) && mediaType != "BD-ROM") diff --git a/DiscImageChef.Core/Devices/Report/SecureDigital.cs b/DiscImageChef.Core/Devices/Report/SecureDigital.cs index 183286f4a..eb161aed1 100644 --- a/DiscImageChef.Core/Devices/Report/SecureDigital.cs +++ b/DiscImageChef.Core/Devices/Report/SecureDigital.cs @@ -42,8 +42,12 @@ namespace DiscImageChef.Core.Devices.Report { if(report == null) return; - if(dev.Type == DeviceType.MMC) report.MultiMediaCard = new mmcsdType(); - else if(dev.Type == DeviceType.SecureDigital) report.SecureDigital = new mmcsdType(); + switch(dev.Type) { + case DeviceType.MMC: report.MultiMediaCard = new mmcsdType(); + break; + case DeviceType.SecureDigital: report.SecureDigital = new mmcsdType(); + break; + } DicConsole.WriteLine("Trying to get CID..."); bool sense = dev.ReadCid(out byte[] cid, out uint[] response, dev.Timeout, out double duration); @@ -52,26 +56,26 @@ namespace DiscImageChef.Core.Devices.Report { DicConsole.WriteLine("CID obtained correctly..."); - if(dev.Type == DeviceType.SecureDigital) - { - // Clear serial number and manufacturing date - cid[9] = 0; - cid[10] = 0; - cid[11] = 0; - cid[12] = 0; - cid[13] = 0; - cid[14] = 0; - report.SecureDigital.CID = cid; - } - else if(dev.Type == DeviceType.MMC) - { - // Clear serial number and manufacturing date - cid[10] = 0; - cid[11] = 0; - cid[12] = 0; - cid[13] = 0; - cid[14] = 0; - report.MultiMediaCard.CID = cid; + switch(dev.Type) { + case DeviceType.SecureDigital: + // Clear serial number and manufacturing date + cid[9] = 0; + cid[10] = 0; + cid[11] = 0; + cid[12] = 0; + cid[13] = 0; + cid[14] = 0; + report.SecureDigital.CID = cid; + break; + case DeviceType.MMC: + // Clear serial number and manufacturing date + cid[10] = 0; + cid[11] = 0; + cid[12] = 0; + cid[13] = 0; + cid[14] = 0; + report.MultiMediaCard.CID = cid; + break; } } else DicConsole.WriteLine("Could not read CID..."); @@ -83,54 +87,62 @@ namespace DiscImageChef.Core.Devices.Report { DicConsole.WriteLine("CSD obtained correctly..."); - if(dev.Type == DeviceType.MMC) report.MultiMediaCard.CSD = csd; - else if(dev.Type == DeviceType.SecureDigital) report.SecureDigital.CSD = csd; + switch(dev.Type) { + case DeviceType.MMC: report.MultiMediaCard.CSD = csd; + break; + case DeviceType.SecureDigital: report.SecureDigital.CSD = csd; + break; + } } else DicConsole.WriteLine("Could not read CSD..."); - if(dev.Type == DeviceType.MMC) - { - DicConsole.WriteLine("Trying to get OCR..."); - sense = dev.ReadOcr(out byte[] ocr, out response, dev.Timeout, out duration); - - if(!sense) + switch(dev.Type) { + case DeviceType.MMC: { - DicConsole.WriteLine("OCR obtained correctly..."); - report.MultiMediaCard.OCR = ocr; + DicConsole.WriteLine("Trying to get OCR..."); + sense = dev.ReadOcr(out byte[] ocr, out response, dev.Timeout, out duration); + + if(!sense) + { + DicConsole.WriteLine("OCR obtained correctly..."); + report.MultiMediaCard.OCR = ocr; + } + else DicConsole.WriteLine("Could not read OCR..."); + + DicConsole.WriteLine("Trying to get Extended CSD..."); + sense = dev.ReadExtendedCsd(out byte[] ecsd, out response, dev.Timeout, out duration); + + if(!sense) + { + DicConsole.WriteLine("Extended CSD obtained correctly..."); + report.MultiMediaCard.ExtendedCSD = ecsd; + } + else DicConsole.WriteLine("Could not read Extended CSD..."); + break; } - else DicConsole.WriteLine("Could not read OCR..."); - - DicConsole.WriteLine("Trying to get Extended CSD..."); - sense = dev.ReadExtendedCsd(out byte[] ecsd, out response, dev.Timeout, out duration); - - if(!sense) + case DeviceType.SecureDigital: { - DicConsole.WriteLine("Extended CSD obtained correctly..."); - report.MultiMediaCard.ExtendedCSD = ecsd; - } - else DicConsole.WriteLine("Could not read Extended CSD..."); - } - else if(dev.Type == DeviceType.SecureDigital) - { - DicConsole.WriteLine("Trying to get OCR..."); - sense = dev.ReadSdocr(out byte[] ocr, out response, dev.Timeout, out duration); + DicConsole.WriteLine("Trying to get OCR..."); + sense = dev.ReadSdocr(out byte[] ocr, out response, dev.Timeout, out duration); - if(!sense) - { - DicConsole.WriteLine("OCR obtained correctly..."); - report.SecureDigital.OCR = ocr; - } - else DicConsole.WriteLine("Could not read OCR..."); + if(!sense) + { + DicConsole.WriteLine("OCR obtained correctly..."); + report.SecureDigital.OCR = ocr; + } + else DicConsole.WriteLine("Could not read OCR..."); - DicConsole.WriteLine("Trying to get SCR..."); - sense = dev.ReadScr(out byte[] scr, out response, dev.Timeout, out duration); + DicConsole.WriteLine("Trying to get SCR..."); + sense = dev.ReadScr(out byte[] scr, out response, dev.Timeout, out duration); - if(!sense) - { - DicConsole.WriteLine("SCR obtained correctly..."); - report.SecureDigital.SCR = scr; + if(!sense) + { + DicConsole.WriteLine("SCR obtained correctly..."); + report.SecureDigital.SCR = scr; + } + else DicConsole.WriteLine("Could not read SCR..."); + break; } - else DicConsole.WriteLine("Could not read SCR..."); } } } diff --git a/DiscImageChef.Core/Devices/Scanning/SCSI.cs b/DiscImageChef.Core/Devices/Scanning/SCSI.cs index 893fa909f..754e1503c 100644 --- a/DiscImageChef.Core/Devices/Scanning/SCSI.cs +++ b/DiscImageChef.Core/Devices/Scanning/SCSI.cs @@ -137,38 +137,36 @@ namespace DiscImageChef.Core.Devices.Scanning Reader scsiReader = null; - if(dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.DirectAccess || - dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice || - dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.OCRWDevice || - dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.OpticalDevice || - dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.SimplifiedDevice || - dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.WriteOnceDevice) - { - scsiReader = new Reader(dev, dev.Timeout, null, false); - results.Blocks = scsiReader.GetDeviceBlocks(); - if(scsiReader.FindReadCommand()) - { - DicConsole.ErrorWriteLine("Unable to read medium."); - return results; - } + switch(dev.ScsiType) { + case Decoders.SCSI.PeripheralDeviceTypes.DirectAccess: + case Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice: + case Decoders.SCSI.PeripheralDeviceTypes.OCRWDevice: + case Decoders.SCSI.PeripheralDeviceTypes.OpticalDevice: + case Decoders.SCSI.PeripheralDeviceTypes.SimplifiedDevice: + case Decoders.SCSI.PeripheralDeviceTypes.WriteOnceDevice: + scsiReader = new Reader(dev, dev.Timeout, null, false); + results.Blocks = scsiReader.GetDeviceBlocks(); + if(scsiReader.FindReadCommand()) + { + DicConsole.ErrorWriteLine("Unable to read medium."); + return results; + } - blockSize = scsiReader.LogicalBlockSize; + blockSize = scsiReader.LogicalBlockSize; - if(results.Blocks != 0 && blockSize != 0) - { - results.Blocks++; + if(results.Blocks != 0 && blockSize != 0) + { + results.Blocks++; #pragma warning disable IDE0004 // Without this specific cast, it gives incorrect values - DicConsole.WriteLine("Media has {0} blocks of {1} bytes/each. (for a total of {2} bytes)", - results.Blocks, blockSize, results.Blocks * (ulong)blockSize); + DicConsole.WriteLine("Media has {0} blocks of {1} bytes/each. (for a total of {2} bytes)", + results.Blocks, blockSize, results.Blocks * (ulong)blockSize); #pragma warning restore IDE0004 // Without this specific cast, it gives incorrect values - } - } - - if(dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess) - { - DicConsole.WriteLine("Scanning will never be supported on SCSI Streaming Devices."); - DicConsole.WriteLine("It has no sense to do it, and it will put too much strain on the tape."); - return results; + } + break; + case Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess: + DicConsole.WriteLine("Scanning will never be supported on SCSI Streaming Devices."); + DicConsole.WriteLine("It has no sense to do it, and it will put too much strain on the tape."); + return results; } if(results.Blocks == 0) diff --git a/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs b/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs index 9b5b69ccf..90fce5009 100644 --- a/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs +++ b/DiscImageChef.Core/Devices/Scanning/SecureDigital.cs @@ -58,47 +58,51 @@ namespace DiscImageChef.Core.Devices.Scanning uint blockSize = 512; bool byteAddressed = true; - if(dev.Type == DeviceType.MMC) - { - ExtendedCSD ecsd = new ExtendedCSD(); - CSD csd = new CSD(); - - sense = dev.ReadExtendedCsd(out cmdBuf, out response, timeout, out duration); - if(!sense) + switch(dev.Type) { + case DeviceType.MMC: { - ecsd = Decoders.MMC.Decoders.DecodeExtendedCSD(cmdBuf); - blocksToRead = ecsd.OptimalReadSize; - results.Blocks = ecsd.SectorCount; - blockSize = (uint)(ecsd.SectorSize == 1 ? 4096 : 512); - // Supposing it's high-capacity MMC if it has Extended CSD... - byteAddressed = false; + ExtendedCSD ecsd = new ExtendedCSD(); + CSD csd = new CSD(); + + sense = dev.ReadExtendedCsd(out cmdBuf, out response, timeout, out duration); + if(!sense) + { + ecsd = Decoders.MMC.Decoders.DecodeExtendedCSD(cmdBuf); + blocksToRead = ecsd.OptimalReadSize; + results.Blocks = ecsd.SectorCount; + blockSize = (uint)(ecsd.SectorSize == 1 ? 4096 : 512); + // Supposing it's high-capacity MMC if it has Extended CSD... + byteAddressed = false; + } + + if(sense || results.Blocks == 0) + { + sense = dev.ReadCsd(out cmdBuf, out response, timeout, out duration); + if(!sense) + { + csd = Decoders.MMC.Decoders.DecodeCSD(cmdBuf); + results.Blocks = (ulong)((csd.Size + 1) * Math.Pow(2, csd.SizeMultiplier + 2)); + blockSize = (uint)Math.Pow(2, csd.ReadBlockLength); + } + } + break; } - - if(sense || results.Blocks == 0) + case DeviceType.SecureDigital: { + Decoders.SecureDigital.CSD csd = new Decoders.SecureDigital.CSD(); + sense = dev.ReadCsd(out cmdBuf, out response, timeout, out duration); if(!sense) { - csd = Decoders.MMC.Decoders.DecodeCSD(cmdBuf); - results.Blocks = (ulong)((csd.Size + 1) * Math.Pow(2, csd.SizeMultiplier + 2)); + csd = Decoders.SecureDigital.Decoders.DecodeCSD(cmdBuf); + results.Blocks = (ulong)(csd.Structure == 0 + ? (csd.Size + 1) * Math.Pow(2, csd.SizeMultiplier + 2) + : (csd.Size + 1) * 1024); blockSize = (uint)Math.Pow(2, csd.ReadBlockLength); + // Structure >=1 for SDHC/SDXC, so that's block addressed + byteAddressed = csd.Structure == 0; } - } - } - else if(dev.Type == DeviceType.SecureDigital) - { - Decoders.SecureDigital.CSD csd = new Decoders.SecureDigital.CSD(); - - sense = dev.ReadCsd(out cmdBuf, out response, timeout, out duration); - if(!sense) - { - csd = Decoders.SecureDigital.Decoders.DecodeCSD(cmdBuf); - results.Blocks = (ulong)(csd.Structure == 0 - ? (csd.Size + 1) * Math.Pow(2, csd.SizeMultiplier + 2) - : (csd.Size + 1) * 1024); - blockSize = (uint)Math.Pow(2, csd.ReadBlockLength); - // Structure >=1 for SDHC/SDXC, so that's block addressed - byteAddressed = csd.Structure == 0; + break; } } diff --git a/DiscImageChef.Core/Sidecar/BlockMedia.cs b/DiscImageChef.Core/Sidecar/BlockMedia.cs index 2fe15f767..f1a26dbc9 100644 --- a/DiscImageChef.Core/Sidecar/BlockMedia.cs +++ b/DiscImageChef.Core/Sidecar/BlockMedia.cs @@ -112,31 +112,31 @@ namespace DiscImageChef.Core Tuple[] tuples = CIS.GetTuples(cis); if(tuples != null) foreach(Tuple tuple in tuples) - if(tuple.Code == TupleCodes.CISTPL_MANFID) - { - ManufacturerIdentificationTuple manfid = - CIS.DecodeManufacturerIdentificationTuple(tuple); + switch(tuple.Code) { + case TupleCodes.CISTPL_MANFID: + ManufacturerIdentificationTuple manfid = + CIS.DecodeManufacturerIdentificationTuple(tuple); - if(manfid != null) - { - sidecar.BlockMedia[0].PCMCIA.ManufacturerCode = manfid.ManufacturerID; - sidecar.BlockMedia[0].PCMCIA.CardCode = manfid.CardID; - sidecar.BlockMedia[0].PCMCIA.ManufacturerCodeSpecified = true; - sidecar.BlockMedia[0].PCMCIA.CardCodeSpecified = true; - } - } - else if(tuple.Code == TupleCodes.CISTPL_VERS_1) - { - Level1VersionTuple vers = CIS.DecodeLevel1VersionTuple(tuple); + if(manfid != null) + { + sidecar.BlockMedia[0].PCMCIA.ManufacturerCode = manfid.ManufacturerID; + sidecar.BlockMedia[0].PCMCIA.CardCode = manfid.CardID; + sidecar.BlockMedia[0].PCMCIA.ManufacturerCodeSpecified = true; + sidecar.BlockMedia[0].PCMCIA.CardCodeSpecified = true; + } + break; + case TupleCodes.CISTPL_VERS_1: + Level1VersionTuple vers = CIS.DecodeLevel1VersionTuple(tuple); - if(vers != null) - { - sidecar.BlockMedia[0].PCMCIA.Manufacturer = vers.Manufacturer; - sidecar.BlockMedia[0].PCMCIA.ProductName = vers.Product; - sidecar.BlockMedia[0].PCMCIA.Compliance = - string.Format("{0}.{1}", vers.MajorVersion, vers.MinorVersion); - sidecar.BlockMedia[0].PCMCIA.AdditionalInformation = vers.AdditionalInformation; - } + if(vers != null) + { + sidecar.BlockMedia[0].PCMCIA.Manufacturer = vers.Manufacturer; + sidecar.BlockMedia[0].PCMCIA.ProductName = vers.Product; + sidecar.BlockMedia[0].PCMCIA.Compliance = + string.Format("{0}.{1}", vers.MajorVersion, vers.MinorVersion); + sidecar.BlockMedia[0].PCMCIA.AdditionalInformation = vers.AdditionalInformation; + } + break; } break; diff --git a/DiscImageChef.Core/Sidecar/OpticalDisc.cs b/DiscImageChef.Core/Sidecar/OpticalDisc.cs index 11b7b1076..8940cb2ba 100644 --- a/DiscImageChef.Core/Sidecar/OpticalDisc.cs +++ b/DiscImageChef.Core/Sidecar/OpticalDisc.cs @@ -208,10 +208,12 @@ namespace DiscImageChef.Core sidecar.OpticalDisc[0].Dimensions = new DimensionsType(); if(dskType == MediaType.UMD) sidecar.OpticalDisc[0].Dimensions.Diameter = 60; - else if(pfi.Value.DiscSize == Decoders.DVD.DVDSize.Eighty) - sidecar.OpticalDisc[0].Dimensions.Diameter = 80; - else if(pfi.Value.DiscSize == Decoders.DVD.DVDSize.OneTwenty) - sidecar.OpticalDisc[0].Dimensions.Diameter = 120; + else switch(pfi.Value.DiscSize) { + case Decoders.DVD.DVDSize.Eighty: sidecar.OpticalDisc[0].Dimensions.Diameter = 80; + break; + case Decoders.DVD.DVDSize.OneTwenty: sidecar.OpticalDisc[0].Dimensions.Diameter = 120; + break; + } } break; @@ -291,15 +293,16 @@ namespace DiscImageChef.Core if(trk.Indexes != null && trk.Indexes.ContainsKey(0)) if(trk.Indexes.TryGetValue(0, out ulong idx0)) xmlTrk.StartSector = (long)idx0; - if(sidecar.OpticalDisc[0].DiscType == "CD" || sidecar.OpticalDisc[0].DiscType == "GD") - { - xmlTrk.StartMSF = LbaToMsf(xmlTrk.StartSector); - xmlTrk.EndMSF = LbaToMsf(xmlTrk.EndSector); - } - else if(sidecar.OpticalDisc[0].DiscType == "DDCD") - { - xmlTrk.StartMSF = DdcdLbaToMsf(xmlTrk.StartSector); - xmlTrk.EndMSF = DdcdLbaToMsf(xmlTrk.EndSector); + switch(sidecar.OpticalDisc[0].DiscType) { + case "CD": + case "GD": + xmlTrk.StartMSF = LbaToMsf(xmlTrk.StartSector); + xmlTrk.EndMSF = LbaToMsf(xmlTrk.EndSector); + break; + case "DDCD": + xmlTrk.StartMSF = DdcdLbaToMsf(xmlTrk.StartSector); + xmlTrk.EndMSF = DdcdLbaToMsf(xmlTrk.EndSector); + break; } xmlTrk.Image = new ImageType {Value = Path.GetFileName(trk.TrackFile), format = trk.TrackFileType}; @@ -468,12 +471,16 @@ namespace DiscImageChef.Core lstFs.Add(plugin.XmlFSType); Statistics.AddFilesystem(plugin.XmlFSType.Type); - if(plugin.XmlFSType.Type == "Opera") dskType = MediaType.ThreeDO; - if(plugin.XmlFSType.Type == "PC Engine filesystem") - dskType = MediaType.SuperCDROM2; - if(plugin.XmlFSType.Type == "Nintendo Wii filesystem") dskType = MediaType.WOD; - if(plugin.XmlFSType.Type == "Nintendo Gamecube filesystem") - dskType = MediaType.GOD; + switch(plugin.XmlFSType.Type) { + case "Opera": dskType = MediaType.ThreeDO; + break; + case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; + break; + case "Nintendo Wii filesystem": dskType = MediaType.WOD; + break; + case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; + break; + } } } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body @@ -512,10 +519,16 @@ namespace DiscImageChef.Core lstFs.Add(plugin.XmlFSType); Statistics.AddFilesystem(plugin.XmlFSType.Type); - if(plugin.XmlFSType.Type == "Opera") dskType = MediaType.ThreeDO; - if(plugin.XmlFSType.Type == "PC Engine filesystem") dskType = MediaType.SuperCDROM2; - if(plugin.XmlFSType.Type == "Nintendo Wii filesystem") dskType = MediaType.WOD; - if(plugin.XmlFSType.Type == "Nintendo Gamecube filesystem") dskType = MediaType.GOD; + switch(plugin.XmlFSType.Type) { + case "Opera": dskType = MediaType.ThreeDO; + break; + case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; + break; + case "Nintendo Wii filesystem": dskType = MediaType.WOD; + break; + case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; + break; + } } } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body diff --git a/DiscImageChef.Decoders/CD/ATIP.cs b/DiscImageChef.Decoders/CD/ATIP.cs index c8b13628c..816856b05 100644 --- a/DiscImageChef.Decoders/CD/ATIP.cs +++ b/DiscImageChef.Decoders/CD/ATIP.cs @@ -457,15 +457,19 @@ namespace DiscImageChef.Decoders.CD switch(sec) { case 15: - if(frm == 00) return "TDK Corporation"; - if(frm == 10) return "Ritek Co."; - if(frm == 20) return "Mitsubishi Chemical Corporation"; - if(frm == 30) return "NAN-YA Plastics Corporation"; + switch(frm) { + case 00: return "TDK Corporation"; + case 10: return "Ritek Co."; + case 20: return "Mitsubishi Chemical Corporation"; + case 30: return "NAN-YA Plastics Corporation"; + } break; case 16: - if(frm == 20) return "Shenzen SG&Gast Digital Optical Discs"; - if(frm == 30) return "Grand Advance Technology Ltd."; + switch(frm) { + case 20: return "Shenzen SG&Gast Digital Optical Discs"; + case 30: return "Grand Advance Technology Ltd."; + } break; case 17: @@ -473,8 +477,10 @@ namespace DiscImageChef.Decoders.CD break; case 18: - if(frm == 10) return "Wealth Fair Investment Ltd."; - if(frm == 60) return "Taroko International Co. Ltd."; + switch(frm) { + case 10: return "Wealth Fair Investment Ltd."; + case 60: return "Taroko International Co. Ltd."; + } break; case 20: @@ -482,88 +488,106 @@ namespace DiscImageChef.Decoders.CD break; case 21: - if(frm == 10) return "Grupo Condor S.L."; - if(frm == 30) return "Bestdisc Technology Corporation"; - if(frm == 40) return "Optical Disc Manufacturing Equipment"; - if(frm == 50) return "Sound Sound Multi-Media Development Ltd."; + switch(frm) { + case 10: return "Grupo Condor S.L."; + case 30: return "Bestdisc Technology Corporation"; + case 40: return "Optical Disc Manufacturing Equipment"; + case 50: return "Sound Sound Multi-Media Development Ltd."; + } break; case 22: - if(frm == 00) return "Woongjin Media Corp."; - if(frm == 10) return "Seantram Technology Inc."; - if(frm == 20) return "Advanced Digital Media"; - if(frm == 30) return "EXIMPO"; - if(frm == 40) return "CIS Technology Inc."; - if(frm == 50) return "Hong Kong Digital Technology Co., Ltd."; - if(frm == 60) return "Acer Media Technology, Inc."; + switch(frm) { + case 00: return "Woongjin Media Corp."; + case 10: return "Seantram Technology Inc."; + case 20: return "Advanced Digital Media"; + case 30: return "EXIMPO"; + case 40: return "CIS Technology Inc."; + case 50: return "Hong Kong Digital Technology Co., Ltd."; + case 60: return "Acer Media Technology, Inc."; + } break; case 23: - if(frm == 00) return "Matsushita Electric Industrial Co., Ltd."; - if(frm == 10) return "Doremi Media Co., Ltd."; - if(frm == 20) return "Nacar Media s.r.l."; - if(frm == 30) return "Audio Distributors Co., Ltd."; - if(frm == 40) return "Victor Company of Japan, Ltd."; - if(frm == 50) return "Optrom Inc."; - if(frm == 60) return "Customer Pressing Oosterhout"; + switch(frm) { + case 00: return "Matsushita Electric Industrial Co., Ltd."; + case 10: return "Doremi Media Co., Ltd."; + case 20: return "Nacar Media s.r.l."; + case 30: return "Audio Distributors Co., Ltd."; + case 40: return "Victor Company of Japan, Ltd."; + case 50: return "Optrom Inc."; + case 60: return "Customer Pressing Oosterhout"; + } break; case 24: - if(frm == 00) return "Taiyo Yuden Company Ltd."; - if(frm == 10) return "SONY Corporation"; - if(frm == 20) return "Computer Support Italy s.r.l."; - if(frm == 30) return "Unitech Japan Inc."; - if(frm == 40) return "kdg mediatech AG"; - if(frm == 50) return "Guann Yinn Co., Ltd."; - if(frm == 60) return "Harmonic Hall Optical Disc Ltd."; + switch(frm) { + case 00: return "Taiyo Yuden Company Ltd."; + case 10: return "SONY Corporation"; + case 20: return "Computer Support Italy s.r.l."; + case 30: return "Unitech Japan Inc."; + case 40: return "kdg mediatech AG"; + case 50: return "Guann Yinn Co., Ltd."; + case 60: return "Harmonic Hall Optical Disc Ltd."; + } break; case 25: - if(frm == 00) return "MPO"; - if(frm == 20) return "Hitachi Maxell, Ltd."; - if(frm == 30) return "Infodisc Technology Co. Ltd."; - if(frm == 40) return "Vivastar AG"; - if(frm == 50) return "AMS Technology Inc."; - if(frm == 60) return "Xcitec Inc."; + switch(frm) { + case 00: return "MPO"; + case 20: return "Hitachi Maxell, Ltd."; + case 30: return "Infodisc Technology Co. Ltd."; + case 40: return "Vivastar AG"; + case 50: return "AMS Technology Inc."; + case 60: return "Xcitec Inc."; + } break; case 26: - if(frm == 00) return "Fornet International Pte Ltd."; - if(frm == 10) return "POSTECH Corporation"; - if(frm == 20) return "SKC Co., Ltd."; - if(frm == 30) return "Optical Disc Corporation"; - if(frm == 40) return "FUJI Photo Film Co., Ltd."; - if(frm == 50) return "Lead Data Inc."; - if(frm == 60) return "CMC Magnetics Corporation"; + switch(frm) { + case 00: return "Fornet International Pte Ltd."; + case 10: return "POSTECH Corporation"; + case 20: return "SKC Co., Ltd."; + case 30: return "Optical Disc Corporation"; + case 40: return "FUJI Photo Film Co., Ltd."; + case 50: return "Lead Data Inc."; + case 60: return "CMC Magnetics Corporation"; + } break; case 27: - if(frm == 00) return "Digital Storage Technology Co., Ltd."; - if(frm == 10) return "Plasmon Data systems Ltd."; - if(frm == 20) return "Princo Corporation"; - if(frm == 30) return "Pioneer Video Corporation"; - if(frm == 40) return "Kodak Japan Ltd."; - if(frm == 50) return "Mitsui Chemicals, Inc."; - if(frm == 60) return "Ricoh Company Ltd."; + switch(frm) { + case 00: return "Digital Storage Technology Co., Ltd."; + case 10: return "Plasmon Data systems Ltd."; + case 20: return "Princo Corporation"; + case 30: return "Pioneer Video Corporation"; + case 40: return "Kodak Japan Ltd."; + case 50: return "Mitsui Chemicals, Inc."; + case 60: return "Ricoh Company Ltd."; + } break; case 28: - if(frm == 00) return "Opti.Me.S. S.p.A."; - if(frm == 10) return "Gigastore Corporation"; - if(frm == 20) return "Multi Media Masters & Machinary SA"; - if(frm == 30) return "Auvistar Industry Co., Ltd."; - if(frm == 40) return "King Pro Mediatek Inc."; - if(frm == 50) return "Delphi Technology Inc."; - if(frm == 60) return "Friendly CD-Tek Co."; + switch(frm) { + case 00: return "Opti.Me.S. S.p.A."; + case 10: return "Gigastore Corporation"; + case 20: return "Multi Media Masters & Machinary SA"; + case 30: return "Auvistar Industry Co., Ltd."; + case 40: return "King Pro Mediatek Inc."; + case 50: return "Delphi Technology Inc."; + case 60: return "Friendly CD-Tek Co."; + } break; case 29: - if(frm == 00) return "Taeil Media Co., Ltd."; - if(frm == 10) return "Vanguard Disc Inc."; - if(frm == 20) return "Unidisc Technology Co., Ltd."; - if(frm == 30) return "Hile Optical Disc Technology Corp."; - if(frm == 40) return "Viva Magnetics Ltd."; - if(frm == 50) return "General Magnetics Ltd."; + switch(frm) { + case 00: return "Taeil Media Co., Ltd."; + case 10: return "Vanguard Disc Inc."; + case 20: return "Unidisc Technology Co., Ltd."; + case 30: return "Hile Optical Disc Technology Corp."; + case 40: return "Viva Magnetics Ltd."; + case 50: return "General Magnetics Ltd."; + } break; case 30: @@ -571,13 +595,17 @@ namespace DiscImageChef.Decoders.CD break; case 31: - if(frm == 00) return "Ritek Co."; - if(frm == 30) return "Grand Advance Technology Ltd."; + switch(frm) { + case 00: return "Ritek Co."; + case 30: return "Grand Advance Technology Ltd."; + } break; case 32: - if(frm == 00) return "TDK Corporation"; - if(frm == 10) return "Prodisc Technology Inc."; + switch(frm) { + case 00: return "TDK Corporation"; + case 10: return "Prodisc Technology Inc."; + } break; case 34: @@ -589,61 +617,75 @@ namespace DiscImageChef.Decoders.CD break; case 45: - if(frm == 00) return "Fornet International Pte Ltd."; - if(frm == 10) return "Unitech Japan Inc."; - if(frm == 20) return "Acer Media Technology, Inc."; - if(frm == 40) return "CIS Technology Inc."; - if(frm == 50) return "Guann Yinn Co., Ltd."; - if(frm == 60) return "Xcitec Inc."; + switch(frm) { + case 00: return "Fornet International Pte Ltd."; + case 10: return "Unitech Japan Inc."; + case 20: return "Acer Media Technology, Inc."; + case 40: return "CIS Technology Inc."; + case 50: return "Guann Yinn Co., Ltd."; + case 60: return "Xcitec Inc."; + } break; case 46: - if(frm == 00) return "Taiyo Yuden Company Ltd."; - if(frm == 10) return "Hong Kong Digital Technology Co., Ltd."; - if(frm == 20) return "Multi Media Masters & Machinary SA"; - if(frm == 30) return "Computer Support Italy s.r.l."; - if(frm == 40) return "FUJI Photo Film Co., Ltd."; - if(frm == 50) return "Auvistar Industry Co., Ltd."; - if(frm == 60) return "CMC Magnetics Corporation"; + switch(frm) { + case 00: return "Taiyo Yuden Company Ltd."; + case 10: return "Hong Kong Digital Technology Co., Ltd."; + case 20: return "Multi Media Masters & Machinary SA"; + case 30: return "Computer Support Italy s.r.l."; + case 40: return "FUJI Photo Film Co., Ltd."; + case 50: return "Auvistar Industry Co., Ltd."; + case 60: return "CMC Magnetics Corporation"; + } break; case 47: - if(frm == 10) return "Hitachi Maxell, Ltd."; - if(frm == 20) return "Princo Corporation"; - if(frm == 40) return "POSTECH Corporation"; - if(frm == 50) return "Ritek Co."; - if(frm == 60) return "Prodisc Technology Inc."; + switch(frm) { + case 10: return "Hitachi Maxell, Ltd."; + case 20: return "Princo Corporation"; + case 40: return "POSTECH Corporation"; + case 50: return "Ritek Co."; + case 60: return "Prodisc Technology Inc."; + } break; case 48: - if(frm == 00) return "Ricoh Company Ltd."; - if(frm == 10) return "Kodak Japan Ltd."; - if(frm == 20) return "Plasmon Data systems Ltd."; - if(frm == 30) return "Pioneer Video Corporation"; - if(frm == 40) return "Digital Storage Technology Co., Ltd."; - if(frm == 50) return "Mitsui Chemicals, Inc."; - if(frm == 60) return "Lead Data Inc."; + switch(frm) { + case 00: return "Ricoh Company Ltd."; + case 10: return "Kodak Japan Ltd."; + case 20: return "Plasmon Data systems Ltd."; + case 30: return "Pioneer Video Corporation"; + case 40: return "Digital Storage Technology Co., Ltd."; + case 50: return "Mitsui Chemicals, Inc."; + case 60: return "Lead Data Inc."; + } break; case 49: - if(frm == 00) return "TDK Corporation"; - if(frm == 10) return "Gigastore Corporation"; - if(frm == 20) return "King Pro Mediatek Inc."; - if(frm == 30) return "Opti.Me.S. S.p.A."; - if(frm == 40) return "Victor Company of Japan, Ltd."; - if(frm == 60) return "Matsushita Electric Industrial Co., Ltd."; + switch(frm) { + case 00: return "TDK Corporation"; + case 10: return "Gigastore Corporation"; + case 20: return "King Pro Mediatek Inc."; + case 30: return "Opti.Me.S. S.p.A."; + case 40: return "Victor Company of Japan, Ltd."; + case 60: return "Matsushita Electric Industrial Co., Ltd."; + } break; case 50: - if(frm == 10) return "Vanguard Disc Inc."; - if(frm == 20) return "Mitsubishi Chemical Corporation"; - if(frm == 30) return "CDA Datenträger Albrechts GmbH"; + switch(frm) { + case 10: return "Vanguard Disc Inc."; + case 20: return "Mitsubishi Chemical Corporation"; + case 30: return "CDA Datenträger Albrechts GmbH"; + } break; case 51: - if(frm == 10) return "Grand Advance Technology Ltd."; - if(frm == 20) return "Infodisc Technology Co. Ltd."; - if(frm == 50) return "Hile Optical Disc Technology Corp."; + switch(frm) { + case 10: return "Grand Advance Technology Ltd."; + case 20: return "Infodisc Technology Co. Ltd."; + case 50: return "Hile Optical Disc Technology Corp."; + } break; } diff --git a/DiscImageChef.Decoders/DVD/PFI.cs b/DiscImageChef.Decoders/DVD/PFI.cs index 934230ddd..9db739efa 100644 --- a/DiscImageChef.Decoders/DVD/PFI.cs +++ b/DiscImageChef.Decoders/DVD/PFI.cs @@ -1078,138 +1078,135 @@ namespace DiscImageChef.Decoders.DVD pfi.Layer0EndPSN = (uint)((response[16] << 24) + (response[17] << 16) + (response[18] << 8) + response[19]); pfi.BCA |= (response[20] & 0x80) == 0x80; - // UMD - if(pfi.DiskCategory == DiskCategory.UMD) pfi.MediaAttribute = (ushort)((response[21] << 8) + response[22]); + switch(pfi.DiskCategory) { + // UMD + case DiskCategory.UMD: pfi.MediaAttribute = (ushort)((response[21] << 8) + response[22]); + break; + // DVD-RAM + case DiskCategory.DVDRAM: + pfi.DiscType = (DVDRAMDiscType)response[36]; - // DVD-RAM - if(pfi.DiskCategory == DiskCategory.DVDRAM) - { - pfi.DiscType = (DVDRAMDiscType)response[36]; - - if(pfi.PartVersion == 1) - { - pfi.Velocity = response[52]; - pfi.ReadPower = response[53]; - pfi.PeakPower = response[54]; - pfi.BiasPower = response[55]; - pfi.FirstPulseStart = response[56]; - pfi.FirstPulseEnd = response[57]; - pfi.MultiPulseDuration = response[58]; - pfi.LastPulseStart = response[59]; - pfi.LastPulseEnd = response[60]; - pfi.BiasPowerDuration = response[61]; - pfi.PeakPowerGroove = response[62]; - pfi.BiasPowerGroove = response[63]; - pfi.FirstPulseStartGroove = response[64]; - pfi.FirstPulseEndGroove = response[65]; - pfi.MultiplePulseDurationGroove = response[66]; - pfi.LastPulseStartGroove = response[67]; - pfi.LastPulseEndGroove = response[68]; - pfi.BiasPowerDurationGroove = response[69]; - } - else if(pfi.PartVersion == 6) - { - pfi.Velocity = response[504]; - pfi.ReadPower = response[505]; - pfi.AdaptativeWritePulseControlFlag |= (response[506] & 0x80) == 0x80; - pfi.PeakPower = response[507]; - pfi.BiasPower1 = response[508]; - pfi.BiasPower2 = response[509]; - pfi.BiasPower3 = response[510]; - pfi.PeakPowerGroove = response[511]; - pfi.BiasPower1Groove = response[512]; - pfi.BiasPower2Groove = response[513]; - pfi.BiasPower3Groove = response[514]; - pfi.FirstPulseEnd = response[515]; - pfi.FirstPulseDuration = response[516]; - pfi.MultiPulseDuration = response[518]; - pfi.LastPulseStart = response[519]; - pfi.BiasPower2Duration = response[520]; - pfi.FirstPulseStart3TSpace3T = response[521]; - pfi.FirstPulseStart4TSpace3T = response[522]; - pfi.FirstPulseStart5TSpace3T = response[523]; - pfi.FirstPulseStartSpace3T = response[524]; - pfi.FirstPulseStart3TSpace4T = response[525]; - pfi.FirstPulseStart4TSpace4T = response[526]; - pfi.FirstPulseStart5TSpace4T = response[527]; - pfi.FirstPulseStartSpace4T = response[528]; - pfi.FirstPulseStart3TSpace5T = response[529]; - pfi.FirstPulseStart4TSpace5T = response[530]; - pfi.FirstPulseStart5TSpace5T = response[531]; - pfi.FirstPulseStartSpace5T = response[532]; - pfi.FirstPulseStart3TSpace = response[533]; - pfi.FirstPulseStart4TSpace = response[534]; - pfi.FirstPulseStart5TSpace = response[535]; - pfi.FirstPulseStartSpace = response[536]; - pfi.FirstPulse3TStartTSpace3T = response[537]; - pfi.FirstPulse4TStartTSpace3T = response[538]; - pfi.FirstPulse5TStartTSpace3T = response[539]; - pfi.FirstPulseStartTSpace3T = response[540]; - pfi.FirstPulse3TStartTSpace4T = response[541]; - pfi.FirstPulse4TStartTSpace4T = response[542]; - pfi.FirstPulse5TStartTSpace4T = response[543]; - pfi.FirstPulseStartTSpace4T = response[544]; - pfi.FirstPulse3TStartTSpace5T = response[545]; - pfi.FirstPulse4TStartTSpace5T = response[546]; - pfi.FirstPulse5TStartTSpace5T = response[547]; - pfi.FirstPulseStartTSpace5T = response[548]; - pfi.FirstPulse3TStartTSpace = response[549]; - pfi.FirstPulse4TStartTSpace = response[550]; - pfi.FirstPulse5TStartTSpace = response[551]; - pfi.FirstPulseStartTSpace = response[552]; - tmp = new byte[48]; - Array.Copy(response, 553, tmp, 0, 48); - pfi.DiskManufacturer = StringHandlers.SpacePaddedToString(tmp); - tmp = new byte[16]; - Array.Copy(response, 601, tmp, 0, 16); - pfi.DiskManufacturerSupplementary = StringHandlers.SpacePaddedToString(tmp); - pfi.WritePowerControlParams = new byte[2]; - pfi.WritePowerControlParams[0] = response[617]; - pfi.WritePowerControlParams[1] = response[618]; - pfi.PowerRatioLandThreshold = response[619]; - pfi.TargetAsymmetry = response[620]; - pfi.TemporaryPeakPower = response[621]; - pfi.TemporaryBiasPower1 = response[622]; - pfi.TemporaryBiasPower2 = response[623]; - pfi.TemporaryBiasPower3 = response[624]; - pfi.PowerRatioGrooveThreshold = response[625]; - pfi.PowerRatioLandThreshold6T = response[626]; - pfi.PowerRatioGrooveThreshold6T = response[627]; - } - } - - // DVD-R and DVD-RW - if(pfi.DiskCategory == DiskCategory.DVDR && pfi.PartVersion < 6 || - pfi.DiskCategory == DiskCategory.DVDRW && pfi.PartVersion < 3) - { - pfi.CurrentBorderOutSector = - (uint)((response[36] << 24) + (response[37] << 16) + (response[38] << 8) + response[39]); - pfi.NextBorderInSector = - (uint)((response[40] << 24) + (response[41] << 16) + (response[42] << 8) + response[43]); - } - - // DVD+RW - if(pfi.DiskCategory == DiskCategory.DVDPRW) - { - pfi.RecordingVelocity = response[36]; - pfi.ReadPowerMaxVelocity = response[37]; - pfi.PIndMaxVelocity = response[38]; - pfi.PMaxVelocity = response[39]; - pfi.E1MaxVelocity = response[40]; - pfi.E2MaxVelocity = response[41]; - pfi.YTargetMaxVelocity = response[42]; - pfi.ReadPowerRefVelocity = response[43]; - pfi.PIndRefVelocity = response[44]; - pfi.PRefVelocity = response[45]; - pfi.E1RefVelocity = response[46]; - pfi.E2RefVelocity = response[47]; - pfi.YTargetRefVelocity = response[48]; - pfi.ReadPowerMinVelocity = response[49]; - pfi.PIndMinVelocity = response[50]; - pfi.PMinVelocity = response[51]; - pfi.E1MinVelocity = response[52]; - pfi.E2MinVelocity = response[53]; - pfi.YTargetMinVelocity = response[54]; + if(pfi.PartVersion == 1) + { + pfi.Velocity = response[52]; + pfi.ReadPower = response[53]; + pfi.PeakPower = response[54]; + pfi.BiasPower = response[55]; + pfi.FirstPulseStart = response[56]; + pfi.FirstPulseEnd = response[57]; + pfi.MultiPulseDuration = response[58]; + pfi.LastPulseStart = response[59]; + pfi.LastPulseEnd = response[60]; + pfi.BiasPowerDuration = response[61]; + pfi.PeakPowerGroove = response[62]; + pfi.BiasPowerGroove = response[63]; + pfi.FirstPulseStartGroove = response[64]; + pfi.FirstPulseEndGroove = response[65]; + pfi.MultiplePulseDurationGroove = response[66]; + pfi.LastPulseStartGroove = response[67]; + pfi.LastPulseEndGroove = response[68]; + pfi.BiasPowerDurationGroove = response[69]; + } + else if(pfi.PartVersion == 6) + { + pfi.Velocity = response[504]; + pfi.ReadPower = response[505]; + pfi.AdaptativeWritePulseControlFlag |= (response[506] & 0x80) == 0x80; + pfi.PeakPower = response[507]; + pfi.BiasPower1 = response[508]; + pfi.BiasPower2 = response[509]; + pfi.BiasPower3 = response[510]; + pfi.PeakPowerGroove = response[511]; + pfi.BiasPower1Groove = response[512]; + pfi.BiasPower2Groove = response[513]; + pfi.BiasPower3Groove = response[514]; + pfi.FirstPulseEnd = response[515]; + pfi.FirstPulseDuration = response[516]; + pfi.MultiPulseDuration = response[518]; + pfi.LastPulseStart = response[519]; + pfi.BiasPower2Duration = response[520]; + pfi.FirstPulseStart3TSpace3T = response[521]; + pfi.FirstPulseStart4TSpace3T = response[522]; + pfi.FirstPulseStart5TSpace3T = response[523]; + pfi.FirstPulseStartSpace3T = response[524]; + pfi.FirstPulseStart3TSpace4T = response[525]; + pfi.FirstPulseStart4TSpace4T = response[526]; + pfi.FirstPulseStart5TSpace4T = response[527]; + pfi.FirstPulseStartSpace4T = response[528]; + pfi.FirstPulseStart3TSpace5T = response[529]; + pfi.FirstPulseStart4TSpace5T = response[530]; + pfi.FirstPulseStart5TSpace5T = response[531]; + pfi.FirstPulseStartSpace5T = response[532]; + pfi.FirstPulseStart3TSpace = response[533]; + pfi.FirstPulseStart4TSpace = response[534]; + pfi.FirstPulseStart5TSpace = response[535]; + pfi.FirstPulseStartSpace = response[536]; + pfi.FirstPulse3TStartTSpace3T = response[537]; + pfi.FirstPulse4TStartTSpace3T = response[538]; + pfi.FirstPulse5TStartTSpace3T = response[539]; + pfi.FirstPulseStartTSpace3T = response[540]; + pfi.FirstPulse3TStartTSpace4T = response[541]; + pfi.FirstPulse4TStartTSpace4T = response[542]; + pfi.FirstPulse5TStartTSpace4T = response[543]; + pfi.FirstPulseStartTSpace4T = response[544]; + pfi.FirstPulse3TStartTSpace5T = response[545]; + pfi.FirstPulse4TStartTSpace5T = response[546]; + pfi.FirstPulse5TStartTSpace5T = response[547]; + pfi.FirstPulseStartTSpace5T = response[548]; + pfi.FirstPulse3TStartTSpace = response[549]; + pfi.FirstPulse4TStartTSpace = response[550]; + pfi.FirstPulse5TStartTSpace = response[551]; + pfi.FirstPulseStartTSpace = response[552]; + tmp = new byte[48]; + Array.Copy(response, 553, tmp, 0, 48); + pfi.DiskManufacturer = StringHandlers.SpacePaddedToString(tmp); + tmp = new byte[16]; + Array.Copy(response, 601, tmp, 0, 16); + pfi.DiskManufacturerSupplementary = StringHandlers.SpacePaddedToString(tmp); + pfi.WritePowerControlParams = new byte[2]; + pfi.WritePowerControlParams[0] = response[617]; + pfi.WritePowerControlParams[1] = response[618]; + pfi.PowerRatioLandThreshold = response[619]; + pfi.TargetAsymmetry = response[620]; + pfi.TemporaryPeakPower = response[621]; + pfi.TemporaryBiasPower1 = response[622]; + pfi.TemporaryBiasPower2 = response[623]; + pfi.TemporaryBiasPower3 = response[624]; + pfi.PowerRatioGrooveThreshold = response[625]; + pfi.PowerRatioLandThreshold6T = response[626]; + pfi.PowerRatioGrooveThreshold6T = response[627]; + } + break; + // DVD-R and DVD-RW + case DiskCategory.DVDR when pfi.PartVersion < 6: + case DiskCategory.DVDRW when pfi.PartVersion < 3: + pfi.CurrentBorderOutSector = + (uint)((response[36] << 24) + (response[37] << 16) + (response[38] << 8) + response[39]); + pfi.NextBorderInSector = + (uint)((response[40] << 24) + (response[41] << 16) + (response[42] << 8) + response[43]); + break; + // DVD+RW + case DiskCategory.DVDPRW: + pfi.RecordingVelocity = response[36]; + pfi.ReadPowerMaxVelocity = response[37]; + pfi.PIndMaxVelocity = response[38]; + pfi.PMaxVelocity = response[39]; + pfi.E1MaxVelocity = response[40]; + pfi.E2MaxVelocity = response[41]; + pfi.YTargetMaxVelocity = response[42]; + pfi.ReadPowerRefVelocity = response[43]; + pfi.PIndRefVelocity = response[44]; + pfi.PRefVelocity = response[45]; + pfi.E1RefVelocity = response[46]; + pfi.E2RefVelocity = response[47]; + pfi.YTargetRefVelocity = response[48]; + pfi.ReadPowerMinVelocity = response[49]; + pfi.PIndMinVelocity = response[50]; + pfi.PMinVelocity = response[51]; + pfi.E1MinVelocity = response[52]; + pfi.E2MinVelocity = response[53]; + pfi.YTargetMinVelocity = response[54]; + break; } // DVD+R, DVD+RW, DVD+R DL and DVD+RW DL @@ -1230,95 +1227,94 @@ namespace DiscImageChef.Decoders.DVD pfi.PFIUsedInADIP = response[35]; } - // DVD+RW - if(pfi.DiskCategory == DiskCategory.DVDPRW && pfi.PartVersion == 2) - { - pfi.TopFirstPulseDuration = response[55]; - pfi.MultiPulseDuration = response[56]; - pfi.FirstPulseLeadTime = response[57]; - pfi.EraseLeadTimeRefVelocity = response[58]; - pfi.EraseLeadTimeUppVelocity = response[59]; + switch(pfi.DiskCategory) { + // DVD+RW + case DiskCategory.DVDPRW when pfi.PartVersion == 2: + pfi.TopFirstPulseDuration = response[55]; + pfi.MultiPulseDuration = response[56]; + pfi.FirstPulseLeadTime = response[57]; + pfi.EraseLeadTimeRefVelocity = response[58]; + pfi.EraseLeadTimeUppVelocity = response[59]; + break; + // DVD+R and DVD+R DL + case DiskCategory.DVDPR: + case DiskCategory.DVDPRDL: + pfi.PrimaryVelocity = response[36]; + pfi.UpperVelocity = response[37]; + pfi.Wavelength = response[38]; + pfi.NormalizedPowerDependency = response[39]; + pfi.MaximumPowerAtPrimaryVelocity = response[40]; + pfi.PindAtPrimaryVelocity = response[41]; + pfi.BtargetAtPrimaryVelocity = response[42]; + pfi.MaximumPowerAtUpperVelocity = response[43]; + pfi.PindAtUpperVelocity = response[44]; + pfi.BtargetAtUpperVelocity = response[45]; + pfi.FirstPulseDuration4TPrimaryVelocity = response[46]; + pfi.FirstPulseDuration3TPrimaryVelocity = response[47]; + pfi.MultiPulseDurationPrimaryVelocity = response[48]; + pfi.LastPulseDurationPrimaryVelocity = response[49]; + pfi.FirstPulseLeadTime4TPrimaryVelocity = response[50]; + pfi.FirstPulseLeadTime3TPrimaryVelocity = response[51]; + pfi.FirstPulseLeadingEdgePrimaryVelocity = response[52]; + pfi.FirstPulseDuration4TUpperVelocity = response[53]; + pfi.FirstPulseDuration3TUpperVelocity = response[54]; + pfi.MultiPulseDurationUpperVelocity = response[55]; + pfi.LastPulseDurationUpperVelocity = response[56]; + pfi.FirstPulseLeadTime4TUpperVelocity = response[57]; + pfi.FirstPulseLeadTime3TUpperVelocity = response[58]; + pfi.FirstPulseLeadingEdgeUpperVelocity = response[59]; + break; } - // DVD+R and DVD+R DL - if(pfi.DiskCategory == DiskCategory.DVDPR || pfi.DiskCategory == DiskCategory.DVDPRDL) - { - pfi.PrimaryVelocity = response[36]; - pfi.UpperVelocity = response[37]; - pfi.Wavelength = response[38]; - pfi.NormalizedPowerDependency = response[39]; - pfi.MaximumPowerAtPrimaryVelocity = response[40]; - pfi.PindAtPrimaryVelocity = response[41]; - pfi.BtargetAtPrimaryVelocity = response[42]; - pfi.MaximumPowerAtUpperVelocity = response[43]; - pfi.PindAtUpperVelocity = response[44]; - pfi.BtargetAtUpperVelocity = response[45]; - pfi.FirstPulseDuration4TPrimaryVelocity = response[46]; - pfi.FirstPulseDuration3TPrimaryVelocity = response[47]; - pfi.MultiPulseDurationPrimaryVelocity = response[48]; - pfi.LastPulseDurationPrimaryVelocity = response[49]; - pfi.FirstPulseLeadTime4TPrimaryVelocity = response[50]; - pfi.FirstPulseLeadTime3TPrimaryVelocity = response[51]; - pfi.FirstPulseLeadingEdgePrimaryVelocity = response[52]; - pfi.FirstPulseDuration4TUpperVelocity = response[53]; - pfi.FirstPulseDuration3TUpperVelocity = response[54]; - pfi.MultiPulseDurationUpperVelocity = response[55]; - pfi.LastPulseDurationUpperVelocity = response[56]; - pfi.FirstPulseLeadTime4TUpperVelocity = response[57]; - pfi.FirstPulseLeadTime3TUpperVelocity = response[58]; - pfi.FirstPulseLeadingEdgeUpperVelocity = response[59]; - } - - // DVD+R DL - if(pfi.DiskCategory == DiskCategory.DVDPRDL) pfi.LayerStructure = (DVDLayerStructure)((response[34] & 0xC0) >> 6); - - // DVD+RW DL - if(pfi.DiskCategory == DiskCategory.DVDPRWDL) - { - pfi.BasicPrimaryVelocity = response[36]; - pfi.MaxReadPowerPrimaryVelocity = response[37]; - pfi.PindPrimaryVelocity = response[38]; - pfi.PPrimaryVelocity = response[39]; - pfi.E1PrimaryVelocity = response[40]; - pfi.E2PrimaryVelocity = response[41]; - pfi.YtargetPrimaryVelocity = response[42]; - pfi.BOptimumPrimaryVelocity = response[43]; - pfi.TFirstPulseDuration = response[46]; - pfi.TMultiPulseDuration = response[47]; - pfi.FirstPulseLeadTimeAnyRun = response[48]; - pfi.FirstPulseLeadTimeRun3T = response[49]; - pfi.LastPulseLeadTimeAnyRun = response[50]; - pfi.LastPulseLeadTime3T = response[51]; - pfi.LastPulseLeadTime4T = response[52]; - pfi.ErasePulseLeadTimeAny = response[53]; - pfi.ErasePulseLeadTime3T = response[54]; - pfi.ErasePulseLeadTime4T = response[55]; - } - - // DVD-R DL and DVD-RW DL - if(pfi.DiskCategory == DiskCategory.DVDR && pfi.PartVersion == 6 || - pfi.DiskCategory == DiskCategory.DVDRW && pfi.PartVersion == 3) - { - pfi.MaxRecordingSpeed = (DVDRecordingSpeed)response[21]; - pfi.MinRecordingSpeed = (DVDRecordingSpeed)response[22]; - pfi.RecordingSpeed1 = (DVDRecordingSpeed)response[23]; - pfi.RecordingSpeed2 = (DVDRecordingSpeed)response[24]; - pfi.RecordingSpeed3 = (DVDRecordingSpeed)response[25]; - pfi.RecordingSpeed4 = (DVDRecordingSpeed)response[26]; - pfi.RecordingSpeed5 = (DVDRecordingSpeed)response[27]; - pfi.RecordingSpeed6 = (DVDRecordingSpeed)response[28]; - pfi.RecordingSpeed7 = (DVDRecordingSpeed)response[29]; - pfi.Class = response[30]; - pfi.ExtendedVersion = response[31]; - pfi.CurrentBorderOutSector = - (uint)((response[36] << 24) + (response[37] << 16) + (response[38] << 8) + response[39]); - pfi.NextBorderInSector = - (uint)((response[40] << 24) + (response[41] << 16) + (response[42] << 8) + response[43]); - pfi.PreRecordedControlDataInv |= (response[44] & 0x01) == 0x01; - pfi.PreRecordedLeadIn |= (response[44] & 0x02) == 0x02; - pfi.PreRecordedLeadOut |= (response[44] & 0x08) == 0x08; - pfi.ARCharLayer1 = (byte)(response[45] & 0x0F); - pfi.TrackPolarityLayer1 = (byte)((response[45] & 0xF0) >> 4); + switch(pfi.DiskCategory) { + // DVD+R DL + case DiskCategory.DVDPRDL: pfi.LayerStructure = (DVDLayerStructure)((response[34] & 0xC0) >> 6); + break; + // DVD+RW DL + case DiskCategory.DVDPRWDL: + pfi.BasicPrimaryVelocity = response[36]; + pfi.MaxReadPowerPrimaryVelocity = response[37]; + pfi.PindPrimaryVelocity = response[38]; + pfi.PPrimaryVelocity = response[39]; + pfi.E1PrimaryVelocity = response[40]; + pfi.E2PrimaryVelocity = response[41]; + pfi.YtargetPrimaryVelocity = response[42]; + pfi.BOptimumPrimaryVelocity = response[43]; + pfi.TFirstPulseDuration = response[46]; + pfi.TMultiPulseDuration = response[47]; + pfi.FirstPulseLeadTimeAnyRun = response[48]; + pfi.FirstPulseLeadTimeRun3T = response[49]; + pfi.LastPulseLeadTimeAnyRun = response[50]; + pfi.LastPulseLeadTime3T = response[51]; + pfi.LastPulseLeadTime4T = response[52]; + pfi.ErasePulseLeadTimeAny = response[53]; + pfi.ErasePulseLeadTime3T = response[54]; + pfi.ErasePulseLeadTime4T = response[55]; + break; + // DVD-R DL and DVD-RW DL + case DiskCategory.DVDR when pfi.PartVersion == 6: + case DiskCategory.DVDRW when pfi.PartVersion == 3: + pfi.MaxRecordingSpeed = (DVDRecordingSpeed)response[21]; + pfi.MinRecordingSpeed = (DVDRecordingSpeed)response[22]; + pfi.RecordingSpeed1 = (DVDRecordingSpeed)response[23]; + pfi.RecordingSpeed2 = (DVDRecordingSpeed)response[24]; + pfi.RecordingSpeed3 = (DVDRecordingSpeed)response[25]; + pfi.RecordingSpeed4 = (DVDRecordingSpeed)response[26]; + pfi.RecordingSpeed5 = (DVDRecordingSpeed)response[27]; + pfi.RecordingSpeed6 = (DVDRecordingSpeed)response[28]; + pfi.RecordingSpeed7 = (DVDRecordingSpeed)response[29]; + pfi.Class = response[30]; + pfi.ExtendedVersion = response[31]; + pfi.CurrentBorderOutSector = + (uint)((response[36] << 24) + (response[37] << 16) + (response[38] << 8) + response[39]); + pfi.NextBorderInSector = + (uint)((response[40] << 24) + (response[41] << 16) + (response[42] << 8) + response[43]); + pfi.PreRecordedControlDataInv |= (response[44] & 0x01) == 0x01; + pfi.PreRecordedLeadIn |= (response[44] & 0x02) == 0x02; + pfi.PreRecordedLeadOut |= (response[44] & 0x08) == 0x08; + pfi.ARCharLayer1 = (byte)(response[45] & 0x0F); + pfi.TrackPolarityLayer1 = (byte)((response[45] & 0xF0) >> 4); + break; } return pfi; @@ -1351,10 +1347,13 @@ namespace DiscImageChef.Decoders.DVD { case DiskCategory.DVDROM: sb.AppendFormat(categorySentence, sizeString, "DVD-ROM", decoded.PartVersion).AppendLine(); - if(decoded.DiscSize == DVDSize.OneTwenty && decoded.PartVersion == 1) - sb.AppendLine("Disc claims conformation to ECMA-267"); - if(decoded.DiscSize == DVDSize.Eighty && decoded.PartVersion == 1) - sb.AppendLine("Disc claims conformation to ECMA-268"); + switch(decoded.DiscSize) { + case DVDSize.OneTwenty when decoded.PartVersion == 1: sb.AppendLine("Disc claims conformation to ECMA-267"); + break; + case DVDSize.Eighty when decoded.PartVersion == 1: sb.AppendLine("Disc claims conformation to ECMA-268"); + break; + } + break; case DiskCategory.DVDRAM: sb.AppendFormat(categorySentence, sizeString, "DVD-RAM", decoded.PartVersion).AppendLine(); @@ -1580,61 +1579,58 @@ namespace DiscImageChef.Decoders.DVD if(decoded.BCA) sb.AppendLine("Disc has a burst cutting area"); - if(decoded.DiskCategory == DiskCategory.UMD) - sb.AppendFormat("Media attribute is {0}", decoded.MediaAttribute).AppendLine(); + switch(decoded.DiskCategory) { + case DiskCategory.UMD: sb.AppendFormat("Media attribute is {0}", decoded.MediaAttribute).AppendLine(); + break; + case DiskCategory.DVDRAM: + switch(decoded.DiscType) + { + case DVDRAMDiscType.Cased: + sb.AppendLine("Disc shall be recorded with a case"); + break; + case DVDRAMDiscType.Uncased: + sb.AppendLine("Disc can be recorded with or without a case"); + break; + default: + sb.AppendFormat("Unknown DVD-RAM case type key {0}", decoded.DiscType).AppendLine(); + break; + } - if(decoded.DiskCategory == DiskCategory.DVDRAM) - { - switch(decoded.DiscType) - { - case DVDRAMDiscType.Cased: - sb.AppendLine("Disc shall be recorded with a case"); - break; - case DVDRAMDiscType.Uncased: - sb.AppendLine("Disc can be recorded with or without a case"); - break; - default: - sb.AppendFormat("Unknown DVD-RAM case type key {0}", decoded.DiscType).AppendLine(); - break; - } - - if(decoded.PartVersion == 6) - { - sb.AppendFormat("Disc manufacturer is {0}", decoded.DiskManufacturer).AppendLine(); - sb.AppendFormat("Disc manufacturer supplementary information is {0}", - decoded.DiskManufacturerSupplementary).AppendLine(); - } + if(decoded.PartVersion == 6) + { + sb.AppendFormat("Disc manufacturer is {0}", decoded.DiskManufacturer).AppendLine(); + sb.AppendFormat("Disc manufacturer supplementary information is {0}", + decoded.DiskManufacturerSupplementary).AppendLine(); + } + break; + case DiskCategory.DVDR when decoded.PartVersion < 6: + case DiskCategory.DVDRW when decoded.PartVersion < 3: + sb.AppendFormat("Current Border-Out first sector is PSN {0:X}h", decoded.CurrentBorderOutSector) + .AppendLine(); + sb.AppendFormat("Next Border-In first sector is PSN {0:X}h", decoded.NextBorderInSector).AppendLine(); + break; + case DiskCategory.DVDPR: + case DiskCategory.DVDPRW: + case DiskCategory.DVDPRDL: + case DiskCategory.DVDPRWDL: + if(decoded.VCPS) sb.AppendLine("Disc contains extended information for VCPS"); + sb.AppendFormat("Disc application code is {0}", decoded.ApplicationCode).AppendLine(); + sb.AppendFormat("Disc manufacturer is {0}", decoded.DiskManufacturerID).AppendLine(); + sb.AppendFormat("Disc media type is {0}", decoded.MediaTypeID).AppendLine(); + sb.AppendFormat("Disc product revision is {0}", decoded.ProductRevision).AppendLine(); + break; } - if(decoded.DiskCategory == DiskCategory.DVDR && decoded.PartVersion < 6 || - decoded.DiskCategory == DiskCategory.DVDRW && decoded.PartVersion < 3) - { - sb.AppendFormat("Current Border-Out first sector is PSN {0:X}h", decoded.CurrentBorderOutSector) - .AppendLine(); - sb.AppendFormat("Next Border-In first sector is PSN {0:X}h", decoded.NextBorderInSector).AppendLine(); - } + if((decoded.DiskCategory != DiskCategory.DVDR || decoded.PartVersion < 6) && + (decoded.DiskCategory != DiskCategory.DVDRW || decoded.PartVersion < 3)) return sb.ToString(); - if(decoded.DiskCategory == DiskCategory.DVDPR || decoded.DiskCategory == DiskCategory.DVDPRW || - decoded.DiskCategory == DiskCategory.DVDPRDL || decoded.DiskCategory == DiskCategory.DVDPRWDL) - { - if(decoded.VCPS) sb.AppendLine("Disc contains extended information for VCPS"); - sb.AppendFormat("Disc application code is {0}", decoded.ApplicationCode).AppendLine(); - sb.AppendFormat("Disc manufacturer is {0}", decoded.DiskManufacturerID).AppendLine(); - sb.AppendFormat("Disc media type is {0}", decoded.MediaTypeID).AppendLine(); - sb.AppendFormat("Disc product revision is {0}", decoded.ProductRevision).AppendLine(); - } - - if(decoded.DiskCategory == DiskCategory.DVDR && decoded.PartVersion >= 6 || - decoded.DiskCategory == DiskCategory.DVDRW && decoded.PartVersion >= 3) - { - sb.AppendFormat("Current RMD in extra Border zone starts at PSN {0:X}h", - decoded.CurrentRMDExtraBorderPSN).AppendLine(); - sb.AppendFormat("PFI in extra Border zone starts at PSN {0:X}h", decoded.PFIExtraBorderPSN) - .AppendLine(); - if(!decoded.PreRecordedControlDataInv) sb.AppendLine("Control Data Zone is pre-recorded"); - if(decoded.PreRecordedLeadIn) sb.AppendLine("Lead-In is pre-recorded"); - if(decoded.PreRecordedLeadOut) sb.AppendLine("Lead-Out is pre-recorded"); - } + sb.AppendFormat("Current RMD in extra Border zone starts at PSN {0:X}h", + decoded.CurrentRMDExtraBorderPSN).AppendLine(); + sb.AppendFormat("PFI in extra Border zone starts at PSN {0:X}h", decoded.PFIExtraBorderPSN) + .AppendLine(); + if(!decoded.PreRecordedControlDataInv) sb.AppendLine("Control Data Zone is pre-recorded"); + if(decoded.PreRecordedLeadIn) sb.AppendLine("Lead-In is pre-recorded"); + if(decoded.PreRecordedLeadOut) sb.AppendLine("Lead-Out is pre-recorded"); return sb.ToString(); } diff --git a/DiscImageChef.Decoders/SCSI/EVPD.cs b/DiscImageChef.Decoders/SCSI/EVPD.cs index 6426e5805..9af225589 100644 --- a/DiscImageChef.Decoders/SCSI/EVPD.cs +++ b/DiscImageChef.Decoders/SCSI/EVPD.cs @@ -407,11 +407,14 @@ namespace DiscImageChef.Decoders.SCSI if(descriptor.Length + position + 4 >= pageResponse.Length) descriptor.Length = (byte)(pageResponse.Length - position - 4); Array.Copy(pageResponse, position + 4, descriptor.Binary, 0, descriptor.Length); - if(descriptor.CodeSet == IdentificationCodeSet.ASCII) - descriptor.ASCII = StringHandlers.CToString(descriptor.Binary); - else if(descriptor.CodeSet == IdentificationCodeSet.UTF8) - descriptor.ASCII = Encoding.UTF8.GetString(descriptor.Binary); - else descriptor.ASCII = ""; + switch(descriptor.CodeSet) { + case IdentificationCodeSet.ASCII: descriptor.ASCII = StringHandlers.CToString(descriptor.Binary); + break; + case IdentificationCodeSet.UTF8: descriptor.ASCII = Encoding.UTF8.GetString(descriptor.Binary); + break; + default: descriptor.ASCII = ""; + break; + } position += 4 + descriptor.Length; descriptors.Add(descriptor); @@ -516,28 +519,36 @@ namespace DiscImageChef.Decoders.SCSI switch(descriptor.Type) { case IdentificationTypes.NoAuthority: - if(descriptor.CodeSet == IdentificationCodeSet.ASCII || - descriptor.CodeSet == IdentificationCodeSet.UTF8) - sb.AppendFormat("\tVendor descriptor contains: {0}", descriptor.ASCII).AppendLine(); - else if(descriptor.CodeSet == IdentificationCodeSet.Binary) - sb.AppendFormat("\tVendor descriptor contains binary data (hex): {0}", - PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40)).AppendLine(); - else - sb.AppendFormat("\tVendor descriptor contains unknown kind {1} of data (hex): {0}", - PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40), - (byte)descriptor.CodeSet).AppendLine(); + switch(descriptor.CodeSet) { + case IdentificationCodeSet.ASCII: + case IdentificationCodeSet.UTF8: sb.AppendFormat("\tVendor descriptor contains: {0}", descriptor.ASCII).AppendLine(); + break; + case IdentificationCodeSet.Binary: + sb.AppendFormat("\tVendor descriptor contains binary data (hex): {0}", + PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40)).AppendLine(); + break; + default: + sb.AppendFormat("\tVendor descriptor contains unknown kind {1} of data (hex): {0}", + PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40), + (byte)descriptor.CodeSet).AppendLine(); + break; + } break; case IdentificationTypes.Inquiry: - if(descriptor.CodeSet == IdentificationCodeSet.ASCII || - descriptor.CodeSet == IdentificationCodeSet.UTF8) - sb.AppendFormat("\tInquiry descriptor contains: {0}", descriptor.ASCII).AppendLine(); - else if(descriptor.CodeSet == IdentificationCodeSet.Binary) - sb.AppendFormat("\tInquiry descriptor contains binary data (hex): {0}", - PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40)).AppendLine(); - else - sb.AppendFormat("\tInquiry descriptor contains unknown kind {1} of data (hex): {0}", - PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40), - (byte)descriptor.CodeSet).AppendLine(); + switch(descriptor.CodeSet) { + case IdentificationCodeSet.ASCII: + case IdentificationCodeSet.UTF8: sb.AppendFormat("\tInquiry descriptor contains: {0}", descriptor.ASCII).AppendLine(); + break; + case IdentificationCodeSet.Binary: + sb.AppendFormat("\tInquiry descriptor contains binary data (hex): {0}", + PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40)).AppendLine(); + break; + default: + sb.AppendFormat("\tInquiry descriptor contains unknown kind {1} of data (hex): {0}", + PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40), + (byte)descriptor.CodeSet).AppendLine(); + break; + } break; case IdentificationTypes.EUI: if(descriptor.CodeSet == IdentificationCodeSet.ASCII || @@ -705,18 +716,24 @@ namespace DiscImageChef.Decoders.SCSI break; default: - if(descriptor.CodeSet == IdentificationCodeSet.ASCII || - descriptor.CodeSet == IdentificationCodeSet.UTF8) - sb.AppendFormat("\tUnknown descriptor type {1} contains: {0}", descriptor.ASCII, - (byte)descriptor.Type).AppendLine(); - else if(descriptor.CodeSet == IdentificationCodeSet.Binary) - sb.AppendFormat("\tUnknown descriptor type {1} contains binary data (hex): {0}", - PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40), - (byte)descriptor.Type).AppendLine(); - else - sb.AppendFormat("Inquiry descriptor type {2} contains unknown kind {1} of data (hex): {0}", - PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40), - (byte)descriptor.CodeSet, (byte)descriptor.Type).AppendLine(); + switch(descriptor.CodeSet) { + case IdentificationCodeSet.ASCII: + case IdentificationCodeSet.UTF8: + sb.AppendFormat("\tUnknown descriptor type {1} contains: {0}", descriptor.ASCII, + (byte)descriptor.Type).AppendLine(); + break; + case IdentificationCodeSet.Binary: + sb.AppendFormat("\tUnknown descriptor type {1} contains binary data (hex): {0}", + PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40), + (byte)descriptor.Type).AppendLine(); + break; + default: + sb.AppendFormat("Inquiry descriptor type {2} contains unknown kind {1} of data (hex): {0}", + PrintHex.ByteArrayToHexArrayString(descriptor.Binary, 40), + (byte)descriptor.CodeSet, (byte)descriptor.Type).AppendLine(); + break; + } + break; } } @@ -1205,38 +1222,41 @@ namespace DiscImageChef.Decoders.SCSI sb.AppendLine("SCSI Extended INQUIRY Data:"); - if(page.PeripheralDeviceType == PeripheralDeviceTypes.DirectAccess || - page.PeripheralDeviceType == PeripheralDeviceTypes.SCSIZonedBlockDevice) - switch(page.SPT) - { - case 0: - sb.AppendLine("Logical unit supports type 1 protection"); - break; - case 1: - sb.AppendLine("Logical unit supports types 1 and 2 protection"); - break; - case 2: - sb.AppendLine("Logical unit supports type 2 protection"); - break; - case 3: - sb.AppendLine("Logical unit supports types 1 and 3 protection"); - break; - case 4: - sb.AppendLine("Logical unit supports type 3 protection"); - break; - case 5: - sb.AppendLine("Logical unit supports types 2 and 3 protection"); - break; - case 7: - sb.AppendLine("Logical unit supports types 1, 2 and 3 protection"); - break; - default: - sb.AppendFormat("Logical unit supports unknown protection defined by code {0}", (byte)page.SPT) - .AppendLine(); - break; - } - else if(page.PeripheralDeviceType == PeripheralDeviceTypes.SequentialAccess && page.SPT == 1) - sb.AppendLine("Logical unit supports logical block protection"); + switch(page.PeripheralDeviceType) { + case PeripheralDeviceTypes.DirectAccess: + case PeripheralDeviceTypes.SCSIZonedBlockDevice: + switch(page.SPT) + { + case 0: + sb.AppendLine("Logical unit supports type 1 protection"); + break; + case 1: + sb.AppendLine("Logical unit supports types 1 and 2 protection"); + break; + case 2: + sb.AppendLine("Logical unit supports type 2 protection"); + break; + case 3: + sb.AppendLine("Logical unit supports types 1 and 3 protection"); + break; + case 4: + sb.AppendLine("Logical unit supports type 3 protection"); + break; + case 5: + sb.AppendLine("Logical unit supports types 2 and 3 protection"); + break; + case 7: + sb.AppendLine("Logical unit supports types 1, 2 and 3 protection"); + break; + default: + sb.AppendFormat("Logical unit supports unknown protection defined by code {0}", (byte)page.SPT) + .AppendLine(); + break; + } + break; + case PeripheralDeviceTypes.SequentialAccess when page.SPT == 1: sb.AppendLine("Logical unit supports logical block protection"); + break; + } if(page.GRD_CHK) sb.AppendLine("Device checks the logical block guard"); if(page.APP_CHK) sb.AppendLine("Device checks the logical block application tag"); diff --git a/DiscImageChef.Decoders/SCSI/Modes/Mode10.cs b/DiscImageChef.Decoders/SCSI/Modes/Mode10.cs index de359bf40..194b6f056 100644 --- a/DiscImageChef.Decoders/SCSI/Modes/Mode10.cs +++ b/DiscImageChef.Decoders/SCSI/Modes/Mode10.cs @@ -100,27 +100,24 @@ namespace DiscImageChef.Decoders.SCSI } } - if(deviceType == PeripheralDeviceTypes.DirectAccess || deviceType == PeripheralDeviceTypes.MultiMediaDevice) - { - header.WriteProtected = (modeResponse[3] & 0x80) == 0x80; - header.DPOFUA = (modeResponse[3] & 0x10) == 0x10; - } - - if(deviceType == PeripheralDeviceTypes.SequentialAccess) - { - header.WriteProtected = (modeResponse[3] & 0x80) == 0x80; - header.Speed = (byte)(modeResponse[3] & 0x0F); - header.BufferedMode = (byte)((modeResponse[3] & 0x70) >> 4); - } - - if(deviceType == PeripheralDeviceTypes.PrinterDevice) - header.BufferedMode = (byte)((modeResponse[3] & 0x70) >> 4); - - if(deviceType == PeripheralDeviceTypes.OpticalDevice) - { - header.WriteProtected = (modeResponse[3] & 0x80) == 0x80; - header.EBC = (modeResponse[3] & 0x01) == 0x01; - header.DPOFUA = (modeResponse[3] & 0x10) == 0x10; + switch(deviceType) { + case PeripheralDeviceTypes.DirectAccess: + case PeripheralDeviceTypes.MultiMediaDevice: + header.WriteProtected = (modeResponse[3] & 0x80) == 0x80; + header.DPOFUA = (modeResponse[3] & 0x10) == 0x10; + break; + case PeripheralDeviceTypes.SequentialAccess: + header.WriteProtected = (modeResponse[3] & 0x80) == 0x80; + header.Speed = (byte)(modeResponse[3] & 0x0F); + header.BufferedMode = (byte)((modeResponse[3] & 0x70) >> 4); + break; + case PeripheralDeviceTypes.PrinterDevice: header.BufferedMode = (byte)((modeResponse[3] & 0x70) >> 4); + break; + case PeripheralDeviceTypes.OpticalDevice: + header.WriteProtected = (modeResponse[3] & 0x80) == 0x80; + header.EBC = (modeResponse[3] & 0x01) == 0x01; + header.DPOFUA = (modeResponse[3] & 0x10) == 0x10; + break; } return header; @@ -217,26 +214,24 @@ namespace DiscImageChef.Decoders.SCSI hdr[2] = (byte)header.MediumType; - if(deviceType == PeripheralDeviceTypes.DirectAccess || deviceType == PeripheralDeviceTypes.MultiMediaDevice) - { - if(header.WriteProtected) hdr[3] += 0x80; - if(header.DPOFUA) hdr[3] += 0x10; - } - - if(deviceType == PeripheralDeviceTypes.SequentialAccess) - { - if(header.WriteProtected) hdr[3] += 0x80; - hdr[3] += (byte)(header.Speed & 0x0F); - hdr[3] += (byte)((header.BufferedMode << 4) & 0x70); - } - - if(deviceType == PeripheralDeviceTypes.PrinterDevice) hdr[3] += (byte)((header.BufferedMode << 4) & 0x70); - - if(deviceType == PeripheralDeviceTypes.OpticalDevice) - { - if(header.WriteProtected) hdr[3] += 0x80; - if(header.EBC) hdr[3] += 0x01; - if(header.DPOFUA) hdr[3] += 0x10; + switch(deviceType) { + case PeripheralDeviceTypes.DirectAccess: + case PeripheralDeviceTypes.MultiMediaDevice: + if(header.WriteProtected) hdr[3] += 0x80; + if(header.DPOFUA) hdr[3] += 0x10; + break; + case PeripheralDeviceTypes.SequentialAccess: + if(header.WriteProtected) hdr[3] += 0x80; + hdr[3] += (byte)(header.Speed & 0x0F); + hdr[3] += (byte)((header.BufferedMode << 4) & 0x70); + break; + case PeripheralDeviceTypes.PrinterDevice: hdr[3] += (byte)((header.BufferedMode << 4) & 0x70); + break; + case PeripheralDeviceTypes.OpticalDevice: + if(header.WriteProtected) hdr[3] += 0x80; + if(header.EBC) hdr[3] += 0x01; + if(header.DPOFUA) hdr[3] += 0x10; + break; } if(longLBA) hdr[4] += 0x01; diff --git a/DiscImageChef.Decoders/SCSI/Modes/Mode6.cs b/DiscImageChef.Decoders/SCSI/Modes/Mode6.cs index 781f16a4f..95a166f68 100644 --- a/DiscImageChef.Decoders/SCSI/Modes/Mode6.cs +++ b/DiscImageChef.Decoders/SCSI/Modes/Mode6.cs @@ -60,27 +60,24 @@ namespace DiscImageChef.Decoders.SCSI } } - if(deviceType == PeripheralDeviceTypes.DirectAccess || deviceType == PeripheralDeviceTypes.MultiMediaDevice) - { - header.WriteProtected = (modeResponse[2] & 0x80) == 0x80; - header.DPOFUA = (modeResponse[2] & 0x10) == 0x10; - } - - if(deviceType == PeripheralDeviceTypes.SequentialAccess) - { - header.WriteProtected = (modeResponse[2] & 0x80) == 0x80; - header.Speed = (byte)(modeResponse[2] & 0x0F); - header.BufferedMode = (byte)((modeResponse[2] & 0x70) >> 4); - } - - if(deviceType == PeripheralDeviceTypes.PrinterDevice) - header.BufferedMode = (byte)((modeResponse[2] & 0x70) >> 4); - - if(deviceType == PeripheralDeviceTypes.OpticalDevice) - { - header.WriteProtected = (modeResponse[2] & 0x80) == 0x80; - header.EBC = (modeResponse[2] & 0x01) == 0x01; - header.DPOFUA = (modeResponse[2] & 0x10) == 0x10; + switch(deviceType) { + case PeripheralDeviceTypes.DirectAccess: + case PeripheralDeviceTypes.MultiMediaDevice: + header.WriteProtected = (modeResponse[2] & 0x80) == 0x80; + header.DPOFUA = (modeResponse[2] & 0x10) == 0x10; + break; + case PeripheralDeviceTypes.SequentialAccess: + header.WriteProtected = (modeResponse[2] & 0x80) == 0x80; + header.Speed = (byte)(modeResponse[2] & 0x0F); + header.BufferedMode = (byte)((modeResponse[2] & 0x70) >> 4); + break; + case PeripheralDeviceTypes.PrinterDevice: header.BufferedMode = (byte)((modeResponse[2] & 0x70) >> 4); + break; + case PeripheralDeviceTypes.OpticalDevice: + header.WriteProtected = (modeResponse[2] & 0x80) == 0x80; + header.EBC = (modeResponse[2] & 0x01) == 0x01; + header.DPOFUA = (modeResponse[2] & 0x10) == 0x10; + break; } return header; @@ -157,7 +154,7 @@ namespace DiscImageChef.Decoders.SCSI return decoded; } - + public static byte[] EncodeModeHeader6(ModeHeader header, PeripheralDeviceTypes deviceType) { byte[] hdr; @@ -167,26 +164,24 @@ namespace DiscImageChef.Decoders.SCSI hdr[1] = (byte)header.MediumType; - if(deviceType == PeripheralDeviceTypes.DirectAccess || deviceType == PeripheralDeviceTypes.MultiMediaDevice) - { - if(header.WriteProtected) hdr[2] += 0x80; - if(header.DPOFUA) hdr[2] += 0x10; - } - - if(deviceType == PeripheralDeviceTypes.SequentialAccess) - { - if(header.WriteProtected) hdr[2] += 0x80; - hdr[2] += (byte)(header.Speed & 0x0F); - hdr[2] += (byte)((header.BufferedMode << 4) & 0x70); - } - - if(deviceType == PeripheralDeviceTypes.PrinterDevice) hdr[2] += (byte)((header.BufferedMode << 4) & 0x70); - - if(deviceType == PeripheralDeviceTypes.OpticalDevice) - { - if(header.WriteProtected) hdr[2] += 0x80; - if(header.EBC) hdr[2] += 0x01; - if(header.DPOFUA) hdr[2] += 0x10; + switch(deviceType) { + case PeripheralDeviceTypes.DirectAccess: + case PeripheralDeviceTypes.MultiMediaDevice: + if(header.WriteProtected) hdr[2] += 0x80; + if(header.DPOFUA) hdr[2] += 0x10; + break; + case PeripheralDeviceTypes.SequentialAccess: + if(header.WriteProtected) hdr[2] += 0x80; + hdr[2] += (byte)(header.Speed & 0x0F); + hdr[2] += (byte)((header.BufferedMode << 4) & 0x70); + break; + case PeripheralDeviceTypes.PrinterDevice: hdr[2] += (byte)((header.BufferedMode << 4) & 0x70); + break; + case PeripheralDeviceTypes.OpticalDevice: + if(header.WriteProtected) hdr[2] += 0x80; + if(header.EBC) hdr[2] += 0x01; + if(header.DPOFUA) hdr[2] += 0x10; + break; } if(header.BlockDescriptors != null) diff --git a/DiscImageChef.Decoders/Xbox/DMI.cs b/DiscImageChef.Decoders/Xbox/DMI.cs index ba01d747e..a64dbb5c5 100644 --- a/DiscImageChef.Decoders/Xbox/DMI.cs +++ b/DiscImageChef.Decoders/Xbox/DMI.cs @@ -234,28 +234,30 @@ namespace DiscImageChef.Decoders.Xbox sb.Append("-"); - if(decoded.CatalogNumber.Length == 13) - { - for(int i = 8; i < 10; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]); + switch(decoded.CatalogNumber.Length) { + case 13: + for(int i = 8; i < 10; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]); - sb.Append("-"); - for(int i = 10; i < 13; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]); - } - else if(decoded.CatalogNumber.Length == 14) - { - for(int i = 8; i < 11; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]); + sb.Append("-"); + for(int i = 10; i < 13; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]); - sb.Append("-"); - for(int i = 11; i < 14; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]); - } - else - { - for(int i = 8; i < decoded.CatalogNumber.Length - 3; i++) - sb.AppendFormat("{0}", decoded.CatalogNumber[i]); + break; + case 14: + for(int i = 8; i < 11; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]); - sb.Append("-"); - for(int i = decoded.CatalogNumber.Length - 3; i < decoded.CatalogNumber.Length; i++) - sb.AppendFormat("{0}", decoded.CatalogNumber[i]); + sb.Append("-"); + for(int i = 11; i < 14; i++) sb.AppendFormat("{0}", decoded.CatalogNumber[i]); + + break; + default: + for(int i = 8; i < decoded.CatalogNumber.Length - 3; i++) + sb.AppendFormat("{0}", decoded.CatalogNumber[i]); + + sb.Append("-"); + for(int i = decoded.CatalogNumber.Length - 3; i < decoded.CatalogNumber.Length; i++) + sb.AppendFormat("{0}", decoded.CatalogNumber[i]); + + break; } sb.AppendLine(); diff --git a/DiscImageChef.Devices/Device/Commands.cs b/DiscImageChef.Devices/Device/Commands.cs index ba681a3d3..e8092b0a6 100644 --- a/DiscImageChef.Devices/Device/Commands.cs +++ b/DiscImageChef.Devices/Device/Commands.cs @@ -137,40 +137,40 @@ namespace DiscImageChef.Devices uint blockSize, uint blocks, ref byte[] buffer, out uint[] response, out double duration, out bool sense, uint timeout = 0) { - if(command == MmcCommands.SendCid && cachedCid != null) - { - System.DateTime start = System.DateTime.Now; - buffer = new byte[cachedCid.Length]; - System.Array.Copy(cachedCid, buffer, buffer.Length); - response = new uint[4]; - sense = false; - System.DateTime end = System.DateTime.Now; - duration = (end - start).TotalMilliseconds; - return 0; - } - - if(command == MmcCommands.SendCsd && cachedCid != null) - { - System.DateTime start = System.DateTime.Now; - buffer = new byte[cachedCsd.Length]; - System.Array.Copy(cachedCsd, buffer, buffer.Length); - response = new uint[4]; - sense = false; - System.DateTime end = System.DateTime.Now; - duration = (end - start).TotalMilliseconds; - return 0; - } - - if(command == (MmcCommands)SecureDigitalCommands.SendScr && cachedScr != null) - { - System.DateTime start = System.DateTime.Now; - buffer = new byte[cachedScr.Length]; - System.Array.Copy(cachedScr, buffer, buffer.Length); - response = new uint[4]; - sense = false; - System.DateTime end = System.DateTime.Now; - duration = (end - start).TotalMilliseconds; - return 0; + switch(command) { + case MmcCommands.SendCid when cachedCid != null: + { + System.DateTime start = System.DateTime.Now; + buffer = new byte[cachedCid.Length]; + System.Array.Copy(cachedCid, buffer, buffer.Length); + response = new uint[4]; + sense = false; + System.DateTime end = System.DateTime.Now; + duration = (end - start).TotalMilliseconds; + return 0; + } + case MmcCommands.SendCsd when cachedCid != null: + { + System.DateTime start = System.DateTime.Now; + buffer = new byte[cachedCsd.Length]; + System.Array.Copy(cachedCsd, buffer, buffer.Length); + response = new uint[4]; + sense = false; + System.DateTime end = System.DateTime.Now; + duration = (end - start).TotalMilliseconds; + return 0; + } + case (MmcCommands)SecureDigitalCommands.SendScr when cachedScr != null: + { + System.DateTime start = System.DateTime.Now; + buffer = new byte[cachedScr.Length]; + System.Array.Copy(cachedScr, buffer, buffer.Length); + response = new uint[4]; + sense = false; + System.DateTime end = System.DateTime.Now; + duration = (end - start).TotalMilliseconds; + return 0; + } } if((command == (MmcCommands)SecureDigitalCommands.SendOperatingCondition || diff --git a/DiscImageChef.Devices/Device/Constructor.cs b/DiscImageChef.Devices/Device/Constructor.cs index 0cdfe035e..8dac57150 100644 --- a/DiscImageChef.Devices/Device/Constructor.cs +++ b/DiscImageChef.Devices/Device/Constructor.cs @@ -121,219 +121,222 @@ namespace DiscImageChef.Devices string ntDevicePath = null; // Windows is answering SCSI INQUIRY for all device types so it needs to be detected first - if(platformId == Interop.PlatformID.Win32NT) - { - Windows.StoragePropertyQuery query = new Windows.StoragePropertyQuery(); - query.PropertyId = Windows.StoragePropertyId.Device; - query.QueryType = Windows.StorageQueryType.Standard; - query.AdditionalParameters = new byte[1]; + switch(platformId) { + case Interop.PlatformID.Win32NT: + Windows.StoragePropertyQuery query = new Windows.StoragePropertyQuery(); + query.PropertyId = Windows.StoragePropertyId.Device; + query.QueryType = Windows.StorageQueryType.Standard; + query.AdditionalParameters = new byte[1]; - IntPtr descriptorPtr = Marshal.AllocHGlobal(1000); - byte[] descriptorB = new byte[1000]; + IntPtr descriptorPtr = Marshal.AllocHGlobal(1000); + byte[] descriptorB = new byte[1000]; - uint returned = 0; - int error = 0; + uint returned = 0; + int error = 0; - bool hasError = !Windows.Extern.DeviceIoControlStorageQuery((SafeFileHandle)fd, - Windows.WindowsIoctl - .IoctlStorageQueryProperty, - ref query, (uint)Marshal.SizeOf(query), - descriptorPtr, 1000, ref returned, - IntPtr.Zero); + bool hasError = !Windows.Extern.DeviceIoControlStorageQuery((SafeFileHandle)fd, + Windows.WindowsIoctl + .IoctlStorageQueryProperty, + ref query, (uint)Marshal.SizeOf(query), + descriptorPtr, 1000, ref returned, + IntPtr.Zero); - if(hasError) error = Marshal.GetLastWin32Error(); + if(hasError) error = Marshal.GetLastWin32Error(); - Marshal.Copy(descriptorPtr, descriptorB, 0, 1000); + Marshal.Copy(descriptorPtr, descriptorB, 0, 1000); - if(!hasError && error == 0) - { - Windows.StorageDeviceDescriptor descriptor = new Windows.StorageDeviceDescriptor(); - descriptor.Version = BitConverter.ToUInt32(descriptorB, 0); - descriptor.Size = BitConverter.ToUInt32(descriptorB, 4); - descriptor.DeviceType = descriptorB[8]; - descriptor.DeviceTypeModifier = descriptorB[9]; - descriptor.RemovableMedia = descriptorB[10] > 0; - descriptor.CommandQueueing = descriptorB[11] > 0; - descriptor.VendorIdOffset = BitConverter.ToInt32(descriptorB, 12); - descriptor.ProductIdOffset = BitConverter.ToInt32(descriptorB, 16); - descriptor.ProductRevisionOffset = BitConverter.ToInt32(descriptorB, 20); - descriptor.SerialNumberOffset = BitConverter.ToInt32(descriptorB, 24); - descriptor.BusType = (Windows.StorageBusType)BitConverter.ToUInt32(descriptorB, 28); - descriptor.RawPropertiesLength = BitConverter.ToUInt32(descriptorB, 32); - descriptor.RawDeviceProperties = new byte[descriptor.RawPropertiesLength]; - Array.Copy(descriptorB, 36, descriptor.RawDeviceProperties, 0, descriptor.RawPropertiesLength); - - switch(descriptor.BusType) + if(!hasError && error == 0) { - case Windows.StorageBusType.SCSI: - case Windows.StorageBusType.SSA: - case Windows.StorageBusType.Fibre: - case Windows.StorageBusType.iSCSI: - case Windows.StorageBusType.SAS: - type = DeviceType.SCSI; - break; - case Windows.StorageBusType.FireWire: - firewire = true; - type = DeviceType.SCSI; - break; - case Windows.StorageBusType.USB: - usb = true; - type = DeviceType.SCSI; - break; - case Windows.StorageBusType.ATAPI: - type = DeviceType.ATAPI; - break; - case Windows.StorageBusType.ATA: - case Windows.StorageBusType.SATA: - type = DeviceType.ATA; - break; - case Windows.StorageBusType.MultiMediaCard: - type = DeviceType.MMC; - break; - case Windows.StorageBusType.SecureDigital: - type = DeviceType.SecureDigital; - break; - case Windows.StorageBusType.NVMe: - type = DeviceType.NVMe; - break; - } + Windows.StorageDeviceDescriptor descriptor = new Windows.StorageDeviceDescriptor(); + descriptor.Version = BitConverter.ToUInt32(descriptorB, 0); + descriptor.Size = BitConverter.ToUInt32(descriptorB, 4); + descriptor.DeviceType = descriptorB[8]; + descriptor.DeviceTypeModifier = descriptorB[9]; + descriptor.RemovableMedia = descriptorB[10] > 0; + descriptor.CommandQueueing = descriptorB[11] > 0; + descriptor.VendorIdOffset = BitConverter.ToInt32(descriptorB, 12); + descriptor.ProductIdOffset = BitConverter.ToInt32(descriptorB, 16); + descriptor.ProductRevisionOffset = BitConverter.ToInt32(descriptorB, 20); + descriptor.SerialNumberOffset = BitConverter.ToInt32(descriptorB, 24); + descriptor.BusType = (Windows.StorageBusType)BitConverter.ToUInt32(descriptorB, 28); + descriptor.RawPropertiesLength = BitConverter.ToUInt32(descriptorB, 32); + descriptor.RawDeviceProperties = new byte[descriptor.RawPropertiesLength]; + Array.Copy(descriptorB, 36, descriptor.RawDeviceProperties, 0, descriptor.RawPropertiesLength); - if(type == DeviceType.SCSI || type == DeviceType.ATAPI) - scsiSense = ScsiInquiry(out inqBuf, out senseBuf); - else if(type == DeviceType.ATA) - { - bool atapiSense = AtapiIdentify(out ataBuf, out errorRegisters); - - if(!atapiSense) + switch(descriptor.BusType) { - type = DeviceType.ATAPI; - Identify.IdentifyDevice? ataid = Identify.Decode(ataBuf); - - if(ataid.HasValue) scsiSense = ScsiInquiry(out inqBuf, out senseBuf); + case Windows.StorageBusType.SCSI: + case Windows.StorageBusType.SSA: + case Windows.StorageBusType.Fibre: + case Windows.StorageBusType.iSCSI: + case Windows.StorageBusType.SAS: + type = DeviceType.SCSI; + break; + case Windows.StorageBusType.FireWire: + firewire = true; + type = DeviceType.SCSI; + break; + case Windows.StorageBusType.USB: + usb = true; + type = DeviceType.SCSI; + break; + case Windows.StorageBusType.ATAPI: + type = DeviceType.ATAPI; + break; + case Windows.StorageBusType.ATA: + case Windows.StorageBusType.SATA: + type = DeviceType.ATA; + break; + case Windows.StorageBusType.MultiMediaCard: + type = DeviceType.MMC; + break; + case Windows.StorageBusType.SecureDigital: + type = DeviceType.SecureDigital; + break; + case Windows.StorageBusType.NVMe: + type = DeviceType.NVMe; + break; } - else manufacturer = "ATA"; - } - } - ntDevicePath = Windows.Command.GetDevicePath((SafeFileHandle)fd); - DicConsole.DebugWriteLine("Windows devices", "NT device path: {0}", ntDevicePath); - Marshal.FreeHGlobal(descriptorPtr); + switch(type) { + case DeviceType.SCSI: + case DeviceType.ATAPI: scsiSense = ScsiInquiry(out inqBuf, out senseBuf); + break; + case DeviceType.ATA: + bool atapiSense = AtapiIdentify(out ataBuf, out errorRegisters); - if(Windows.Command.IsSdhci((SafeFileHandle)fd)) - { - byte[] sdBuffer = new byte[16]; - bool sense = false; + if(!atapiSense) + { + type = DeviceType.ATAPI; + Identify.IdentifyDevice? ataid = Identify.Decode(ataBuf); - lastError = Windows.Command.SendMmcCommand((SafeFileHandle)fd, MmcCommands.SendCsd, false, false, - MmcFlags.ResponseSpiR2 | MmcFlags.ResponseR2 | - MmcFlags.CommandAc, 0, 16, 1, ref sdBuffer, - out uint[] response, out double duration, out sense, 0); - - if(!sense) - { - cachedCsd = new byte[16]; - Array.Copy(sdBuffer, 0, cachedCsd, 0, 16); + if(ataid.HasValue) scsiSense = ScsiInquiry(out inqBuf, out senseBuf); + } + else manufacturer = "ATA"; + break; + } } - sdBuffer = new byte[16]; - sense = false; + ntDevicePath = Windows.Command.GetDevicePath((SafeFileHandle)fd); + DicConsole.DebugWriteLine("Windows devices", "NT device path: {0}", ntDevicePath); + Marshal.FreeHGlobal(descriptorPtr); - lastError = Windows.Command.SendMmcCommand((SafeFileHandle)fd, MmcCommands.SendCid, false, false, - MmcFlags.ResponseSpiR2 | MmcFlags.ResponseR2 | - MmcFlags.CommandAc, 0, 16, 1, ref sdBuffer, out response, - out duration, out sense, 0); - - if(!sense) + if(Windows.Command.IsSdhci((SafeFileHandle)fd)) { - cachedCid = new byte[16]; - Array.Copy(sdBuffer, 0, cachedCid, 0, 16); - } + byte[] sdBuffer = new byte[16]; + bool sense = false; - sdBuffer = new byte[8]; - sense = false; + lastError = Windows.Command.SendMmcCommand((SafeFileHandle)fd, MmcCommands.SendCsd, false, false, + MmcFlags.ResponseSpiR2 | MmcFlags.ResponseR2 | + MmcFlags.CommandAc, 0, 16, 1, ref sdBuffer, + out uint[] response, out double duration, out sense, 0); - lastError = Windows.Command.SendMmcCommand((SafeFileHandle)fd, - (MmcCommands)SecureDigitalCommands.SendScr, false, true, - MmcFlags.ResponseSpiR1 | MmcFlags.ResponseR1 | - MmcFlags.CommandAdtc, 0, 8, 1, ref sdBuffer, - out response, out duration, out sense, 0); + if(!sense) + { + cachedCsd = new byte[16]; + Array.Copy(sdBuffer, 0, cachedCsd, 0, 16); + } - if(!sense) - { - cachedScr = new byte[8]; - Array.Copy(sdBuffer, 0, cachedScr, 0, 8); - } + sdBuffer = new byte[16]; + sense = false; - if(cachedScr != null) - { - sdBuffer = new byte[4]; + lastError = Windows.Command.SendMmcCommand((SafeFileHandle)fd, MmcCommands.SendCid, false, false, + MmcFlags.ResponseSpiR2 | MmcFlags.ResponseR2 | + MmcFlags.CommandAc, 0, 16, 1, ref sdBuffer, out response, + out duration, out sense, 0); + + if(!sense) + { + cachedCid = new byte[16]; + Array.Copy(sdBuffer, 0, cachedCid, 0, 16); + } + + sdBuffer = new byte[8]; sense = false; lastError = Windows.Command.SendMmcCommand((SafeFileHandle)fd, - (MmcCommands)SecureDigitalCommands - .SendOperatingCondition, false, true, - MmcFlags.ResponseSpiR3 | MmcFlags.ResponseR3 | - MmcFlags.CommandBcr, 0, 4, 1, ref sdBuffer, + (MmcCommands)SecureDigitalCommands.SendScr, false, true, + MmcFlags.ResponseSpiR1 | MmcFlags.ResponseR1 | + MmcFlags.CommandAdtc, 0, 8, 1, ref sdBuffer, out response, out duration, out sense, 0); if(!sense) { - cachedScr = new byte[4]; - Array.Copy(sdBuffer, 0, cachedScr, 0, 4); + cachedScr = new byte[8]; + Array.Copy(sdBuffer, 0, cachedScr, 0, 8); } - } - else - { - sdBuffer = new byte[4]; - sense = false; - lastError = Windows.Command.SendMmcCommand((SafeFileHandle)fd, MmcCommands.SendOpCond, false, - true, - MmcFlags.ResponseSpiR3 | MmcFlags.ResponseR3 | - MmcFlags.CommandBcr, 0, 4, 1, ref sdBuffer, - out response, out duration, out sense, 0); - - if(!sense) + if(cachedScr != null) { - cachedScr = new byte[4]; - Array.Copy(sdBuffer, 0, cachedScr, 0, 4); + sdBuffer = new byte[4]; + sense = false; + + lastError = Windows.Command.SendMmcCommand((SafeFileHandle)fd, + (MmcCommands)SecureDigitalCommands + .SendOperatingCondition, false, true, + MmcFlags.ResponseSpiR3 | MmcFlags.ResponseR3 | + MmcFlags.CommandBcr, 0, 4, 1, ref sdBuffer, + out response, out duration, out sense, 0); + + if(!sense) + { + cachedScr = new byte[4]; + Array.Copy(sdBuffer, 0, cachedScr, 0, 4); + } + } + else + { + sdBuffer = new byte[4]; + sense = false; + + lastError = Windows.Command.SendMmcCommand((SafeFileHandle)fd, MmcCommands.SendOpCond, false, + true, + MmcFlags.ResponseSpiR3 | MmcFlags.ResponseR3 | + MmcFlags.CommandBcr, 0, 4, 1, ref sdBuffer, + out response, out duration, out sense, 0); + + if(!sense) + { + cachedScr = new byte[4]; + Array.Copy(sdBuffer, 0, cachedScr, 0, 4); + } } } - } + break; + case Interop.PlatformID.Linux: + if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) || + devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) || + devicePath.StartsWith("/dev/st", StringComparison.Ordinal)) + scsiSense = ScsiInquiry(out inqBuf, out senseBuf); + // MultiMediaCard and SecureDigital go here + else if(devicePath.StartsWith("/dev/mmcblk", StringComparison.Ordinal)) + { + string devPath = devicePath.Substring(5); + if(System.IO.File.Exists("/sys/block/" + devPath + "/device/csd")) + { + int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/csd", out cachedCsd); + if(len == 0) cachedCsd = null; + } + if(System.IO.File.Exists("/sys/block/" + devPath + "/device/cid")) + { + int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/cid", out cachedCid); + if(len == 0) cachedCid = null; + } + if(System.IO.File.Exists("/sys/block/" + devPath + "/device/scr")) + { + int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/scr", out cachedScr); + if(len == 0) cachedScr = null; + } + if(System.IO.File.Exists("/sys/block/" + devPath + "/device/ocr")) + { + int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/ocr", out cachedOcr); + if(len == 0) cachedOcr = null; + } + } + break; + default: scsiSense = ScsiInquiry(out inqBuf, out senseBuf); + break; } - else if(platformId == Interop.PlatformID.Linux) - { - if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) || - devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) || - devicePath.StartsWith("/dev/st", StringComparison.Ordinal)) - scsiSense = ScsiInquiry(out inqBuf, out senseBuf); - // MultiMediaCard and SecureDigital go here - else if(devicePath.StartsWith("/dev/mmcblk", StringComparison.Ordinal)) - { - string devPath = devicePath.Substring(5); - if(System.IO.File.Exists("/sys/block/" + devPath + "/device/csd")) - { - int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/csd", out cachedCsd); - if(len == 0) cachedCsd = null; - } - if(System.IO.File.Exists("/sys/block/" + devPath + "/device/cid")) - { - int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/cid", out cachedCid); - if(len == 0) cachedCid = null; - } - if(System.IO.File.Exists("/sys/block/" + devPath + "/device/scr")) - { - int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/scr", out cachedScr); - if(len == 0) cachedScr = null; - } - if(System.IO.File.Exists("/sys/block/" + devPath + "/device/ocr")) - { - int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/ocr", out cachedOcr); - if(len == 0) cachedOcr = null; - } - } - } - else scsiSense = ScsiInquiry(out inqBuf, out senseBuf); #region SecureDigital / MultiMediaCard if(cachedCid != null) @@ -365,106 +368,107 @@ namespace DiscImageChef.Devices #endregion SecureDigital / MultiMediaCard #region USB - if(platformId == Interop.PlatformID.Linux) - { - if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) || - devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) || - devicePath.StartsWith("/dev/st", StringComparison.Ordinal)) - { - string devPath = devicePath.Substring(5); - if(System.IO.Directory.Exists("/sys/block/" + devPath)) + switch(platformId) { + case Interop.PlatformID.Linux: + if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) || + devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) || + devicePath.StartsWith("/dev/st", StringComparison.Ordinal)) { - string resolvedLink = Linux.Command.ReadLink("/sys/block/" + devPath); - resolvedLink = "/sys" + resolvedLink.Substring(2); - if(!string.IsNullOrEmpty(resolvedLink)) - while(resolvedLink.Contains("usb")) - { - resolvedLink = System.IO.Path.GetDirectoryName(resolvedLink); - if(System.IO.File.Exists(resolvedLink + "/descriptors") && - System.IO.File.Exists(resolvedLink + "/idProduct") && - System.IO.File.Exists(resolvedLink + "/idVendor")) + string devPath = devicePath.Substring(5); + if(System.IO.Directory.Exists("/sys/block/" + devPath)) + { + string resolvedLink = Linux.Command.ReadLink("/sys/block/" + devPath); + resolvedLink = "/sys" + resolvedLink.Substring(2); + if(!string.IsNullOrEmpty(resolvedLink)) + while(resolvedLink.Contains("usb")) { - System.IO.FileStream usbFs; - System.IO.StreamReader usbSr; - string usbTemp; - - usbFs = new System.IO.FileStream(resolvedLink + "/descriptors", - System.IO.FileMode.Open, - System.IO.FileAccess.Read); - byte[] usbBuf = new byte[65536]; - int usbCount = usbFs.Read(usbBuf, 0, 65536); - usbDescriptors = new byte[usbCount]; - Array.Copy(usbBuf, 0, usbDescriptors, 0, usbCount); - usbFs.Close(); - - usbSr = new System.IO.StreamReader(resolvedLink + "/idProduct"); - usbTemp = usbSr.ReadToEnd(); - ushort.TryParse(usbTemp, System.Globalization.NumberStyles.HexNumber, - System.Globalization.CultureInfo.InvariantCulture, out usbProduct); - usbSr.Close(); - - usbSr = new System.IO.StreamReader(resolvedLink + "/idVendor"); - usbTemp = usbSr.ReadToEnd(); - ushort.TryParse(usbTemp, System.Globalization.NumberStyles.HexNumber, - System.Globalization.CultureInfo.InvariantCulture, out usbVendor); - usbSr.Close(); - - if(System.IO.File.Exists(resolvedLink + "/manufacturer")) + resolvedLink = System.IO.Path.GetDirectoryName(resolvedLink); + if(System.IO.File.Exists(resolvedLink + "/descriptors") && + System.IO.File.Exists(resolvedLink + "/idProduct") && + System.IO.File.Exists(resolvedLink + "/idVendor")) { - usbSr = new System.IO.StreamReader(resolvedLink + "/manufacturer"); - usbManufacturerString = usbSr.ReadToEnd().Trim(); - usbSr.Close(); - } + System.IO.FileStream usbFs; + System.IO.StreamReader usbSr; + string usbTemp; - if(System.IO.File.Exists(resolvedLink + "/product")) - { - usbSr = new System.IO.StreamReader(resolvedLink + "/product"); - usbProductString = usbSr.ReadToEnd().Trim(); - usbSr.Close(); - } + usbFs = new System.IO.FileStream(resolvedLink + "/descriptors", + System.IO.FileMode.Open, + System.IO.FileAccess.Read); + byte[] usbBuf = new byte[65536]; + int usbCount = usbFs.Read(usbBuf, 0, 65536); + usbDescriptors = new byte[usbCount]; + Array.Copy(usbBuf, 0, usbDescriptors, 0, usbCount); + usbFs.Close(); - if(System.IO.File.Exists(resolvedLink + "/serial")) - { - usbSr = new System.IO.StreamReader(resolvedLink + "/serial"); - usbSerialString = usbSr.ReadToEnd().Trim(); + usbSr = new System.IO.StreamReader(resolvedLink + "/idProduct"); + usbTemp = usbSr.ReadToEnd(); + ushort.TryParse(usbTemp, System.Globalization.NumberStyles.HexNumber, + System.Globalization.CultureInfo.InvariantCulture, out usbProduct); usbSr.Close(); - } - usb = true; - break; + usbSr = new System.IO.StreamReader(resolvedLink + "/idVendor"); + usbTemp = usbSr.ReadToEnd(); + ushort.TryParse(usbTemp, System.Globalization.NumberStyles.HexNumber, + System.Globalization.CultureInfo.InvariantCulture, out usbVendor); + usbSr.Close(); + + if(System.IO.File.Exists(resolvedLink + "/manufacturer")) + { + usbSr = new System.IO.StreamReader(resolvedLink + "/manufacturer"); + usbManufacturerString = usbSr.ReadToEnd().Trim(); + usbSr.Close(); + } + + if(System.IO.File.Exists(resolvedLink + "/product")) + { + usbSr = new System.IO.StreamReader(resolvedLink + "/product"); + usbProductString = usbSr.ReadToEnd().Trim(); + usbSr.Close(); + } + + if(System.IO.File.Exists(resolvedLink + "/serial")) + { + usbSr = new System.IO.StreamReader(resolvedLink + "/serial"); + usbSerialString = usbSr.ReadToEnd().Trim(); + usbSr.Close(); + } + + usb = true; + break; + } } - } + } } - } - } - else if(platformId == Interop.PlatformID.Win32NT) - { - Windows.Usb.UsbDevice usbDevice = null; - // I have to search for USB disks, floppies and CD-ROMs as separate device types - foreach(string devGuid in new[] - { - Windows.Usb.GuidDevinterfaceFloppy, Windows.Usb.GuidDevinterfaceCdrom, - Windows.Usb.GuidDevinterfaceDisk - }) - { - usbDevice = Windows.Usb.FindDrivePath(devicePath, devGuid); - if(usbDevice != null) break; - } + break; + case Interop.PlatformID.Win32NT: + Windows.Usb.UsbDevice usbDevice = null; - if(usbDevice != null) - { - usbDescriptors = usbDevice.BinaryDescriptors; - usbVendor = (ushort)usbDevice.DeviceDescriptor.idVendor; - usbProduct = (ushort)usbDevice.DeviceDescriptor.idProduct; - usbManufacturerString = usbDevice.Manufacturer; - usbProductString = usbDevice.Product; - usbSerialString = - usbDevice.SerialNumber; // This is incorrect filled by Windows with SCSI/ATA serial number - } + // I have to search for USB disks, floppies and CD-ROMs as separate device types + foreach(string devGuid in new[] + { + Windows.Usb.GuidDevinterfaceFloppy, Windows.Usb.GuidDevinterfaceCdrom, + Windows.Usb.GuidDevinterfaceDisk + }) + { + usbDevice = Windows.Usb.FindDrivePath(devicePath, devGuid); + if(usbDevice != null) break; + } + + if(usbDevice != null) + { + usbDescriptors = usbDevice.BinaryDescriptors; + usbVendor = (ushort)usbDevice.DeviceDescriptor.idVendor; + usbProduct = (ushort)usbDevice.DeviceDescriptor.idProduct; + usbManufacturerString = usbDevice.Manufacturer; + usbProductString = usbDevice.Product; + usbSerialString = + usbDevice.SerialNumber; // This is incorrect filled by Windows with SCSI/ATA serial number + } + break; + default: usb = false; + break; } - // TODO: Implement for other operating systems - else usb = false; #endregion USB #region FireWire diff --git a/DiscImageChef.Devices/Windows/Command.cs b/DiscImageChef.Devices/Windows/Command.cs index b0d95e80f..59e96541d 100644 --- a/DiscImageChef.Devices/Windows/Command.cs +++ b/DiscImageChef.Devices/Windows/Command.cs @@ -139,10 +139,15 @@ namespace DiscImageChef.Devices.Windows dataBuffer = new byte[64 * 512] }; - if(protocol == AtaProtocol.PioIn || protocol == AtaProtocol.UDmaIn || protocol == AtaProtocol.Dma) - aptdBuf.aptd.AtaFlags = AtaFlags.DataIn; - else if(protocol == AtaProtocol.PioOut || protocol == AtaProtocol.UDmaOut) - aptdBuf.aptd.AtaFlags = AtaFlags.DataOut; + switch(protocol) { + case AtaProtocol.PioIn: + case AtaProtocol.UDmaIn: + case AtaProtocol.Dma: aptdBuf.aptd.AtaFlags = AtaFlags.DataIn; + break; + case AtaProtocol.PioOut: + case AtaProtocol.UDmaOut: aptdBuf.aptd.AtaFlags = AtaFlags.DataOut; + break; + } switch(protocol) { @@ -224,10 +229,15 @@ namespace DiscImageChef.Devices.Windows dataBuffer = new byte[64 * 512] }; - if(protocol == AtaProtocol.PioIn || protocol == AtaProtocol.UDmaIn || protocol == AtaProtocol.Dma) - aptdBuf.aptd.AtaFlags = AtaFlags.DataIn; - else if(protocol == AtaProtocol.PioOut || protocol == AtaProtocol.UDmaOut) - aptdBuf.aptd.AtaFlags = AtaFlags.DataOut; + switch(protocol) { + case AtaProtocol.PioIn: + case AtaProtocol.UDmaIn: + case AtaProtocol.Dma: aptdBuf.aptd.AtaFlags = AtaFlags.DataIn; + break; + case AtaProtocol.PioOut: + case AtaProtocol.UDmaOut: aptdBuf.aptd.AtaFlags = AtaFlags.DataOut; + break; + } switch(protocol) { @@ -317,10 +327,15 @@ namespace DiscImageChef.Devices.Windows dataBuffer = new byte[64 * 512] }; - if(protocol == AtaProtocol.PioIn || protocol == AtaProtocol.UDmaIn || protocol == AtaProtocol.Dma) - aptdBuf.aptd.AtaFlags = AtaFlags.DataIn; - else if(protocol == AtaProtocol.PioOut || protocol == AtaProtocol.UDmaOut) - aptdBuf.aptd.AtaFlags = AtaFlags.DataOut; + switch(protocol) { + case AtaProtocol.PioIn: + case AtaProtocol.UDmaIn: + case AtaProtocol.Dma: aptdBuf.aptd.AtaFlags = AtaFlags.DataIn; + break; + case AtaProtocol.PioOut: + case AtaProtocol.UDmaOut: aptdBuf.aptd.AtaFlags = AtaFlags.DataOut; + break; + } switch(protocol) { diff --git a/DiscImageChef.DiscImages/Anex86.cs b/DiscImageChef.DiscImages/Anex86.cs index ad02f784d..a9f748042 100644 --- a/DiscImageChef.DiscImages/Anex86.cs +++ b/DiscImageChef.DiscImages/Anex86.cs @@ -145,12 +145,20 @@ namespace DiscImageChef.DiscImages switch(fdihdr.spt) { case 8: - if(fdihdr.heads == 1) ImageInfo.MediaType = MediaType.DOS_525_SS_DD_8; - else if(fdihdr.heads == 2) ImageInfo.MediaType = MediaType.DOS_525_DS_DD_8; + switch(fdihdr.heads) { + case 1: ImageInfo.MediaType = MediaType.DOS_525_SS_DD_8; + break; + case 2: ImageInfo.MediaType = MediaType.DOS_525_DS_DD_8; + break; + } break; case 9: - if(fdihdr.heads == 1) ImageInfo.MediaType = MediaType.DOS_525_SS_DD_9; - else if(fdihdr.heads == 2) ImageInfo.MediaType = MediaType.DOS_525_DS_DD_9; + switch(fdihdr.heads) { + case 1: ImageInfo.MediaType = MediaType.DOS_525_SS_DD_9; + break; + case 2: ImageInfo.MediaType = MediaType.DOS_525_DS_DD_9; + break; + } break; } @@ -222,8 +230,12 @@ namespace DiscImageChef.DiscImages switch(fdihdr.spt) { case 16: - if(fdihdr.heads == 1) ImageInfo.MediaType = MediaType.NEC_525_SS; - else if(fdihdr.heads == 2) ImageInfo.MediaType = MediaType.NEC_525_DS; + switch(fdihdr.heads) { + case 1: ImageInfo.MediaType = MediaType.NEC_525_SS; + break; + case 2: ImageInfo.MediaType = MediaType.NEC_525_DS; + break; + } break; } @@ -232,12 +244,20 @@ namespace DiscImageChef.DiscImages switch(fdihdr.spt) { case 8: - if(fdihdr.heads == 1) ImageInfo.MediaType = MediaType.DOS_35_SS_DD_8; - else if(fdihdr.heads == 2) ImageInfo.MediaType = MediaType.DOS_35_DS_DD_8; + switch(fdihdr.heads) { + case 1: ImageInfo.MediaType = MediaType.DOS_35_SS_DD_8; + break; + case 2: ImageInfo.MediaType = MediaType.DOS_35_DS_DD_8; + break; + } break; case 9: - if(fdihdr.heads == 1) ImageInfo.MediaType = MediaType.DOS_35_SS_DD_9; - else if(fdihdr.heads == 2) ImageInfo.MediaType = MediaType.DOS_35_DS_DD_9; + switch(fdihdr.heads) { + case 1: ImageInfo.MediaType = MediaType.DOS_35_SS_DD_9; + break; + case 2: ImageInfo.MediaType = MediaType.DOS_35_DS_DD_9; + break; + } break; case 15: if(fdihdr.heads == 2) ImageInfo.MediaType = MediaType.NEC_35_HD_15; diff --git a/DiscImageChef.DiscImages/Apple2MG.cs b/DiscImageChef.DiscImages/Apple2MG.cs index 8c5c764bf..9cd520b31 100644 --- a/DiscImageChef.DiscImages/Apple2MG.cs +++ b/DiscImageChef.DiscImages/Apple2MG.cs @@ -288,13 +288,17 @@ namespace DiscImageChef.DiscImages if(imageHeader.DataSize == 0 && imageHeader.Blocks == 0 && imageHeader.ImageFormat != PRODOS_SECTOR_ORDER) return false; - if(imageHeader.ImageFormat == PRODOS_SECTOR_ORDER && imageHeader.Blocks == 0) return false; - - if(imageHeader.ImageFormat == PRODOS_SECTOR_ORDER) imageHeader.DataSize = imageHeader.Blocks * 512; - else if(imageHeader.Blocks == 0 && imageHeader.DataSize != 0) - imageHeader.Blocks = imageHeader.DataSize / 256; - else if(imageHeader.DataSize == 0 && imageHeader.Blocks != 0) - imageHeader.DataSize = imageHeader.Blocks * 256; + switch(imageHeader.ImageFormat) { + case PRODOS_SECTOR_ORDER when imageHeader.Blocks == 0: return false; + case PRODOS_SECTOR_ORDER: imageHeader.DataSize = imageHeader.Blocks * 512; + break; + default: + if(imageHeader.Blocks == 0 && imageHeader.DataSize != 0) + imageHeader.Blocks = imageHeader.DataSize / 256; + else if(imageHeader.DataSize == 0 && imageHeader.Blocks != 0) + imageHeader.DataSize = imageHeader.Blocks * 256; + break; + } ImageInfo.SectorSize = (uint)(imageHeader.ImageFormat == PRODOS_SECTOR_ORDER ? 512 : 256); diff --git a/DiscImageChef.DiscImages/BlindWrite5.cs b/DiscImageChef.DiscImages/BlindWrite5.cs index 86460bbc8..c65a75415 100644 --- a/DiscImageChef.DiscImages/BlindWrite5.cs +++ b/DiscImageChef.DiscImages/BlindWrite5.cs @@ -735,12 +735,14 @@ namespace DiscImageChef.DiscImages long sectorSize = dataFile.Length / dataFile.Sectors; if(sectorSize > 2352) - if(sectorSize - 2352 == 16) chars.Subchannel = TrackSubchannelType.Q16Interleaved; - else if(sectorSize - 2352 == 96) chars.Subchannel = TrackSubchannelType.PackedInterleaved; - else - { - DicConsole.ErrorWriteLine("BlindWrite5 found unknown subchannel size: {0}", sectorSize - 2352); - return false; + switch(sectorSize - 2352) { + case 16: chars.Subchannel = TrackSubchannelType.Q16Interleaved; + break; + case 96: chars.Subchannel = TrackSubchannelType.PackedInterleaved; + break; + default: + DicConsole.ErrorWriteLine("BlindWrite5 found unknown subchannel size: {0}", sectorSize - 2352); + return false; } else chars.Subchannel = TrackSubchannelType.None; @@ -1114,8 +1116,12 @@ namespace DiscImageChef.DiscImages if(isBd && ImageInfo.Sectors > 24438784) { - if(ImageInfo.MediaType == MediaType.BDR) ImageInfo.MediaType = MediaType.BDRXL; - if(ImageInfo.MediaType == MediaType.BDRE) ImageInfo.MediaType = MediaType.BDREXL; + switch(ImageInfo.MediaType) { + case MediaType.BDR: ImageInfo.MediaType = MediaType.BDRXL; + break; + case MediaType.BDRE: ImageInfo.MediaType = MediaType.BDREXL; + break; + } } DicConsole.DebugWriteLine("BlindWrite5 plugin", "ImageInfo.mediaType = {0}", ImageInfo.MediaType); diff --git a/DiscImageChef.DiscImages/CHD.cs b/DiscImageChef.DiscImages/CHD.cs index 5dc471dd9..3b7646839 100644 --- a/DiscImageChef.DiscImages/CHD.cs +++ b/DiscImageChef.DiscImages/CHD.cs @@ -2038,17 +2038,17 @@ namespace DiscImageChef.DiscImages uint sector_size; if(tag == SectorTagType.CdSectorSubchannel) - if(track.TrackSubchannelType == TrackSubchannelType.None) - throw new FeatureNotPresentImageException("Requested sector does not contain subchannel"); - else if(track.TrackSubchannelType == TrackSubchannelType.RawInterleaved) - { - sector_offset = (uint)track.TrackRawBytesPerSector; - sector_size = 96; + switch(track.TrackSubchannelType) { + case TrackSubchannelType.None: throw new FeatureNotPresentImageException("Requested sector does not contain subchannel"); + case TrackSubchannelType.RawInterleaved: + sector_offset = (uint)track.TrackRawBytesPerSector; + sector_size = 96; + break; + default: + throw new + FeatureSupportedButNotImplementedImageException(string.Format("Unsupported subchannel type {0}", + track.TrackSubchannelType)); } - else - throw new - FeatureSupportedButNotImplementedImageException(string.Format("Unsupported subchannel type {0}", - track.TrackSubchannelType)); else switch(track.TrackType) { diff --git a/DiscImageChef.DiscImages/D88.cs b/DiscImageChef.DiscImages/D88.cs index 00d589a25..3464a220a 100644 --- a/DiscImageChef.DiscImages/D88.cs +++ b/DiscImageChef.DiscImages/D88.cs @@ -407,9 +407,14 @@ namespace DiscImageChef.DiscImages ImageInfo.MediaType = MediaType.NEC_8_SD; else if(bps == IBMSectorSizeCode.QuarterKilo) { - if(trkCounter == 80 && spt == 16) ImageInfo.MediaType = MediaType.NEC_525_SS; - else if(trkCounter == 154 && spt == 26) ImageInfo.MediaType = MediaType.NEC_8_DD; - else if(trkCounter == 160 && spt == 16) ImageInfo.MediaType = MediaType.NEC_525_DS; + switch(trkCounter) { + case 80 when spt == 16: ImageInfo.MediaType = MediaType.NEC_525_SS; + break; + case 154 when spt == 26: ImageInfo.MediaType = MediaType.NEC_8_DD; + break; + case 160 when spt == 16: ImageInfo.MediaType = MediaType.NEC_525_DS; + break; + } } else if(trkCounter == 154 && spt == 8 && bps == IBMSectorSizeCode.Kilo) ImageInfo.MediaType = MediaType.NEC_525_HD; diff --git a/DiscImageChef.DiscImages/DiscJuggler.cs b/DiscImageChef.DiscImages/DiscJuggler.cs index 5d04a45c2..1fe6e1382 100644 --- a/DiscImageChef.DiscImages/DiscJuggler.cs +++ b/DiscImageChef.DiscImages/DiscJuggler.cs @@ -927,10 +927,10 @@ namespace DiscImageChef.DiscImages break; } case SectorTagType.CdSectorSubchannel: - if(_track.TrackSubchannelType == TrackSubchannelType.None) - throw new ArgumentException("Unsupported tag requested for this track", nameof(tag)); - if(_track.TrackSubchannelType == TrackSubchannelType.Q16Interleaved) - throw new ArgumentException("Q16 subchannel not yet supported"); + switch(_track.TrackSubchannelType) { + case TrackSubchannelType.None: throw new ArgumentException("Unsupported tag requested for this track", nameof(tag)); + case TrackSubchannelType.Q16Interleaved: throw new ArgumentException("Q16 subchannel not yet supported"); + } sectorOffset = 2352; sectorSize = 96; @@ -968,10 +968,10 @@ namespace DiscImageChef.DiscImages break; } case SectorTagType.CdSectorSubchannel: - if(_track.TrackSubchannelType == TrackSubchannelType.None) - throw new ArgumentException("Unsupported tag requested for this track", nameof(tag)); - if(_track.TrackSubchannelType == TrackSubchannelType.Q16Interleaved) - throw new ArgumentException("Q16 subchannel not yet supported"); + switch(_track.TrackSubchannelType) { + case TrackSubchannelType.None: throw new ArgumentException("Unsupported tag requested for this track", nameof(tag)); + case TrackSubchannelType.Q16Interleaved: throw new ArgumentException("Q16 subchannel not yet supported"); + } sectorOffset = 2352; sectorSize = 96; @@ -987,10 +987,10 @@ namespace DiscImageChef.DiscImages switch(tag) { case SectorTagType.CdSectorSubchannel: - if(_track.TrackSubchannelType == TrackSubchannelType.None) - throw new ArgumentException("Unsupported tag requested for this track", nameof(tag)); - if(_track.TrackSubchannelType == TrackSubchannelType.Q16Interleaved) - throw new ArgumentException("Q16 subchannel not yet supported"); + switch(_track.TrackSubchannelType) { + case TrackSubchannelType.None: throw new ArgumentException("Unsupported tag requested for this track", nameof(tag)); + case TrackSubchannelType.Q16Interleaved: throw new ArgumentException("Q16 subchannel not yet supported"); + } sectorOffset = 2352; sectorSize = 96; diff --git a/DiscImageChef.DiscImages/KryoFlux.cs b/DiscImageChef.DiscImages/KryoFlux.cs index 5a072c14e..8ce3d0d23 100644 --- a/DiscImageChef.DiscImages/KryoFlux.cs +++ b/DiscImageChef.DiscImages/KryoFlux.cs @@ -292,17 +292,21 @@ namespace DiscImageChef.DiscImages kvp[1] = kvp[1].Trim(); DicConsole.DebugWriteLine("KryoFlux plugin", "\"{0}\" = \"{1}\"", kvp[0], kvp[1]); - if(kvp[0] == hostDate) - { - if(DateTime.TryParseExact(kvp[1], "yyyy.MM.dd", CultureInfo.InvariantCulture, - DateTimeStyles.AssumeLocal, out blockDate)) - foundDate = true; + switch(kvp[0]) { + case hostDate: + if(DateTime.TryParseExact(kvp[1], "yyyy.MM.dd", CultureInfo.InvariantCulture, + DateTimeStyles.AssumeLocal, out blockDate)) + foundDate = true; + break; + case hostTime: + DateTime.TryParseExact(kvp[1], "HH:mm:ss", CultureInfo.InvariantCulture, + DateTimeStyles.AssumeLocal, out blockTime); + break; + case kfName: ImageInfo.ImageApplication = kvp[1]; + break; + case kfVersion: ImageInfo.ImageApplicationVersion = kvp[1]; + break; } - else if(kvp[0] == hostTime) - DateTime.TryParseExact(kvp[1], "HH:mm:ss", CultureInfo.InvariantCulture, - DateTimeStyles.AssumeLocal, out blockTime); - else if(kvp[0] == kfName) ImageInfo.ImageApplication = kvp[1]; - else if(kvp[0] == kfVersion) ImageInfo.ImageApplicationVersion = kvp[1]; } if(foundDate) diff --git a/DiscImageChef.DiscImages/NDIF.cs b/DiscImageChef.DiscImages/NDIF.cs index 8f5044230..1a32fb284 100644 --- a/DiscImageChef.DiscImages/NDIF.cs +++ b/DiscImageChef.DiscImages/NDIF.cs @@ -325,14 +325,12 @@ namespace DiscImageChef.DiscImages bChnk.sector += (uint)ImageInfo.Sectors; // TODO: Handle compressed chunks - if(bChnk.type == CHUNK_TYPE_KENCODE) - throw new ImageNotSupportedException("Chunks compressed with KenCode are not yet supported."); - if(bChnk.type == CHUNK_TYPE_RLE) - throw new ImageNotSupportedException("Chunks compressed with RLE are not yet supported."); - if(bChnk.type == CHUNK_TYPE_LZH) - throw new ImageNotSupportedException("Chunks compressed with LZH are not yet supported."); - if(bChnk.type == CHUNK_TYPE_STUFFIT) - throw new ImageNotSupportedException("Chunks compressed with StuffIt! are not yet supported."); + switch(bChnk.type) { + case CHUNK_TYPE_KENCODE: throw new ImageNotSupportedException("Chunks compressed with KenCode are not yet supported."); + case CHUNK_TYPE_RLE: throw new ImageNotSupportedException("Chunks compressed with RLE are not yet supported."); + case CHUNK_TYPE_LZH: throw new ImageNotSupportedException("Chunks compressed with LZH are not yet supported."); + case CHUNK_TYPE_STUFFIT: throw new ImageNotSupportedException("Chunks compressed with StuffIt! are not yet supported."); + } // TODO: Handle compressed chunks if(bChnk.type > CHUNK_TYPE_COPY && bChnk.type < CHUNK_TYPE_KENCODE || @@ -543,26 +541,23 @@ namespace DiscImageChef.DiscImages return sector; } - if(currentChunk.type == CHUNK_TYPE_NOCOPY) - { - sector = new byte[SECTOR_SIZE]; + switch(currentChunk.type) { + case CHUNK_TYPE_NOCOPY: + sector = new byte[SECTOR_SIZE]; - if(sectorCache.Count >= maxCachedSectors) sectorCache.Clear(); + if(sectorCache.Count >= maxCachedSectors) sectorCache.Clear(); - sectorCache.Add(sectorAddress, sector); - return sector; - } + sectorCache.Add(sectorAddress, sector); + return sector; + case CHUNK_TYPE_COPY: + imageStream.Seek(currentChunk.offset + relOff, SeekOrigin.Begin); + sector = new byte[SECTOR_SIZE]; + imageStream.Read(sector, 0, sector.Length); - if(currentChunk.type == CHUNK_TYPE_COPY) - { - imageStream.Seek(currentChunk.offset + relOff, SeekOrigin.Begin); - sector = new byte[SECTOR_SIZE]; - imageStream.Read(sector, 0, sector.Length); + if(sectorCache.Count >= maxCachedSectors) sectorCache.Clear(); - if(sectorCache.Count >= maxCachedSectors) sectorCache.Clear(); - - sectorCache.Add(sectorAddress, sector); - return sector; + sectorCache.Add(sectorAddress, sector); + return sector; } throw new ImageNotSupportedException(string.Format("Unsupported chunk type 0x{0:X8} found", diff --git a/DiscImageChef.DiscImages/UDIF.cs b/DiscImageChef.DiscImages/UDIF.cs index 32cfc533a..4183e5b45 100644 --- a/DiscImageChef.DiscImages/UDIF.cs +++ b/DiscImageChef.DiscImages/UDIF.cs @@ -461,19 +461,17 @@ namespace DiscImageChef.DiscImages bChnk.sector += bHdr.sectorStart; bChnk.offset += bHdr.dataOffset; - // TODO: Handle comments - if(bChnk.type == CHUNK_TYPE_COMMNT) continue; - - // TODO: Handle compressed chunks - if(bChnk.type == CHUNK_TYPE_KENCODE) - throw new - ImageNotSupportedException("Chunks compressed with KenCode are not yet supported."); - if(bChnk.type == CHUNK_TYPE_RLE) - throw new ImageNotSupportedException("Chunks compressed with RLE are not yet supported."); - if(bChnk.type == CHUNK_TYPE_LZH) - throw new ImageNotSupportedException("Chunks compressed with LZH are not yet supported."); - if(bChnk.type == CHUNK_TYPE_LZFSE) - throw new ImageNotSupportedException("Chunks compressed with lzfse are not yet supported."); + switch(bChnk.type) { + // TODO: Handle comments + case CHUNK_TYPE_COMMNT: continue; + // TODO: Handle compressed chunks + case CHUNK_TYPE_KENCODE: + throw new + ImageNotSupportedException("Chunks compressed with KenCode are not yet supported."); + case CHUNK_TYPE_RLE: throw new ImageNotSupportedException("Chunks compressed with RLE are not yet supported."); + case CHUNK_TYPE_LZH: throw new ImageNotSupportedException("Chunks compressed with LZH are not yet supported."); + case CHUNK_TYPE_LZFSE: throw new ImageNotSupportedException("Chunks compressed with lzfse are not yet supported."); + } if(bChnk.type > CHUNK_TYPE_NOCOPY && bChnk.type < CHUNK_TYPE_COMMNT || bChnk.type > CHUNK_TYPE_LZFSE && bChnk.type < CHUNK_TYPE_END) @@ -551,14 +549,17 @@ namespace DiscImageChef.DiscImages MemoryStream cmpMs = new MemoryStream(cmpBuffer); Stream decStream; - if(currentChunk.type == CHUNK_TYPE_ADC) decStream = new ADCStream(cmpMs, CompressionMode.Decompress); - else if(currentChunk.type == CHUNK_TYPE_ZLIB) - decStream = new Ionic.Zlib.ZlibStream(cmpMs, Ionic.Zlib.CompressionMode.Decompress); - else if(currentChunk.type == CHUNK_TYPE_BZIP) - decStream = new BZip2Stream(cmpMs, CompressionMode.Decompress); - else - throw new ImageNotSupportedException(string.Format("Unsupported chunk type 0x{0:X8} found", - currentChunk.type)); + switch(currentChunk.type) { + case CHUNK_TYPE_ADC: decStream = new ADCStream(cmpMs, CompressionMode.Decompress); + break; + case CHUNK_TYPE_ZLIB: decStream = new Ionic.Zlib.ZlibStream(cmpMs, Ionic.Zlib.CompressionMode.Decompress); + break; + case CHUNK_TYPE_BZIP: decStream = new BZip2Stream(cmpMs, CompressionMode.Decompress); + break; + default: + throw new ImageNotSupportedException(string.Format("Unsupported chunk type 0x{0:X8} found", + currentChunk.type)); + } #if DEBUG try @@ -598,26 +599,24 @@ namespace DiscImageChef.DiscImages return sector; } - if(currentChunk.type == CHUNK_TYPE_NOCOPY || currentChunk.type == CHUNK_TYPE_ZERO) - { - sector = new byte[SECTOR_SIZE]; + switch(currentChunk.type) { + case CHUNK_TYPE_NOCOPY: + case CHUNK_TYPE_ZERO: + sector = new byte[SECTOR_SIZE]; - if(sectorCache.Count >= maxCachedSectors) sectorCache.Clear(); + if(sectorCache.Count >= maxCachedSectors) sectorCache.Clear(); - sectorCache.Add(sectorAddress, sector); - return sector; - } + sectorCache.Add(sectorAddress, sector); + return sector; + case CHUNK_TYPE_COPY: + imageStream.Seek((long)currentChunk.offset + relOff, SeekOrigin.Begin); + sector = new byte[SECTOR_SIZE]; + imageStream.Read(sector, 0, sector.Length); - if(currentChunk.type == CHUNK_TYPE_COPY) - { - imageStream.Seek((long)currentChunk.offset + relOff, SeekOrigin.Begin); - sector = new byte[SECTOR_SIZE]; - imageStream.Read(sector, 0, sector.Length); + if(sectorCache.Count >= maxCachedSectors) sectorCache.Clear(); - if(sectorCache.Count >= maxCachedSectors) sectorCache.Clear(); - - sectorCache.Add(sectorAddress, sector); - return sector; + sectorCache.Add(sectorAddress, sector); + return sector; } throw new ImageNotSupportedException(string.Format("Unsupported chunk type 0x{0:X8} found", diff --git a/DiscImageChef.DiscImages/VHDX.cs b/DiscImageChef.DiscImages/VHDX.cs index 7c4e5c331..36777bf0e 100644 --- a/DiscImageChef.DiscImages/VHDX.cs +++ b/DiscImageChef.DiscImages/VHDX.cs @@ -694,19 +694,24 @@ namespace DiscImageChef.DiscImages MemoryStream sectorBmpMs = new MemoryStream(); foreach(ulong pt in sectorBitmapPointers) - if((pt & BAT_FLAGS_MASK) == SECTOR_BITMAP_NOT_PRESENT) sectorBmpMs.Write(new byte[1048576], 0, 1048576); - else if((pt & BAT_FLAGS_MASK) == SECTOR_BITMAP_PRESENT) - { - stream.Seek((long)((pt & BAT_FILE_OFFSET_MASK) * 1048576), SeekOrigin.Begin); - byte[] bmp = new byte[1048576]; - stream.Read(bmp, 0, bmp.Length); - sectorBmpMs.Write(bmp, 0, bmp.Length); + switch(pt & BAT_FLAGS_MASK) { + case SECTOR_BITMAP_NOT_PRESENT: sectorBmpMs.Write(new byte[1048576], 0, 1048576); + break; + case SECTOR_BITMAP_PRESENT: + stream.Seek((long)((pt & BAT_FILE_OFFSET_MASK) * 1048576), SeekOrigin.Begin); + byte[] bmp = new byte[1048576]; + stream.Read(bmp, 0, bmp.Length); + sectorBmpMs.Write(bmp, 0, bmp.Length); + break; + default: + if((pt & BAT_FLAGS_MASK) != 0) + throw new + ImageNotSupportedException(string + .Format("Unsupported sector bitmap block flags (0x{0:X16}) found, not proceeding.", + pt & BAT_FLAGS_MASK)); + + break; } - else if((pt & BAT_FLAGS_MASK) != 0) - throw new - ImageNotSupportedException(string - .Format("Unsupported sector bitmap block flags (0x{0:X16}) found, not proceeding.", - pt & BAT_FLAGS_MASK)); sectorBitmap = sectorBmpMs.ToArray(); sectorBmpMs.Close(); @@ -835,11 +840,12 @@ namespace DiscImageChef.DiscImages throw new ImageNotSupportedException(string.Format("Unknown flags (0x{0:X16}) set in block pointer", blkPtr & BAT_RESERVED_MASK)); - if((blkFlags & BAT_FLAGS_MASK) == PAYLOAD_BLOCK_NOT_PRESENT) - return hasParent ? parentImage.ReadSector(sectorAddress) : new byte[logicalSectorSize]; - - if((blkFlags & BAT_FLAGS_MASK) == PAYLOAD_BLOCK_UNDEFINED || (blkFlags & BAT_FLAGS_MASK) == PAYLOAD_BLOCK_ZERO || - (blkFlags & BAT_FLAGS_MASK) == PAYLOAD_BLOCK_UNMAPPER) return new byte[logicalSectorSize]; + switch(blkFlags & BAT_FLAGS_MASK) { + case PAYLOAD_BLOCK_NOT_PRESENT: return hasParent ? parentImage.ReadSector(sectorAddress) : new byte[logicalSectorSize]; + case PAYLOAD_BLOCK_UNDEFINED: + case PAYLOAD_BLOCK_ZERO: + case PAYLOAD_BLOCK_UNMAPPER: return new byte[logicalSectorSize]; + } bool partialBlock; partialBlock = !((blkFlags & BAT_FLAGS_MASK) == PAYLOAD_BLOCK_FULLY_PRESENT); diff --git a/DiscImageChef.DiscImages/VMware.cs b/DiscImageChef.DiscImages/VMware.cs index 48d596b63..95b32f812 100644 --- a/DiscImageChef.DiscImages/VMware.cs +++ b/DiscImageChef.DiscImages/VMware.cs @@ -739,28 +739,26 @@ namespace DiscImageChef.DiscImages Stream dataStream; - if(currentExtent.Type == "ZERO") - { - sector = new byte[SECTOR_SIZE]; + switch(currentExtent.Type) { + case "ZERO": + sector = new byte[SECTOR_SIZE]; - if(sectorCache.Count >= maxCachedSectors) sectorCache.Clear(); + if(sectorCache.Count >= maxCachedSectors) sectorCache.Clear(); - sectorCache.Add(sectorAddress, sector); - return sector; - } + sectorCache.Add(sectorAddress, sector); + return sector; + case "FLAT": + case "VMFS": + dataStream = currentExtent.Filter.GetDataForkStream(); + dataStream.Seek((long)((currentExtent.Offset + (sectorAddress - extentStartSector)) * SECTOR_SIZE), + SeekOrigin.Begin); + sector = new byte[SECTOR_SIZE]; + dataStream.Read(sector, 0, sector.Length); - if(currentExtent.Type == "FLAT" || currentExtent.Type == "VMFS") - { - dataStream = currentExtent.Filter.GetDataForkStream(); - dataStream.Seek((long)((currentExtent.Offset + (sectorAddress - extentStartSector)) * SECTOR_SIZE), - SeekOrigin.Begin); - sector = new byte[SECTOR_SIZE]; - dataStream.Read(sector, 0, sector.Length); + if(sectorCache.Count >= maxCachedSectors) sectorCache.Clear(); - if(sectorCache.Count >= maxCachedSectors) sectorCache.Clear(); - - sectorCache.Add(sectorAddress, sector); - return sector; + sectorCache.Add(sectorAddress, sector); + return sector; } ulong index = sectorAddress / grainSize; diff --git a/DiscImageChef.DiscImages/ZZZRawImage.cs b/DiscImageChef.DiscImages/ZZZRawImage.cs index 04a726721..3349284b8 100644 --- a/DiscImageChef.DiscImages/ZZZRawImage.cs +++ b/DiscImageChef.DiscImages/ZZZRawImage.cs @@ -123,70 +123,77 @@ namespace DiscImageChef.DiscImages stream.Seek(0, SeekOrigin.Begin); extension = Path.GetExtension(imageFilter.GetFilename()).ToLower(); - if(extension == ".iso" && imageFilter.GetDataForkLength() % 2048 == 0) ImageInfo.SectorSize = 2048; - else if(extension == ".d81" && imageFilter.GetDataForkLength() == 819200) ImageInfo.SectorSize = 256; - else if((extension == ".adf" || extension == ".adl" || extension == ".ssd" || extension == ".dsd") && - (imageFilter.GetDataForkLength() == 163840 || imageFilter.GetDataForkLength() == 327680 || - imageFilter.GetDataForkLength() == 655360)) ImageInfo.SectorSize = 256; - else if((extension == ".adf" || extension == ".adl") && imageFilter.GetDataForkLength() == 819200) - ImageInfo.SectorSize = 1024; - else - switch(imageFilter.GetDataForkLength()) - { - case 242944: - case 256256: - case 495872: - case 92160: - case 133120: - ImageInfo.SectorSize = 128; - break; - case 116480: - case 287488: // T0S0 = 128bps - case 988416: // T0S0 = 128bps - case 995072: // T0S0 = 128bps, T0S1 = 256bps - case 1021696: // T0S0 = 128bps, T0S1 = 256bps - case 232960: - case 143360: - case 286720: - case 512512: - case 102400: - case 204800: - case 655360: - case 80384: // T0S0 = 128bps - case 325632: // T0S0 = 128bps, T0S1 = 256bps - case 653312: // T0S0 = 128bps, T0S1 = 256bps - - #region Commodore - case 174848: - case 175531: - case 196608: - case 197376: - case 349696: - case 351062: - case 822400: - #endregion Commodore - - ImageInfo.SectorSize = 256; - break; - case 81664: - ImageInfo.SectorSize = 319; - break; - case 306432: // T0S0 = 128bps - case 1146624: // T0S0 = 128bps, T0S1 = 256bps - case 1177344: // T0S0 = 128bps, T0S1 = 256bps - ImageInfo.SectorSize = 512; - break; - case 1222400: // T0S0 = 128bps, T0S1 = 256bps - case 1304320: // T0S0 = 128bps, T0S1 = 256bps - case 1255168: // T0S0 = 128bps, T0S1 = 256bps - case 1261568: - case 1638400: + switch(extension) { + case ".iso" when imageFilter.GetDataForkLength() % 2048 == 0: ImageInfo.SectorSize = 2048; + break; + case ".d81" when imageFilter.GetDataForkLength() == 819200: ImageInfo.SectorSize = 256; + break; + default: + if((extension == ".adf" || extension == ".adl" || extension == ".ssd" || extension == ".dsd") && + (imageFilter.GetDataForkLength() == 163840 || imageFilter.GetDataForkLength() == 327680 || + imageFilter.GetDataForkLength() == 655360)) ImageInfo.SectorSize = 256; + else if((extension == ".adf" || extension == ".adl") && imageFilter.GetDataForkLength() == 819200) ImageInfo.SectorSize = 1024; - break; - default: - ImageInfo.SectorSize = 512; - break; - } + else + switch(imageFilter.GetDataForkLength()) + { + case 242944: + case 256256: + case 495872: + case 92160: + case 133120: + ImageInfo.SectorSize = 128; + break; + case 116480: + case 287488: // T0S0 = 128bps + case 988416: // T0S0 = 128bps + case 995072: // T0S0 = 128bps, T0S1 = 256bps + case 1021696: // T0S0 = 128bps, T0S1 = 256bps + case 232960: + case 143360: + case 286720: + case 512512: + case 102400: + case 204800: + case 655360: + case 80384: // T0S0 = 128bps + case 325632: // T0S0 = 128bps, T0S1 = 256bps + case 653312: // T0S0 = 128bps, T0S1 = 256bps + + #region Commodore + case 174848: + case 175531: + case 196608: + case 197376: + case 349696: + case 351062: + case 822400: + #endregion Commodore + + ImageInfo.SectorSize = 256; + break; + case 81664: + ImageInfo.SectorSize = 319; + break; + case 306432: // T0S0 = 128bps + case 1146624: // T0S0 = 128bps, T0S1 = 256bps + case 1177344: // T0S0 = 128bps, T0S1 = 256bps + ImageInfo.SectorSize = 512; + break; + case 1222400: // T0S0 = 128bps, T0S1 = 256bps + case 1304320: // T0S0 = 128bps, T0S1 = 256bps + case 1255168: // T0S0 = 128bps, T0S1 = 256bps + case 1261568: + case 1638400: + ImageInfo.SectorSize = 1024; + break; + default: + ImageInfo.SectorSize = 512; + break; + } + + break; + } ImageInfo.ImageSize = (ulong)imageFilter.GetDataForkLength(); ImageInfo.ImageCreationTime = imageFilter.GetCreationTime(); diff --git a/DiscImageChef.Filesystems/BFS.cs b/DiscImageChef.Filesystems/BFS.cs index c9f1de70f..a404592a8 100644 --- a/DiscImageChef.Filesystems/BFS.cs +++ b/DiscImageChef.Filesystems/BFS.cs @@ -176,11 +176,16 @@ namespace DiscImageChef.Filesystems 1 << (int)besb.block_shift, besb.block_size).AppendLine(); } - if(besb.flags == BEFS_CLEAN) - if(besb.log_start == besb.log_end) sb.AppendLine("Filesystem is clean"); - else sb.AppendLine("Filesystem is dirty"); - else if(besb.flags == BEFS_DIRTY) sb.AppendLine("Filesystem is dirty"); - else sb.AppendFormat("Unknown flags: {0:X8}", besb.flags).AppendLine(); + switch(besb.flags) { + case BEFS_CLEAN: + if(besb.log_start == besb.log_end) sb.AppendLine("Filesystem is clean"); + else sb.AppendLine("Filesystem is dirty"); + break; + case BEFS_DIRTY: sb.AppendLine("Filesystem is dirty"); + break; + default: sb.AppendFormat("Unknown flags: {0:X8}", besb.flags).AppendLine(); + break; + } sb.AppendFormat("Volume name: {0}", StringHandlers.CToString(besb.name, CurrentEncoding)).AppendLine(); sb.AppendFormat("{0} bytes per block", besb.block_size).AppendLine(); diff --git a/DiscImageChef.Filesystems/CPM/Info.cs b/DiscImageChef.Filesystems/CPM/Info.cs index b7bcc02b5..60bb48f2a 100644 --- a/DiscImageChef.Filesystems/CPM/Info.cs +++ b/DiscImageChef.Filesystems/CPM/Info.cs @@ -263,9 +263,14 @@ namespace DiscImageChef.Filesystems.CPM if(amsSb.format == 2) { - if((amsSb.sidedness & 0x02) == 1) workingDefinition.order = "SIDES"; - else if((amsSb.sidedness & 0x02) == 2) workingDefinition.order = "CYLINDERS"; - else workingDefinition.order = null; + switch(amsSb.sidedness & 0x02) { + case 1: workingDefinition.order = "SIDES"; + break; + case 2: workingDefinition.order = "CYLINDERS"; + break; + default: workingDefinition.order = null; + break; + } workingDefinition.side2 = new Side(); workingDefinition.side2.sideId = 1; diff --git a/DiscImageChef.Filesystems/CPM/Super.cs b/DiscImageChef.Filesystems/CPM/Super.cs index 8c6bce2a2..82b19f595 100644 --- a/DiscImageChef.Filesystems/CPM/Super.cs +++ b/DiscImageChef.Filesystems/CPM/Super.cs @@ -210,6 +210,7 @@ namespace DiscImageChef.Filesystems.CPM passwordCache = new Dictionary(); DicConsole.DebugWriteLine("CP/M Plugin", "Traversing directory."); + IntPtr dirPtr; // For each directory entry for(int dOff = 0; dOff < directory.Length; dOff += 32) @@ -218,7 +219,7 @@ namespace DiscImageChef.Filesystems.CPM if(allocationBlocks.Count > 256) { DirectoryEntry16 entry = new DirectoryEntry16(); - IntPtr dirPtr = Marshal.AllocHGlobal(32); + dirPtr = Marshal.AllocHGlobal(32); Marshal.Copy(directory, dOff, dirPtr, 32); entry = (DirectoryEntry16)Marshal.PtrToStructure(dirPtr, typeof(DirectoryEntry16)); Marshal.FreeHGlobal(dirPtr); @@ -312,7 +313,7 @@ namespace DiscImageChef.Filesystems.CPM else { DirectoryEntry entry = new DirectoryEntry(); - IntPtr dirPtr = Marshal.AllocHGlobal(32); + dirPtr = Marshal.AllocHGlobal(32); Marshal.Copy(directory, dOff, dirPtr, 32); entry = (DirectoryEntry)Marshal.PtrToStructure(dirPtr, typeof(DirectoryEntry)); Marshal.FreeHGlobal(dirPtr); @@ -407,7 +408,7 @@ namespace DiscImageChef.Filesystems.CPM else if((directory[dOff] & 0x7F) >= 0x10 && (directory[dOff] & 0x7F) < 0x20) { PasswordEntry entry = new PasswordEntry(); - IntPtr dirPtr = Marshal.AllocHGlobal(32); + dirPtr = Marshal.AllocHGlobal(32); Marshal.Copy(directory, dOff, dirPtr, 32); entry = (PasswordEntry)Marshal.PtrToStructure(dirPtr, typeof(PasswordEntry)); Marshal.FreeHGlobal(dirPtr); @@ -449,162 +450,163 @@ namespace DiscImageChef.Filesystems.CPM dirCnt++; } // Volume label and password entry. Volume password is ignored. - else if((directory[dOff] & 0x7F) == 0x20) - { - LabelEntry entry = new LabelEntry(); - IntPtr dirPtr = Marshal.AllocHGlobal(32); - Marshal.Copy(directory, dOff, dirPtr, 32); - entry = (LabelEntry)Marshal.PtrToStructure(dirPtr, typeof(LabelEntry)); - Marshal.FreeHGlobal(dirPtr); + else switch(directory[dOff] & 0x7F) { + case 0x20: + LabelEntry labelEntry; + dirPtr = Marshal.AllocHGlobal(32); + Marshal.Copy(directory, dOff, dirPtr, 32); + labelEntry = (LabelEntry)Marshal.PtrToStructure(dirPtr, typeof(LabelEntry)); + Marshal.FreeHGlobal(dirPtr); - // The volume label defines if one of the fields in CP/M 3 timestamp is a creation or an access time - atime |= (entry.flags & 0x40) == 0x40; + // The volume label defines if one of the fields in CP/M 3 timestamp is a creation or an access time + atime |= (labelEntry.flags & 0x40) == 0x40; - label = Encoding.ASCII.GetString(directory, dOff + 1, 11).Trim(); - labelCreationDate = new byte[4]; - labelUpdateDate = new byte[4]; - Array.Copy(directory, dOff + 24, labelCreationDate, 0, 4); - Array.Copy(directory, dOff + 28, labelUpdateDate, 0, 4); + label = Encoding.ASCII.GetString(directory, dOff + 1, 11).Trim(); + labelCreationDate = new byte[4]; + labelUpdateDate = new byte[4]; + Array.Copy(directory, dOff + 24, labelCreationDate, 0, 4); + Array.Copy(directory, dOff + 28, labelUpdateDate, 0, 4); + + // Count entries 3 by 3 for timestamps + switch(dirCnt % 3) + { + case 0: + file1 = null; + break; + case 1: + file2 = null; + break; + case 2: + file3 = null; + break; + } + + dirCnt++; + break; + case 0x21: + if(directory[dOff + 10] == 0x00 && directory[dOff + 20] == 0x00 && directory[dOff + 30] == 0x00 && + directory[dOff + 31] == 0x00) + { + DateEntry dateEntry; + dirPtr = Marshal.AllocHGlobal(32); + Marshal.Copy(directory, dOff, dirPtr, 32); + dateEntry = (DateEntry)Marshal.PtrToStructure(dirPtr, typeof(DateEntry)); + Marshal.FreeHGlobal(dirPtr); + + FileEntryInfo fInfo; + + // Entry contains timestamps for last 3 entries, whatever the kind they are. + if(!string.IsNullOrEmpty(file1)) + { + if(statCache.TryGetValue(file1, out fInfo)) statCache.Remove(file1); + else fInfo = new FileEntryInfo(); + + if(atime) fInfo.AccessTime = DateHandlers.CPMToDateTime(dateEntry.date1); + else fInfo.CreationTime = DateHandlers.CPMToDateTime(dateEntry.date1); + + fInfo.LastWriteTime = DateHandlers.CPMToDateTime(dateEntry.date2); + + statCache.Add(file1, fInfo); + } + + if(!string.IsNullOrEmpty(file2)) + { + if(statCache.TryGetValue(file2, out fInfo)) statCache.Remove(file2); + else fInfo = new FileEntryInfo(); + + if(atime) fInfo.AccessTime = DateHandlers.CPMToDateTime(dateEntry.date3); + else fInfo.CreationTime = DateHandlers.CPMToDateTime(dateEntry.date3); + + fInfo.LastWriteTime = DateHandlers.CPMToDateTime(dateEntry.date4); + + statCache.Add(file2, fInfo); + } + + if(!string.IsNullOrEmpty(file3)) + { + if(statCache.TryGetValue(file3, out fInfo)) statCache.Remove(file3); + else fInfo = new FileEntryInfo(); + + if(atime) fInfo.AccessTime = DateHandlers.CPMToDateTime(dateEntry.date5); + else fInfo.CreationTime = DateHandlers.CPMToDateTime(dateEntry.date5); + + fInfo.LastWriteTime = DateHandlers.CPMToDateTime(dateEntry.date6); + + statCache.Add(file3, fInfo); + } - // Count entries 3 by 3 for timestamps - switch(dirCnt % 3) - { - case 0: file1 = null; - break; - case 1: file2 = null; - break; - case 2: file3 = null; - break; - } + dirCnt = 0; + } + // However, if this byte is 0, timestamp is in Z80DOS or DOS+ format + else if(directory[dOff + 1] == 0x00) + { + TrdPartyDateEntry trdPartyDateEntry; + dirPtr = Marshal.AllocHGlobal(32); + Marshal.Copy(directory, dOff, dirPtr, 32); + trdPartyDateEntry = (TrdPartyDateEntry)Marshal.PtrToStructure(dirPtr, typeof(TrdPartyDateEntry)); + Marshal.FreeHGlobal(dirPtr); - dirCnt++; + FileEntryInfo fInfo; + + // Entry contains timestamps for last 3 entries, whatever the kind they are. + if(!string.IsNullOrEmpty(file1)) + { + if(statCache.TryGetValue(file1, out fInfo)) statCache.Remove(file1); + else fInfo = new FileEntryInfo(); + + byte[] ctime = new byte[4]; + ctime[0] = trdPartyDateEntry.create1[0]; + ctime[1] = trdPartyDateEntry.create1[1]; + + fInfo.AccessTime = DateHandlers.CPMToDateTime(trdPartyDateEntry.access1); + fInfo.CreationTime = DateHandlers.CPMToDateTime(ctime); + fInfo.LastWriteTime = DateHandlers.CPMToDateTime(trdPartyDateEntry.modify1); + + statCache.Add(file1, fInfo); + } + + if(!string.IsNullOrEmpty(file2)) + { + if(statCache.TryGetValue(file2, out fInfo)) statCache.Remove(file2); + else fInfo = new FileEntryInfo(); + + byte[] ctime = new byte[4]; + ctime[0] = trdPartyDateEntry.create2[0]; + ctime[1] = trdPartyDateEntry.create2[1]; + + fInfo.AccessTime = DateHandlers.CPMToDateTime(trdPartyDateEntry.access2); + fInfo.CreationTime = DateHandlers.CPMToDateTime(ctime); + fInfo.LastWriteTime = DateHandlers.CPMToDateTime(trdPartyDateEntry.modify2); + + statCache.Add(file2, fInfo); + } + + if(!string.IsNullOrEmpty(file3)) + { + if(statCache.TryGetValue(file1, out fInfo)) statCache.Remove(file3); + else fInfo = new FileEntryInfo(); + + byte[] ctime = new byte[4]; + ctime[0] = trdPartyDateEntry.create3[0]; + ctime[1] = trdPartyDateEntry.create3[1]; + + fInfo.AccessTime = DateHandlers.CPMToDateTime(trdPartyDateEntry.access3); + fInfo.CreationTime = DateHandlers.CPMToDateTime(ctime); + fInfo.LastWriteTime = DateHandlers.CPMToDateTime(trdPartyDateEntry.modify3); + + statCache.Add(file3, fInfo); + } + + file1 = null; + file2 = null; + file3 = null; + dirCnt = 0; + } + break; } - // Timestamp entry - else if((directory[dOff] & 0x7F) == 0x21) - if(directory[dOff + 10] == 0x00 && directory[dOff + 20] == 0x00 && directory[dOff + 30] == 0x00 && - directory[dOff + 31] == 0x00) - { - DateEntry entry = new DateEntry(); - IntPtr dirPtr = Marshal.AllocHGlobal(32); - Marshal.Copy(directory, dOff, dirPtr, 32); - entry = (DateEntry)Marshal.PtrToStructure(dirPtr, typeof(DateEntry)); - Marshal.FreeHGlobal(dirPtr); - - FileEntryInfo fInfo; - - // Entry contains timestamps for last 3 entries, whatever the kind they are. - if(!string.IsNullOrEmpty(file1)) - { - if(statCache.TryGetValue(file1, out fInfo)) statCache.Remove(file1); - else fInfo = new FileEntryInfo(); - - if(atime) fInfo.AccessTime = DateHandlers.CPMToDateTime(entry.date1); - else fInfo.CreationTime = DateHandlers.CPMToDateTime(entry.date1); - - fInfo.LastWriteTime = DateHandlers.CPMToDateTime(entry.date2); - - statCache.Add(file1, fInfo); - } - - if(!string.IsNullOrEmpty(file2)) - { - if(statCache.TryGetValue(file2, out fInfo)) statCache.Remove(file2); - else fInfo = new FileEntryInfo(); - - if(atime) fInfo.AccessTime = DateHandlers.CPMToDateTime(entry.date3); - else fInfo.CreationTime = DateHandlers.CPMToDateTime(entry.date3); - - fInfo.LastWriteTime = DateHandlers.CPMToDateTime(entry.date4); - - statCache.Add(file2, fInfo); - } - - if(!string.IsNullOrEmpty(file3)) - { - if(statCache.TryGetValue(file3, out fInfo)) statCache.Remove(file3); - else fInfo = new FileEntryInfo(); - - if(atime) fInfo.AccessTime = DateHandlers.CPMToDateTime(entry.date5); - else fInfo.CreationTime = DateHandlers.CPMToDateTime(entry.date5); - - fInfo.LastWriteTime = DateHandlers.CPMToDateTime(entry.date6); - - statCache.Add(file3, fInfo); - } - - file1 = null; - file2 = null; - file3 = null; - dirCnt = 0; - } - // However, if this byte is 0, timestamp is in Z80DOS or DOS+ format - else if(directory[dOff + 1] == 0x00) - { - TrdPartyDateEntry entry = new TrdPartyDateEntry(); - IntPtr dirPtr = Marshal.AllocHGlobal(32); - Marshal.Copy(directory, dOff, dirPtr, 32); - entry = (TrdPartyDateEntry)Marshal.PtrToStructure(dirPtr, typeof(TrdPartyDateEntry)); - Marshal.FreeHGlobal(dirPtr); - - FileEntryInfo fInfo; - - // Entry contains timestamps for last 3 entries, whatever the kind they are. - if(!string.IsNullOrEmpty(file1)) - { - if(statCache.TryGetValue(file1, out fInfo)) statCache.Remove(file1); - else fInfo = new FileEntryInfo(); - - byte[] ctime = new byte[4]; - ctime[0] = entry.create1[0]; - ctime[1] = entry.create1[1]; - - fInfo.AccessTime = DateHandlers.CPMToDateTime(entry.access1); - fInfo.CreationTime = DateHandlers.CPMToDateTime(ctime); - fInfo.LastWriteTime = DateHandlers.CPMToDateTime(entry.modify1); - - statCache.Add(file1, fInfo); - } - - if(!string.IsNullOrEmpty(file2)) - { - if(statCache.TryGetValue(file2, out fInfo)) statCache.Remove(file2); - else fInfo = new FileEntryInfo(); - - byte[] ctime = new byte[4]; - ctime[0] = entry.create2[0]; - ctime[1] = entry.create2[1]; - - fInfo.AccessTime = DateHandlers.CPMToDateTime(entry.access2); - fInfo.CreationTime = DateHandlers.CPMToDateTime(ctime); - fInfo.LastWriteTime = DateHandlers.CPMToDateTime(entry.modify2); - - statCache.Add(file2, fInfo); - } - - if(!string.IsNullOrEmpty(file3)) - { - if(statCache.TryGetValue(file1, out fInfo)) statCache.Remove(file3); - else fInfo = new FileEntryInfo(); - - byte[] ctime = new byte[4]; - ctime[0] = entry.create3[0]; - ctime[1] = entry.create3[1]; - - fInfo.AccessTime = DateHandlers.CPMToDateTime(entry.access3); - fInfo.CreationTime = DateHandlers.CPMToDateTime(ctime); - fInfo.LastWriteTime = DateHandlers.CPMToDateTime(entry.modify3); - - statCache.Add(file3, fInfo); - } - - file1 = null; - file2 = null; - file3 = null; - dirCnt = 0; - } // Cache all files. As CP/M maximum volume size is 8 Mib // this should not be a problem diff --git a/DiscImageChef.Filesystems/Cram.cs b/DiscImageChef.Filesystems/Cram.cs index c57573dc7..d125661d8 100644 --- a/DiscImageChef.Filesystems/Cram.cs +++ b/DiscImageChef.Filesystems/Cram.cs @@ -113,17 +113,17 @@ namespace DiscImageChef.Filesystems CramSuperBlock crSb = new CramSuperBlock(); bool littleEndian = true; - if(magic == Cram_MAGIC) - { - IntPtr crSbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(crSb)); - Marshal.Copy(sector, 0, crSbPtr, Marshal.SizeOf(crSb)); - crSb = (CramSuperBlock)Marshal.PtrToStructure(crSbPtr, typeof(CramSuperBlock)); - Marshal.FreeHGlobal(crSbPtr); - } - else if(magic == Cram_CIGAM) - { - crSb = BigEndianMarshal.ByteArrayToStructureBigEndian(sector); - littleEndian = false; + switch(magic) { + case Cram_MAGIC: + IntPtr crSbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(crSb)); + Marshal.Copy(sector, 0, crSbPtr, Marshal.SizeOf(crSb)); + crSb = (CramSuperBlock)Marshal.PtrToStructure(crSbPtr, typeof(CramSuperBlock)); + Marshal.FreeHGlobal(crSbPtr); + break; + case Cram_CIGAM: + crSb = BigEndianMarshal.ByteArrayToStructureBigEndian(sector); + littleEndian = false; + break; } StringBuilder sbInformation = new StringBuilder(); diff --git a/DiscImageChef.Filesystems/FAT.cs b/DiscImageChef.Filesystems/FAT.cs index d0a0f6ea1..132e7484b 100644 --- a/DiscImageChef.Filesystems/FAT.cs +++ b/DiscImageChef.Filesystems/FAT.cs @@ -175,12 +175,14 @@ namespace DiscImageChef.Filesystems huge_sectors /= 4; } - // exFAT - if(oem_string == "EXFAT ") return false; - // NTFS - if(oem_string == "NTFS " && bootable == 0xAA55 && fats_no == 0 && fat_sectors == 0) return false; - // QNX4 - if(oem_string == "FQNX4FS ") return false; + switch(oem_string) { + // exFAT + case "EXFAT ": return false; + // NTFS + case "NTFS " when bootable == 0xAA55 && fats_no == 0 && fat_sectors == 0: return false; + // QNX4 + case "FQNX4FS ": return false; + } // HPFS if(16 + partition.Start <= partition.End) @@ -195,32 +197,27 @@ namespace DiscImageChef.Filesystems if(hpfs_magic1 == 0xF995E849 && hpfs_magic2 == 0xFA53E9C5) return false; } - // FAT32 for sure - if(bits_in_bps == 1 && correct_spc && fats_no <= 2 && sectors == 0 && fat_sectors == 0 && - fat32_signature == 0x29 && fat32_string == "FAT32 ") return true; - // short FAT32 - if(bits_in_bps == 1 && correct_spc && fats_no <= 2 && sectors == 0 && fat_sectors == 0 && - fat32_signature == 0x28) - return big_sectors == 0 - ? huge_sectors <= partition.End - partition.Start + 1 - : big_sectors <= partition.End - partition.Start + 1; - // MSX-DOS FAT12 - if(bits_in_bps == 1 && correct_spc && fats_no <= 2 && root_entries > 0 && - sectors <= partition.End - partition.Start + 1 && fat_sectors > 0 && - msx_string == "VOL_ID") return true; - // EBPB - if(bits_in_bps == 1 && correct_spc && fats_no <= 2 && root_entries > 0 && fat_sectors > 0 && - (bpb_signature == 0x28 || bpb_signature == 0x29)) - return sectors == 0 - ? big_sectors <= partition.End - partition.Start + 1 - : sectors <= partition.End - partition.Start + 1; - - // BPB - if(bits_in_bps == 1 && correct_spc && reserved_secs < partition.End - partition.Start && fats_no <= 2 && - root_entries > 0 && fat_sectors > 0) - return sectors == 0 - ? big_sectors <= partition.End - partition.Start + 1 - : sectors <= partition.End - partition.Start + 1; + switch(bits_in_bps) { + // FAT32 for sure + case 1 when correct_spc && fats_no <= 2 && sectors == 0 && fat_sectors == 0 && fat32_signature == 0x29 && fat32_string == "FAT32 ": return true; + // short FAT32 + case 1 when correct_spc && fats_no <= 2 && sectors == 0 && fat_sectors == 0 && fat32_signature == 0x28: + return big_sectors == 0 + ? huge_sectors <= partition.End - partition.Start + 1 + : big_sectors <= partition.End - partition.Start + 1; + // MSX-DOS FAT12 + case 1 when correct_spc && fats_no <= 2 && root_entries > 0 && sectors <= partition.End - partition.Start + 1 && fat_sectors > 0 && msx_string == "VOL_ID": return true; + // EBPB + case 1 when correct_spc && fats_no <= 2 && root_entries > 0 && fat_sectors > 0 && (bpb_signature == 0x28 || bpb_signature == 0x29): + return sectors == 0 + ? big_sectors <= partition.End - partition.Start + 1 + : sectors <= partition.End - partition.Start + 1; + // BPB + case 1 when correct_spc && reserved_secs < partition.End - partition.Start && fats_no <= 2 && root_entries > 0 && fat_sectors > 0: + return sectors == 0 + ? big_sectors <= partition.End - partition.Start + 1 + : sectors <= partition.End - partition.Start + 1; + } // Apricot BPB if(bits_in_apricot_bps == 1 && apricot_correct_spc && diff --git a/DiscImageChef.Filesystems/FFS.cs b/DiscImageChef.Filesystems/FFS.cs index d907d12b4..587e25eb9 100644 --- a/DiscImageChef.Filesystems/FFS.cs +++ b/DiscImageChef.Filesystems/FFS.cs @@ -359,9 +359,14 @@ namespace DiscImageChef.Filesystems sbInformation.AppendFormat("NINDIR: 0x{0:X8}", ufs_sb.fs_nindir).AppendLine(); sbInformation.AppendFormat("INOPB: 0x{0:X8}", ufs_sb.fs_inopb).AppendLine(); sbInformation.AppendFormat("NSPF: 0x{0:X8}", ufs_sb.fs_old_nspf).AppendLine(); - if(ufs_sb.fs_optim == 0) sbInformation.AppendLine("Filesystem will minimize allocation time"); - else if(ufs_sb.fs_optim == 1) sbInformation.AppendLine("Filesystem will minimize volume fragmentation"); - else sbInformation.AppendFormat("Unknown optimization value: 0x{0:X8}", ufs_sb.fs_optim).AppendLine(); + switch(ufs_sb.fs_optim) { + case 0: sbInformation.AppendLine("Filesystem will minimize allocation time"); + break; + case 1: sbInformation.AppendLine("Filesystem will minimize volume fragmentation"); + break; + default: sbInformation.AppendFormat("Unknown optimization value: 0x{0:X8}", ufs_sb.fs_optim).AppendLine(); + break; + } if(fs_type_sun) sbInformation.AppendFormat("{0} sectors/track", ufs_sb.fs_old_npsect).AppendLine(); else if(fs_type_sun86) sbInformation.AppendFormat("Volume state on {0}", DateHandlers.UNIXToDateTime(ufs_sb.fs_old_npsect)) diff --git a/DiscImageChef.Filesystems/ISO9660/Info.cs b/DiscImageChef.Filesystems/ISO9660/Info.cs index 71b314219..811b428ce 100644 --- a/DiscImageChef.Filesystems/ISO9660/Info.cs +++ b/DiscImageChef.Filesystems/ISO9660/Info.cs @@ -310,86 +310,84 @@ namespace DiscImageChef.Filesystems.ISO9660 ushort nextSignature = BigEndianBitConverter.ToUInt16(sa, sa_off); - // Easy, contains size field - if(nextSignature == AppleMagic) - { - Apple = true; - sa_off += sa[sa_off + 2]; - noneFound = false; - } - - // Not easy, contains size field - if(nextSignature == AppleMagicOld) - { - Apple = true; - AppleOldId apple_id = (AppleOldId)sa[sa_off + 2]; - noneFound = false; - - switch(apple_id) - { - case AppleOldId.ProDOS: - sa_off += Marshal.SizeOf(typeof(AppleProDOSOldSystemUse)); - break; - case AppleOldId.TypeCreator: - case AppleOldId.TypeCreatorBundle: - sa_off += Marshal.SizeOf(typeof(AppleHFSTypeCreatorSystemUse)); - break; - case AppleOldId.TypeCreatorIcon: - case AppleOldId.TypeCreatorIconBundle: - sa_off += Marshal.SizeOf(typeof(AppleHFSIconSystemUse)); - break; - case AppleOldId.HFS: - sa_off += Marshal.SizeOf(typeof(AppleHFSOldSystemUse)); - break; - } - } - - // IEEE-P1281 aka SUSP 1.12 - if(nextSignature == SUSP_Indicator) - { - SUSP = true; - sa_off += sa[sa_off + 2]; - noneFound = false; - - while(sa_off + 2 < sa_len) - { - nextSignature = BigEndianBitConverter.ToUInt16(sa, sa_off); - - if(nextSignature == AppleMagic) - if(sa[sa_off + 3] == 1 && sa[sa_off + 2] == 7) Apple = true; - else Apple |= sa[sa_off + 3] != 1; - - if(nextSignature == SUSP_Continuation && sa_off + sa[sa_off + 2] <= sa_len) - { - byte[] ce = new byte[sa[sa_off + 2]]; - Array.Copy(sa, sa_off, ce, 0, ce.Length); - ContinuationArea ca = - BigEndianMarshal.ByteArrayToStructureBigEndian(ce); - contareas.Add(ca); - } - - if(nextSignature == SUSP_Reference && sa_off + sa[sa_off + 2] <= sa_len) - { - byte[] er = new byte[sa[sa_off + 2]]; - Array.Copy(sa, sa_off, er, 0, er.Length); - refareas.Add(er); - } - - RRIP |= nextSignature == RRIP_Magic || nextSignature == RRIP_PosixAttributes || - nextSignature == RRIP_PosixDevNo || nextSignature == RRIP_Symlink || - nextSignature == RRIP_Name || nextSignature == RRIP_Childlink || - nextSignature == RRIP_Parentlink || nextSignature == RRIP_RelocatedDir || - nextSignature == RRIP_Timestamps || nextSignature == RRIP_Sparse; - - ziso |= nextSignature == ziso_Magic; - Amiga |= nextSignature == Amiga_Magic; - AAIP |= nextSignature == AAIP_Magic || - nextSignature == AAIP_OldMagic && sa[sa_off + 3] == 1 && sa[sa_off + 2] >= 9; - + switch(nextSignature) { + // Easy, contains size field + case AppleMagic: + Apple = true; sa_off += sa[sa_off + 2]; + noneFound = false; + break; + // Not easy, contains size field + case AppleMagicOld: + Apple = true; + AppleOldId apple_id = (AppleOldId)sa[sa_off + 2]; + noneFound = false; - if(nextSignature == SUSP_Terminator) break; - } + switch(apple_id) + { + case AppleOldId.ProDOS: + sa_off += Marshal.SizeOf(typeof(AppleProDOSOldSystemUse)); + break; + case AppleOldId.TypeCreator: + case AppleOldId.TypeCreatorBundle: + sa_off += Marshal.SizeOf(typeof(AppleHFSTypeCreatorSystemUse)); + break; + case AppleOldId.TypeCreatorIcon: + case AppleOldId.TypeCreatorIconBundle: + sa_off += Marshal.SizeOf(typeof(AppleHFSIconSystemUse)); + break; + case AppleOldId.HFS: + sa_off += Marshal.SizeOf(typeof(AppleHFSOldSystemUse)); + break; + } + + break; + // IEEE-P1281 aka SUSP 1.12 + case SUSP_Indicator: + SUSP = true; + sa_off += sa[sa_off + 2]; + noneFound = false; + + while(sa_off + 2 < sa_len) + { + nextSignature = BigEndianBitConverter.ToUInt16(sa, sa_off); + + switch(nextSignature) { + case AppleMagic: + if(sa[sa_off + 3] == 1 && sa[sa_off + 2] == 7) Apple = true; + else Apple |= sa[sa_off + 3] != 1; + break; + case SUSP_Continuation when sa_off + sa[sa_off + 2] <= sa_len: + byte[] ce = new byte[sa[sa_off + 2]]; + Array.Copy(sa, sa_off, ce, 0, ce.Length); + ContinuationArea ca = + BigEndianMarshal.ByteArrayToStructureBigEndian(ce); + contareas.Add(ca); + break; + case SUSP_Reference when sa_off + sa[sa_off + 2] <= sa_len: + byte[] er = new byte[sa[sa_off + 2]]; + Array.Copy(sa, sa_off, er, 0, er.Length); + refareas.Add(er); + break; + } + + RRIP |= nextSignature == RRIP_Magic || nextSignature == RRIP_PosixAttributes || + nextSignature == RRIP_PosixDevNo || nextSignature == RRIP_Symlink || + nextSignature == RRIP_Name || nextSignature == RRIP_Childlink || + nextSignature == RRIP_Parentlink || nextSignature == RRIP_RelocatedDir || + nextSignature == RRIP_Timestamps || nextSignature == RRIP_Sparse; + + ziso |= nextSignature == ziso_Magic; + Amiga |= nextSignature == Amiga_Magic; + AAIP |= nextSignature == AAIP_Magic || + nextSignature == AAIP_OldMagic && sa[sa_off + 3] == 1 && sa[sa_off + 2] >= 9; + + sa_off += sa[sa_off + 2]; + + if(nextSignature == SUSP_Terminator) break; + } + + break; } if(noneFound) break; @@ -417,16 +415,17 @@ namespace DiscImageChef.Filesystems.ISO9660 { ushort nextSignature = BigEndianBitConverter.ToUInt16(ca_data, ca_off); - // Apple never said to include its extensions inside a continuation area, but just in case - if(nextSignature == AppleMagic) - if(ca_data[ca_off + 3] == 1 && ca_data[ca_off + 2] == 7) Apple = true; - else Apple |= ca_data[ca_off + 3] != 1; - - if(nextSignature == SUSP_Reference && ca_off + ca_data[ca_off + 2] <= ca.ca_length_be) - { - byte[] er = new byte[ca_data[ca_off + 2]]; - Array.Copy(ca_data, ca_off, er, 0, er.Length); - refareas.Add(er); + switch(nextSignature) { + // Apple never said to include its extensions inside a continuation area, but just in case + case AppleMagic: + if(ca_data[ca_off + 3] == 1 && ca_data[ca_off + 2] == 7) Apple = true; + else Apple |= ca_data[ca_off + 3] != 1; + break; + case SUSP_Reference when ca_off + ca_data[ca_off + 2] <= ca.ca_length_be: + byte[] er = new byte[ca_data[ca_off + 2]]; + Array.Copy(ca_data, ca_off, er, 0, er.Length); + refareas.Add(er); + break; } RRIP |= nextSignature == RRIP_Magic || nextSignature == RRIP_PosixAttributes || diff --git a/DiscImageChef.Filesystems/LisaFS/Xattr.cs b/DiscImageChef.Filesystems/LisaFS/Xattr.cs index 3c9890a5b..40b5501cd 100644 --- a/DiscImageChef.Filesystems/LisaFS/Xattr.cs +++ b/DiscImageChef.Filesystems/LisaFS/Xattr.cs @@ -167,17 +167,14 @@ namespace DiscImageChef.Filesystems.LisaFS if(error != Errno.NoError) return error; - if(xattr == "com.apple.lisa.password" && file.password_valid > 0) - { - buf = new byte[8]; - Array.Copy(file.password, 0, buf, 0, 8); - return Errno.NoError; - } - - if(xattr == "com.apple.lisa.serial" && file.serial > 0) - { - buf = Encoding.ASCII.GetBytes(file.serial.ToString()); - return Errno.NoError; + switch(xattr) { + case "com.apple.lisa.password" when file.password_valid > 0: + buf = new byte[8]; + Array.Copy(file.password, 0, buf, 0, 8); + return Errno.NoError; + case "com.apple.lisa.serial" when file.serial > 0: + buf = Encoding.ASCII.GetBytes(file.serial.ToString()); + return Errno.NoError; } if(!ArrayHelpers.ArrayIsNullOrEmpty(file.LisaInfo) && xattr == "com.apple.lisa.label") diff --git a/DiscImageChef.Filesystems/MinixFS.cs b/DiscImageChef.Filesystems/MinixFS.cs index 8601255c5..5112f01a4 100644 --- a/DiscImageChef.Filesystems/MinixFS.cs +++ b/DiscImageChef.Filesystems/MinixFS.cs @@ -166,20 +166,21 @@ namespace DiscImageChef.Filesystems filenamesize = 60; littleEndian = magic != MINIX3_CIGAM || magic == MINIX2_CIGAM || magic == MINIX_CIGAM; - if(magic == MINIX3_MAGIC || magic == MINIX3_CIGAM) - { - minixVersion = "Minix v3 filesystem"; - xmlFSType.Type = "Minix v3"; - } - else if(magic == MINIX2_MAGIC || magic == MINIX2_CIGAM) - { - minixVersion = "Minix 3 v2 filesystem"; - xmlFSType.Type = "Minix 3 v2"; - } - else - { - minixVersion = "Minix 3 v1 filesystem"; - xmlFSType.Type = "Minix 3 v1"; + switch(magic) { + case MINIX3_MAGIC: + case MINIX3_CIGAM: + minixVersion = "Minix v3 filesystem"; + xmlFSType.Type = "Minix v3"; + break; + case MINIX2_MAGIC: + case MINIX2_CIGAM: + minixVersion = "Minix 3 v2 filesystem"; + xmlFSType.Type = "Minix 3 v2"; + break; + default: + minixVersion = "Minix 3 v1 filesystem"; + xmlFSType.Type = "Minix 3 v1"; + break; } minix3 = true; diff --git a/DiscImageChef.Filesystems/Squash.cs b/DiscImageChef.Filesystems/Squash.cs index 56a684abc..35c7bbc52 100644 --- a/DiscImageChef.Filesystems/Squash.cs +++ b/DiscImageChef.Filesystems/Squash.cs @@ -123,17 +123,17 @@ namespace DiscImageChef.Filesystems SquashSuperBlock sqSb = new SquashSuperBlock(); bool littleEndian = true; - if(magic == Squash_MAGIC) - { - IntPtr sqSbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(sqSb)); - Marshal.Copy(sector, 0, sqSbPtr, Marshal.SizeOf(sqSb)); - sqSb = (SquashSuperBlock)Marshal.PtrToStructure(sqSbPtr, typeof(SquashSuperBlock)); - Marshal.FreeHGlobal(sqSbPtr); - } - else if(magic == Squash_CIGAM) - { - sqSb = BigEndianMarshal.ByteArrayToStructureBigEndian(sector); - littleEndian = false; + switch(magic) { + case Squash_MAGIC: + IntPtr sqSbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(sqSb)); + Marshal.Copy(sector, 0, sqSbPtr, Marshal.SizeOf(sqSb)); + sqSb = (SquashSuperBlock)Marshal.PtrToStructure(sqSbPtr, typeof(SquashSuperBlock)); + Marshal.FreeHGlobal(sqSbPtr); + break; + case Squash_CIGAM: + sqSb = BigEndianMarshal.ByteArrayToStructureBigEndian(sector); + littleEndian = false; + break; } StringBuilder sbInformation = new StringBuilder(); diff --git a/DiscImageChef.Filesystems/UDF.cs b/DiscImageChef.Filesystems/UDF.cs index 02e4eaab1..304a7f1b2 100644 --- a/DiscImageChef.Filesystems/UDF.cs +++ b/DiscImageChef.Filesystems/UDF.cs @@ -369,20 +369,19 @@ namespace DiscImageChef.Filesystems { if(tagId == TagIdentifier.TerminatingDescriptor) break; - if(tagId == TagIdentifier.LogicalVolumeDescriptor) - { - IntPtr lvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvd)); - Marshal.Copy(sector, 0, lvdPtr, Marshal.SizeOf(lvd)); - lvd = (LogicalVolumeDescriptor)Marshal.PtrToStructure(lvdPtr, typeof(LogicalVolumeDescriptor)); - Marshal.FreeHGlobal(lvdPtr); - } - - if(tagId == TagIdentifier.PrimaryVolumeDescriptor) - { - IntPtr pvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(pvd)); - Marshal.Copy(sector, 0, pvdPtr, Marshal.SizeOf(pvd)); - pvd = (PrimaryVolumeDescriptor)Marshal.PtrToStructure(pvdPtr, typeof(PrimaryVolumeDescriptor)); - Marshal.FreeHGlobal(pvdPtr); + switch(tagId) { + case TagIdentifier.LogicalVolumeDescriptor: + IntPtr lvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvd)); + Marshal.Copy(sector, 0, lvdPtr, Marshal.SizeOf(lvd)); + lvd = (LogicalVolumeDescriptor)Marshal.PtrToStructure(lvdPtr, typeof(LogicalVolumeDescriptor)); + Marshal.FreeHGlobal(lvdPtr); + break; + case TagIdentifier.PrimaryVolumeDescriptor: + IntPtr pvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(pvd)); + Marshal.Copy(sector, 0, pvdPtr, Marshal.SizeOf(pvd)); + pvd = (PrimaryVolumeDescriptor)Marshal.PtrToStructure(pvdPtr, typeof(PrimaryVolumeDescriptor)); + Marshal.FreeHGlobal(pvdPtr); + break; } } else break; diff --git a/DiscImageChef.Filesystems/ext2FS.cs b/DiscImageChef.Filesystems/ext2FS.cs index d3e3dd4d6..4c4b80170 100644 --- a/DiscImageChef.Filesystems/ext2FS.cs +++ b/DiscImageChef.Filesystems/ext2FS.cs @@ -121,53 +121,51 @@ namespace DiscImageChef.Filesystems xmlFSType = new Schemas.FileSystemType(); - if(supblk.magic == ext2OldFSMagic) - { - sb.AppendLine("ext2 (old) filesystem"); - xmlFSType.Type = "ext2"; - } - else if(supblk.magic == ext2FSMagic) - { - ext3 |= (supblk.ftr_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) == EXT3_FEATURE_COMPAT_HAS_JOURNAL || - (supblk.ftr_incompat & EXT3_FEATURE_INCOMPAT_RECOVER) == EXT3_FEATURE_INCOMPAT_RECOVER || - (supblk.ftr_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) == EXT3_FEATURE_INCOMPAT_JOURNAL_DEV; - - if((supblk.ftr_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) == EXT4_FEATURE_RO_COMPAT_HUGE_FILE || - (supblk.ftr_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM) == EXT4_FEATURE_RO_COMPAT_GDT_CSUM || - (supblk.ftr_ro_compat & EXT4_FEATURE_RO_COMPAT_DIR_NLINK) == EXT4_FEATURE_RO_COMPAT_DIR_NLINK || - (supblk.ftr_ro_compat & EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE) == EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE || - (supblk.ftr_incompat & EXT4_FEATURE_INCOMPAT_64BIT) == EXT4_FEATURE_INCOMPAT_64BIT || - (supblk.ftr_incompat & EXT4_FEATURE_INCOMPAT_MMP) == EXT4_FEATURE_INCOMPAT_MMP || - (supblk.ftr_incompat & EXT4_FEATURE_INCOMPAT_FLEX_BG) == EXT4_FEATURE_INCOMPAT_FLEX_BG || - (supblk.ftr_incompat & EXT4_FEATURE_INCOMPAT_EA_INODE) == EXT4_FEATURE_INCOMPAT_EA_INODE || - (supblk.ftr_incompat & EXT4_FEATURE_INCOMPAT_DIRDATA) == EXT4_FEATURE_INCOMPAT_DIRDATA) - { - ext3 = false; - ext4 = true; - } - - new_ext2 |= !ext3 && !ext4; - - if(new_ext2) - { - sb.AppendLine("ext2 filesystem"); + switch(supblk.magic) { + case ext2OldFSMagic: + sb.AppendLine("ext2 (old) filesystem"); xmlFSType.Type = "ext2"; - } - if(ext3) - { - sb.AppendLine("ext3 filesystem"); - xmlFSType.Type = "ext3"; - } - if(ext4) - { - sb.AppendLine("ext4 filesystem"); - xmlFSType.Type = "ext4"; - } - } - else - { - information = "Not a ext2/3/4 filesystem" + Environment.NewLine; - return; + break; + case ext2FSMagic: + ext3 |= (supblk.ftr_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) == EXT3_FEATURE_COMPAT_HAS_JOURNAL || + (supblk.ftr_incompat & EXT3_FEATURE_INCOMPAT_RECOVER) == EXT3_FEATURE_INCOMPAT_RECOVER || + (supblk.ftr_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) == EXT3_FEATURE_INCOMPAT_JOURNAL_DEV; + + if((supblk.ftr_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) == EXT4_FEATURE_RO_COMPAT_HUGE_FILE || + (supblk.ftr_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM) == EXT4_FEATURE_RO_COMPAT_GDT_CSUM || + (supblk.ftr_ro_compat & EXT4_FEATURE_RO_COMPAT_DIR_NLINK) == EXT4_FEATURE_RO_COMPAT_DIR_NLINK || + (supblk.ftr_ro_compat & EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE) == EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE || + (supblk.ftr_incompat & EXT4_FEATURE_INCOMPAT_64BIT) == EXT4_FEATURE_INCOMPAT_64BIT || + (supblk.ftr_incompat & EXT4_FEATURE_INCOMPAT_MMP) == EXT4_FEATURE_INCOMPAT_MMP || + (supblk.ftr_incompat & EXT4_FEATURE_INCOMPAT_FLEX_BG) == EXT4_FEATURE_INCOMPAT_FLEX_BG || + (supblk.ftr_incompat & EXT4_FEATURE_INCOMPAT_EA_INODE) == EXT4_FEATURE_INCOMPAT_EA_INODE || + (supblk.ftr_incompat & EXT4_FEATURE_INCOMPAT_DIRDATA) == EXT4_FEATURE_INCOMPAT_DIRDATA) + { + ext3 = false; + ext4 = true; + } + + new_ext2 |= !ext3 && !ext4; + + if(new_ext2) + { + sb.AppendLine("ext2 filesystem"); + xmlFSType.Type = "ext2"; + } + if(ext3) + { + sb.AppendLine("ext3 filesystem"); + xmlFSType.Type = "ext3"; + } + if(ext4) + { + sb.AppendLine("ext4 filesystem"); + xmlFSType.Type = "ext4"; + } + break; + default: + information = "Not a ext2/3/4 filesystem" + Environment.NewLine; + return; } string ext_os; diff --git a/DiscImageChef.Interop/DetectOS.cs b/DiscImageChef.Interop/DetectOS.cs index 0c4a5d712..a2bbec3b4 100644 --- a/DiscImageChef.Interop/DetectOS.cs +++ b/DiscImageChef.Interop/DetectOS.cs @@ -197,8 +197,10 @@ namespace DiscImageChef.Interop case PlatformID.MacOSX: if(Environment.OSVersion.Version.Major == 1) { - if(Environment.OSVersion.Version.Minor == 3) return "10.0"; - if(Environment.OSVersion.Version.Minor == 4) return "10.1"; + switch(Environment.OSVersion.Version.Minor) { + case 3: return "10.0"; + case 4: return "10.1"; + } goto default; } diff --git a/DiscImageChef.Partitions/Acorn.cs b/DiscImageChef.Partitions/Acorn.cs index a227e2a7d..0c6af2b92 100644 --- a/DiscImageChef.Partitions/Acorn.cs +++ b/DiscImageChef.Partitions/Acorn.cs @@ -109,60 +109,66 @@ namespace DiscImageChef.Partitions } } - if((bootBlock.flags & TYPE_MASK) == TYPE_LINUX) - { - LinuxTable table = new LinuxTable(); - IntPtr tablePtr = Marshal.AllocHGlobal(512); - Marshal.Copy(map, 0, tablePtr, 512); - table = (LinuxTable)Marshal.PtrToStructure(tablePtr, typeof(LinuxTable)); - Marshal.FreeHGlobal(tablePtr); - - foreach(LinuxEntry entry in table.entries) + switch(bootBlock.flags & TYPE_MASK) { + case TYPE_LINUX: { - Partition part = new Partition - { - Start = (ulong)(mapSector + entry.start), - Size = entry.size, - Length = (ulong)(entry.size * sector.Length), - Sequence = counter, - Scheme = Name - }; - part.Offset = part.Start * (ulong)sector.Length; - if(entry.magic == LINUX_MAGIC || entry.magic == SWAP_MAGIC) - { - partitions.Add(part); - counter++; - } - } - } - else if((bootBlock.flags & TYPE_MASK) == TYPE_RISCIX_MFM || - (bootBlock.flags & TYPE_MASK) == TYPE_RISCIX_SCSI) - { - RiscIxTable table = new RiscIxTable(); - IntPtr tablePtr = Marshal.AllocHGlobal(512); - Marshal.Copy(map, 0, tablePtr, 512); - table = (RiscIxTable)Marshal.PtrToStructure(tablePtr, typeof(RiscIxTable)); - Marshal.FreeHGlobal(tablePtr); + LinuxTable table = new LinuxTable(); + IntPtr tablePtr = Marshal.AllocHGlobal(512); + Marshal.Copy(map, 0, tablePtr, 512); + table = (LinuxTable)Marshal.PtrToStructure(tablePtr, typeof(LinuxTable)); + Marshal.FreeHGlobal(tablePtr); - if(table.magic == RISCIX_MAGIC) - foreach(RiscIxEntry entry in table.partitions) + foreach(LinuxEntry entry in table.entries) { Partition part = new Partition { Start = (ulong)(mapSector + entry.start), - Size = entry.length, - Length = (ulong)(entry.length * sector.Length), - Name = StringHandlers.CToString(entry.name, Encoding.GetEncoding("iso-8859-1")), + Size = entry.size, + Length = (ulong)(entry.size * sector.Length), Sequence = counter, Scheme = Name }; part.Offset = part.Start * (ulong)sector.Length; - if(entry.length > 0) + if(entry.magic == LINUX_MAGIC || entry.magic == SWAP_MAGIC) { partitions.Add(part); counter++; } } + + break; + } + case TYPE_RISCIX_MFM: + case TYPE_RISCIX_SCSI: + { + RiscIxTable table = new RiscIxTable(); + IntPtr tablePtr = Marshal.AllocHGlobal(512); + Marshal.Copy(map, 0, tablePtr, 512); + table = (RiscIxTable)Marshal.PtrToStructure(tablePtr, typeof(RiscIxTable)); + Marshal.FreeHGlobal(tablePtr); + + if(table.magic == RISCIX_MAGIC) + foreach(RiscIxEntry entry in table.partitions) + { + Partition part = new Partition + { + Start = (ulong)(mapSector + entry.start), + Size = entry.length, + Length = (ulong)(entry.length * sector.Length), + Name = StringHandlers.CToString(entry.name, Encoding.GetEncoding("iso-8859-1")), + Sequence = counter, + Scheme = Name + }; + part.Offset = part.Start * (ulong)sector.Length; + if(entry.length > 0) + { + partitions.Add(part); + counter++; + } + } + + break; + } } return !(partitions.Count == 0); diff --git a/DiscImageChef.Partitions/Atari.cs b/DiscImageChef.Partitions/Atari.cs index 41d23a2a8..c23143ee2 100644 --- a/DiscImageChef.Partitions/Atari.cs +++ b/DiscImageChef.Partitions/Atari.cs @@ -140,175 +140,184 @@ namespace DiscImageChef.Partitions { uint type = table.entries[i].type & 0x00FFFFFF; - if(type == TypeGEMDOS || type == TypeBigGEMDOS || type == TypeLinux || type == TypeSwap || - type == TypeRAW || type == TypeNetBSD || type == TypeNetBSDSwap || type == TypeSysV || - type == TypeMac || type == TypeMinix || type == TypeMinix2) - { - validTable = true; + switch(type) { + case TypeGEMDOS: + case TypeBigGEMDOS: + case TypeLinux: + case TypeSwap: + case TypeRAW: + case TypeNetBSD: + case TypeNetBSDSwap: + case TypeSysV: + case TypeMac: + case TypeMinix: + case TypeMinix2: + validTable = true; - if(table.entries[i].start <= imagePlugin.GetSectors()) - { - if(table.entries[i].start + table.entries[i].length > imagePlugin.GetSectors()) - DicConsole.DebugWriteLine("Atari partition plugin", - "WARNING: End of partition goes beyond device size"); - - ulong sectorSize = imagePlugin.GetSectorSize(); - if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048; - - byte[] partType = new byte[3]; - partType[0] = (byte)((type & 0xFF0000) >> 16); - partType[1] = (byte)((type & 0x00FF00) >> 8); - partType[2] = (byte)(type & 0x0000FF); - - CommonTypes.Partition part = new CommonTypes.Partition + if(table.entries[i].start <= imagePlugin.GetSectors()) { - Size = table.entries[i].length * sectorSize, - Length = table.entries[i].length, - Sequence = partitionSequence, - Name = "", - Offset = table.entries[i].start * sectorSize, - Start = table.entries[i].start, - Type = Encoding.ASCII.GetString(partType), - Scheme = Name - }; - switch(type) - { - case TypeGEMDOS: - part.Description = "Atari GEMDOS partition"; - break; - case TypeBigGEMDOS: - part.Description = "Atari GEMDOS partition bigger than 32 MiB"; - break; - case TypeLinux: - part.Description = "Linux partition"; - break; - case TypeSwap: - part.Description = "Swap partition"; - break; - case TypeRAW: - part.Description = "RAW partition"; - break; - case TypeNetBSD: - part.Description = "NetBSD partition"; - break; - case TypeNetBSDSwap: - part.Description = "NetBSD swap partition"; - break; - case TypeSysV: - part.Description = "Atari UNIX partition"; - break; - case TypeMac: - part.Description = "Macintosh partition"; - break; - case TypeMinix: - case TypeMinix2: - part.Description = "MINIX partition"; - break; - default: - part.Description = "Unknown partition type"; - break; + if(table.entries[i].start + table.entries[i].length > imagePlugin.GetSectors()) + DicConsole.DebugWriteLine("Atari partition plugin", + "WARNING: End of partition goes beyond device size"); + + ulong sectorSize = imagePlugin.GetSectorSize(); + if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048; + + byte[] partType = new byte[3]; + partType[0] = (byte)((type & 0xFF0000) >> 16); + partType[1] = (byte)((type & 0x00FF00) >> 8); + partType[2] = (byte)(type & 0x0000FF); + + CommonTypes.Partition part = new CommonTypes.Partition + { + Size = table.entries[i].length * sectorSize, + Length = table.entries[i].length, + Sequence = partitionSequence, + Name = "", + Offset = table.entries[i].start * sectorSize, + Start = table.entries[i].start, + Type = Encoding.ASCII.GetString(partType), + Scheme = Name + }; + switch(type) + { + case TypeGEMDOS: + part.Description = "Atari GEMDOS partition"; + break; + case TypeBigGEMDOS: + part.Description = "Atari GEMDOS partition bigger than 32 MiB"; + break; + case TypeLinux: + part.Description = "Linux partition"; + break; + case TypeSwap: + part.Description = "Swap partition"; + break; + case TypeRAW: + part.Description = "RAW partition"; + break; + case TypeNetBSD: + part.Description = "NetBSD partition"; + break; + case TypeNetBSDSwap: + part.Description = "NetBSD swap partition"; + break; + case TypeSysV: + part.Description = "Atari UNIX partition"; + break; + case TypeMac: + part.Description = "Macintosh partition"; + break; + case TypeMinix: + case TypeMinix2: + part.Description = "MINIX partition"; + break; + default: + part.Description = "Unknown partition type"; + break; + } + + partitions.Add(part); + partitionSequence++; } - partitions.Add(part); - partitionSequence++; - } - } + break; + case TypeExtended: + byte[] extendedSector = imagePlugin.ReadSector(table.entries[i].start); + AtariTable extendedTable = new AtariTable(); + extendedTable.entries = new AtariEntry[4]; - if(type == TypeExtended) - { - byte[] extendedSector = imagePlugin.ReadSector(table.entries[i].start); - AtariTable extendedTable = new AtariTable(); - extendedTable.entries = new AtariEntry[4]; - - for(int j = 0; j < 4; j++) - { - extendedTable.entries[j].type = - BigEndianBitConverter.ToUInt32(extendedSector, 454 + j * 12 + 0); - extendedTable.entries[j].start = - BigEndianBitConverter.ToUInt32(extendedSector, 454 + j * 12 + 4); - extendedTable.entries[j].length = - BigEndianBitConverter.ToUInt32(extendedSector, 454 + j * 12 + 8); - } - - for(int j = 0; j < 4; j++) - { - uint extendedType = extendedTable.entries[j].type & 0x00FFFFFF; - - if(extendedType == TypeGEMDOS || extendedType == TypeBigGEMDOS || extendedType == TypeLinux || - extendedType == TypeSwap || extendedType == TypeRAW || extendedType == TypeNetBSD || - extendedType == TypeNetBSDSwap || extendedType == TypeSysV || extendedType == TypeMac || - extendedType == TypeMinix || extendedType == TypeMinix2) + for(int j = 0; j < 4; j++) { - validTable = true; - if(extendedTable.entries[j].start <= imagePlugin.GetSectors()) + extendedTable.entries[j].type = + BigEndianBitConverter.ToUInt32(extendedSector, 454 + j * 12 + 0); + extendedTable.entries[j].start = + BigEndianBitConverter.ToUInt32(extendedSector, 454 + j * 12 + 4); + extendedTable.entries[j].length = + BigEndianBitConverter.ToUInt32(extendedSector, 454 + j * 12 + 8); + } + + for(int j = 0; j < 4; j++) + { + uint extendedType = extendedTable.entries[j].type & 0x00FFFFFF; + + if(extendedType == TypeGEMDOS || extendedType == TypeBigGEMDOS || extendedType == TypeLinux || + extendedType == TypeSwap || extendedType == TypeRAW || extendedType == TypeNetBSD || + extendedType == TypeNetBSDSwap || extendedType == TypeSysV || extendedType == TypeMac || + extendedType == TypeMinix || extendedType == TypeMinix2) { - if(extendedTable.entries[j].start + extendedTable.entries[j].length > - imagePlugin.GetSectors()) - DicConsole.DebugWriteLine("Atari partition plugin", - "WARNING: End of partition goes beyond device size"); - - ulong sectorSize = imagePlugin.GetSectorSize(); - if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048; - - byte[] partType = new byte[3]; - partType[0] = (byte)((extendedType & 0xFF0000) >> 16); - partType[1] = (byte)((extendedType & 0x00FF00) >> 8); - partType[2] = (byte)(extendedType & 0x0000FF); - - CommonTypes.Partition part = new CommonTypes.Partition + validTable = true; + if(extendedTable.entries[j].start <= imagePlugin.GetSectors()) { - Size = extendedTable.entries[j].length * sectorSize, - Length = extendedTable.entries[j].length, - Sequence = partitionSequence, - Name = "", - Offset = extendedTable.entries[j].start * sectorSize, - Start = extendedTable.entries[j].start, - Type = Encoding.ASCII.GetString(partType), - Scheme = Name - }; - switch(extendedType) - { - case TypeGEMDOS: - part.Description = "Atari GEMDOS partition"; - break; - case TypeBigGEMDOS: - part.Description = "Atari GEMDOS partition bigger than 32 MiB"; - break; - case TypeLinux: - part.Description = "Linux partition"; - break; - case TypeSwap: - part.Description = "Swap partition"; - break; - case TypeRAW: - part.Description = "RAW partition"; - break; - case TypeNetBSD: - part.Description = "NetBSD partition"; - break; - case TypeNetBSDSwap: - part.Description = "NetBSD swap partition"; - break; - case TypeSysV: - part.Description = "Atari UNIX partition"; - break; - case TypeMac: - part.Description = "Macintosh partition"; - break; - case TypeMinix: - case TypeMinix2: - part.Description = "MINIX partition"; - break; - default: - part.Description = "Unknown partition type"; - break; + if(extendedTable.entries[j].start + extendedTable.entries[j].length > + imagePlugin.GetSectors()) + DicConsole.DebugWriteLine("Atari partition plugin", + "WARNING: End of partition goes beyond device size"); + + ulong sectorSize = imagePlugin.GetSectorSize(); + if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048; + + byte[] partType = new byte[3]; + partType[0] = (byte)((extendedType & 0xFF0000) >> 16); + partType[1] = (byte)((extendedType & 0x00FF00) >> 8); + partType[2] = (byte)(extendedType & 0x0000FF); + + CommonTypes.Partition part = new CommonTypes.Partition + { + Size = extendedTable.entries[j].length * sectorSize, + Length = extendedTable.entries[j].length, + Sequence = partitionSequence, + Name = "", + Offset = extendedTable.entries[j].start * sectorSize, + Start = extendedTable.entries[j].start, + Type = Encoding.ASCII.GetString(partType), + Scheme = Name + }; + switch(extendedType) + { + case TypeGEMDOS: + part.Description = "Atari GEMDOS partition"; + break; + case TypeBigGEMDOS: + part.Description = "Atari GEMDOS partition bigger than 32 MiB"; + break; + case TypeLinux: + part.Description = "Linux partition"; + break; + case TypeSwap: + part.Description = "Swap partition"; + break; + case TypeRAW: + part.Description = "RAW partition"; + break; + case TypeNetBSD: + part.Description = "NetBSD partition"; + break; + case TypeNetBSDSwap: + part.Description = "NetBSD swap partition"; + break; + case TypeSysV: + part.Description = "Atari UNIX partition"; + break; + case TypeMac: + part.Description = "Macintosh partition"; + break; + case TypeMinix: + case TypeMinix2: + part.Description = "MINIX partition"; + break; + default: + part.Description = "Unknown partition type"; + break; + } + + partitions.Add(part); + partitionSequence++; } - - partitions.Add(part); - partitionSequence++; } } - } + + break; } } diff --git a/DiscImageChef.Tests.Devices/SCSI/MMC.cs b/DiscImageChef.Tests.Devices/SCSI/MMC.cs index 66a2b6a2b..e2e2953f8 100644 --- a/DiscImageChef.Tests.Devices/SCSI/MMC.cs +++ b/DiscImageChef.Tests.Devices/SCSI/MMC.cs @@ -1399,45 +1399,46 @@ namespace DiscImageChef.Tests.Devices.SCSI DicConsole.WriteLine("Format"); DicConsole.WriteLine("Available values:"); - if(mediaType == MmcDiscStructureMediaType.Dvd) - { - DicConsole.WriteLine("\t{0} {1} {2} {3}", MmcDiscStructureFormat.PhysicalInformation, - MmcDiscStructureFormat.CopyrightInformation, - MmcDiscStructureFormat.DiscKey, - MmcDiscStructureFormat.BurstCuttingArea); - DicConsole.WriteLine("\t{0} {1} {2} {3}", - MmcDiscStructureFormat.DiscManufacturingInformation, - MmcDiscStructureFormat.SectorCopyrightInformation, - MmcDiscStructureFormat.MediaIdentifier, - MmcDiscStructureFormat.MediaKeyBlock); - DicConsole.WriteLine("\t{0} {1} {2} {3}", MmcDiscStructureFormat.DvdramDds, - MmcDiscStructureFormat.DvdramMediumStatus, - MmcDiscStructureFormat.DvdramSpareAreaInformation, - MmcDiscStructureFormat.DvdramRecordingType); - DicConsole.WriteLine("\t{0} {1} {2} {3}", MmcDiscStructureFormat.LastBorderOutRmd, - MmcDiscStructureFormat.SpecifiedRmd, - MmcDiscStructureFormat.PreRecordedInfo, - MmcDiscStructureFormat.DvdrMediaIdentifier); - DicConsole.WriteLine("\t{0} {1} {2} {3}", MmcDiscStructureFormat.DvdrPhysicalInformation, - MmcDiscStructureFormat.Adip, - MmcDiscStructureFormat.HddvdCopyrightInformation, - MmcDiscStructureFormat.DvdAacs); - DicConsole.WriteLine("\t{0} {1} {2} {3}", MmcDiscStructureFormat.HddvdrMediumStatus, - MmcDiscStructureFormat.HddvdrLastRmd, - MmcDiscStructureFormat.DvdrLayerCapacity, - MmcDiscStructureFormat.MiddleZoneStart); - DicConsole.WriteLine("\t{0} {1} {2} {3}", MmcDiscStructureFormat.JumpIntervalSize, - MmcDiscStructureFormat.ManualLayerJumpStartLba, - MmcDiscStructureFormat.RemapAnchorPoint, MmcDiscStructureFormat.Dcb); - } - if(mediaType == MmcDiscStructureMediaType.Bd) - { - DicConsole.WriteLine("\t{0} {1} {2} {3}", MmcDiscStructureFormat.DiscInformation, - MmcDiscStructureFormat.BdBurstCuttingArea, - MmcDiscStructureFormat.BdDds, MmcDiscStructureFormat.CartridgeStatus); - DicConsole.WriteLine("\t{0} {1} {2}", MmcDiscStructureFormat.BdSpareAreaInformation, - MmcDiscStructureFormat.RawDfl, MmcDiscStructureFormat.Pac); + switch(mediaType) { + case MmcDiscStructureMediaType.Dvd: + DicConsole.WriteLine("\t{0} {1} {2} {3}", MmcDiscStructureFormat.PhysicalInformation, + MmcDiscStructureFormat.CopyrightInformation, + MmcDiscStructureFormat.DiscKey, + MmcDiscStructureFormat.BurstCuttingArea); + DicConsole.WriteLine("\t{0} {1} {2} {3}", + MmcDiscStructureFormat.DiscManufacturingInformation, + MmcDiscStructureFormat.SectorCopyrightInformation, + MmcDiscStructureFormat.MediaIdentifier, + MmcDiscStructureFormat.MediaKeyBlock); + DicConsole.WriteLine("\t{0} {1} {2} {3}", MmcDiscStructureFormat.DvdramDds, + MmcDiscStructureFormat.DvdramMediumStatus, + MmcDiscStructureFormat.DvdramSpareAreaInformation, + MmcDiscStructureFormat.DvdramRecordingType); + DicConsole.WriteLine("\t{0} {1} {2} {3}", MmcDiscStructureFormat.LastBorderOutRmd, + MmcDiscStructureFormat.SpecifiedRmd, + MmcDiscStructureFormat.PreRecordedInfo, + MmcDiscStructureFormat.DvdrMediaIdentifier); + DicConsole.WriteLine("\t{0} {1} {2} {3}", MmcDiscStructureFormat.DvdrPhysicalInformation, + MmcDiscStructureFormat.Adip, + MmcDiscStructureFormat.HddvdCopyrightInformation, + MmcDiscStructureFormat.DvdAacs); + DicConsole.WriteLine("\t{0} {1} {2} {3}", MmcDiscStructureFormat.HddvdrMediumStatus, + MmcDiscStructureFormat.HddvdrLastRmd, + MmcDiscStructureFormat.DvdrLayerCapacity, + MmcDiscStructureFormat.MiddleZoneStart); + DicConsole.WriteLine("\t{0} {1} {2} {3}", MmcDiscStructureFormat.JumpIntervalSize, + MmcDiscStructureFormat.ManualLayerJumpStartLba, + MmcDiscStructureFormat.RemapAnchorPoint, MmcDiscStructureFormat.Dcb); + break; + case MmcDiscStructureMediaType.Bd: + DicConsole.WriteLine("\t{0} {1} {2} {3}", MmcDiscStructureFormat.DiscInformation, + MmcDiscStructureFormat.BdBurstCuttingArea, + MmcDiscStructureFormat.BdDds, MmcDiscStructureFormat.CartridgeStatus); + DicConsole.WriteLine("\t{0} {1} {2}", MmcDiscStructureFormat.BdSpareAreaInformation, + MmcDiscStructureFormat.RawDfl, MmcDiscStructureFormat.Pac); + break; } + DicConsole.WriteLine("\t{0} {1} {2} {3}", MmcDiscStructureFormat.AacsVolId, MmcDiscStructureFormat.AacsMediaSerial, MmcDiscStructureFormat.AacsMediaId, MmcDiscStructureFormat.Aacsmkb); diff --git a/DiscImageChef/Commands/DeviceInfo.cs b/DiscImageChef/Commands/DeviceInfo.cs index 3e45a3dd0..f138327fd 100644 --- a/DiscImageChef/Commands/DeviceInfo.cs +++ b/DiscImageChef/Commands/DeviceInfo.cs @@ -963,223 +963,223 @@ namespace DiscImageChef.Commands } } - if(devType == Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice) - { - byte[] confBuf; - sense = dev.GetConfiguration(out confBuf, out senseBuf, dev.Timeout, out duration); + switch(devType) { + case Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice: + byte[] confBuf; + sense = dev.GetConfiguration(out confBuf, out senseBuf, dev.Timeout, out duration); - if(!sense) - { - DataFile.WriteTo("Device-Info command", options.OutputPrefix, "_mmc_getconfiguration.bin", - "MMC GET CONFIGURATION", confBuf); - - Decoders.SCSI.MMC.Features.SeparatedFeatures ftr = - Decoders.SCSI.MMC.Features.Separate(confBuf); - - DicConsole.DebugWriteLine("Device-Info command", "GET CONFIGURATION length is {0} bytes", - ftr.DataLength); - DicConsole.DebugWriteLine("Device-Info command", - "GET CONFIGURATION current profile is {0:X4}h", - ftr.CurrentProfile); - if(ftr.Descriptors != null) + if(!sense) { - DicConsole.WriteLine("SCSI MMC GET CONFIGURATION Features:"); - foreach(Decoders.SCSI.MMC.Features.FeatureDescriptor desc in ftr.Descriptors) - { - DicConsole.DebugWriteLine("Device-Info command", "Feature {0:X4}h", desc.Code); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, "_mmc_getconfiguration.bin", + "MMC GET CONFIGURATION", confBuf); - switch(desc.Code) + Decoders.SCSI.MMC.Features.SeparatedFeatures ftr = + Decoders.SCSI.MMC.Features.Separate(confBuf); + + DicConsole.DebugWriteLine("Device-Info command", "GET CONFIGURATION length is {0} bytes", + ftr.DataLength); + DicConsole.DebugWriteLine("Device-Info command", + "GET CONFIGURATION current profile is {0:X4}h", + ftr.CurrentProfile); + if(ftr.Descriptors != null) + { + DicConsole.WriteLine("SCSI MMC GET CONFIGURATION Features:"); + foreach(Decoders.SCSI.MMC.Features.FeatureDescriptor desc in ftr.Descriptors) { - case 0x0000: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0000(desc.Data)); - break; - case 0x0001: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0001(desc.Data)); - break; - case 0x0002: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0002(desc.Data)); - break; - case 0x0003: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0003(desc.Data)); - break; - case 0x0004: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0004(desc.Data)); - break; - case 0x0010: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0010(desc.Data)); - break; - case 0x001D: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_001D(desc.Data)); - break; - case 0x001E: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_001E(desc.Data)); - break; - case 0x001F: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_001F(desc.Data)); - break; - case 0x0020: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0020(desc.Data)); - break; - case 0x0021: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0021(desc.Data)); - break; - case 0x0022: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0022(desc.Data)); - break; - case 0x0023: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0023(desc.Data)); - break; - case 0x0024: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0024(desc.Data)); - break; - case 0x0025: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0025(desc.Data)); - break; - case 0x0026: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0026(desc.Data)); - break; - case 0x0027: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0027(desc.Data)); - break; - case 0x0028: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0028(desc.Data)); - break; - case 0x0029: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0029(desc.Data)); - break; - case 0x002A: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_002A(desc.Data)); - break; - case 0x002B: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_002B(desc.Data)); - break; - case 0x002C: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_002C(desc.Data)); - break; - case 0x002D: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_002D(desc.Data)); - break; - case 0x002E: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_002E(desc.Data)); - break; - case 0x002F: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_002F(desc.Data)); - break; - case 0x0030: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0030(desc.Data)); - break; - case 0x0031: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0031(desc.Data)); - break; - case 0x0032: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0032(desc.Data)); - break; - case 0x0033: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0033(desc.Data)); - break; - case 0x0035: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0035(desc.Data)); - break; - case 0x0037: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0037(desc.Data)); - break; - case 0x0038: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0038(desc.Data)); - break; - case 0x003A: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_003A(desc.Data)); - break; - case 0x003B: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_003B(desc.Data)); - break; - case 0x0040: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0040(desc.Data)); - break; - case 0x0041: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0041(desc.Data)); - break; - case 0x0042: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0042(desc.Data)); - break; - case 0x0050: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0050(desc.Data)); - break; - case 0x0051: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0051(desc.Data)); - break; - case 0x0080: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0080(desc.Data)); - break; - case 0x0100: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0100(desc.Data)); - break; - case 0x0101: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0101(desc.Data)); - break; - case 0x0102: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0102(desc.Data)); - break; - case 0x0103: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0103(desc.Data)); - break; - case 0x0104: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0104(desc.Data)); - break; - case 0x0105: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0105(desc.Data)); - break; - case 0x0106: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0106(desc.Data)); - break; - case 0x0107: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0107(desc.Data)); - break; - case 0x0108: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0108(desc.Data)); - break; - case 0x0109: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0109(desc.Data)); - break; - case 0x010A: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_010A(desc.Data)); - break; - case 0x010B: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_010B(desc.Data)); - break; - case 0x010C: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_010C(desc.Data)); - break; - case 0x010D: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_010D(desc.Data)); - break; - case 0x010E: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_010E(desc.Data)); - break; - case 0x0110: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0110(desc.Data)); - break; - case 0x0113: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0113(desc.Data)); - break; - case 0x0142: - DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0142(desc.Data)); - break; - default: - DicConsole.WriteLine("Found unknown feature code {0:X4}h", desc.Code); - break; + DicConsole.DebugWriteLine("Device-Info command", "Feature {0:X4}h", desc.Code); + + switch(desc.Code) + { + case 0x0000: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0000(desc.Data)); + break; + case 0x0001: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0001(desc.Data)); + break; + case 0x0002: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0002(desc.Data)); + break; + case 0x0003: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0003(desc.Data)); + break; + case 0x0004: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0004(desc.Data)); + break; + case 0x0010: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0010(desc.Data)); + break; + case 0x001D: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_001D(desc.Data)); + break; + case 0x001E: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_001E(desc.Data)); + break; + case 0x001F: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_001F(desc.Data)); + break; + case 0x0020: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0020(desc.Data)); + break; + case 0x0021: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0021(desc.Data)); + break; + case 0x0022: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0022(desc.Data)); + break; + case 0x0023: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0023(desc.Data)); + break; + case 0x0024: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0024(desc.Data)); + break; + case 0x0025: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0025(desc.Data)); + break; + case 0x0026: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0026(desc.Data)); + break; + case 0x0027: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0027(desc.Data)); + break; + case 0x0028: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0028(desc.Data)); + break; + case 0x0029: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0029(desc.Data)); + break; + case 0x002A: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_002A(desc.Data)); + break; + case 0x002B: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_002B(desc.Data)); + break; + case 0x002C: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_002C(desc.Data)); + break; + case 0x002D: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_002D(desc.Data)); + break; + case 0x002E: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_002E(desc.Data)); + break; + case 0x002F: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_002F(desc.Data)); + break; + case 0x0030: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0030(desc.Data)); + break; + case 0x0031: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0031(desc.Data)); + break; + case 0x0032: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0032(desc.Data)); + break; + case 0x0033: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0033(desc.Data)); + break; + case 0x0035: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0035(desc.Data)); + break; + case 0x0037: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0037(desc.Data)); + break; + case 0x0038: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0038(desc.Data)); + break; + case 0x003A: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_003A(desc.Data)); + break; + case 0x003B: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_003B(desc.Data)); + break; + case 0x0040: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0040(desc.Data)); + break; + case 0x0041: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0041(desc.Data)); + break; + case 0x0042: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0042(desc.Data)); + break; + case 0x0050: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0050(desc.Data)); + break; + case 0x0051: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0051(desc.Data)); + break; + case 0x0080: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0080(desc.Data)); + break; + case 0x0100: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0100(desc.Data)); + break; + case 0x0101: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0101(desc.Data)); + break; + case 0x0102: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0102(desc.Data)); + break; + case 0x0103: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0103(desc.Data)); + break; + case 0x0104: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0104(desc.Data)); + break; + case 0x0105: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0105(desc.Data)); + break; + case 0x0106: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0106(desc.Data)); + break; + case 0x0107: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0107(desc.Data)); + break; + case 0x0108: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0108(desc.Data)); + break; + case 0x0109: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0109(desc.Data)); + break; + case 0x010A: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_010A(desc.Data)); + break; + case 0x010B: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_010B(desc.Data)); + break; + case 0x010C: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_010C(desc.Data)); + break; + case 0x010D: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_010D(desc.Data)); + break; + case 0x010E: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_010E(desc.Data)); + break; + case 0x0110: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0110(desc.Data)); + break; + case 0x0113: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0113(desc.Data)); + break; + case 0x0142: + DicConsole.WriteLine(Decoders.SCSI.MMC.Features.Prettify_0142(desc.Data)); + break; + default: + DicConsole.WriteLine("Found unknown feature code {0:X4}h", desc.Code); + break; + } } } + else + DicConsole.DebugWriteLine("Device-Info command", + "GET CONFIGURATION returned no feature descriptors"); } - else - DicConsole.DebugWriteLine("Device-Info command", - "GET CONFIGURATION returned no feature descriptors"); - } - // TODO: DVD drives respond correctly to BD status. - // While specification says if no medium is present - // it should inform all possible capabilities, - // testing drives show only supported media capabilities. - /* + // TODO: DVD drives respond correctly to BD status. + // While specification says if no medium is present + // it should inform all possible capabilities, + // testing drives show only supported media capabilities. + /* byte[] strBuf; sense = dev.ReadDiscStructure(out strBuf, out senseBuf, MmcDiscStructureMediaType.DVD, 0, 0, MmcDiscStructureFormat.CapabilityList, 0, dev.Timeout, out duration); @@ -1220,284 +1220,283 @@ namespace DiscImageChef.Commands } */ - #region Plextor - if(dev.Manufacturer == "PLEXTOR") - { - bool plxtSense = true; - bool plxtDvd = false; - byte[] plxtBuf = null; - - switch(dev.Model) + #region Plextor + if(dev.Manufacturer == "PLEXTOR") { - case "DVDR PX-708A": - case "DVDR PX-708A2": - case "DVDR PX-712A": - plxtDvd = true; - plxtSense = dev.PlextorReadEeprom(out plxtBuf, out senseBuf, dev.Timeout, - out duration); - break; - case "DVDR PX-714A": - case "DVDR PX-716A": - case "DVDR PX-716AL": - case "DVDR PX-755A": - case "DVDR PX-760A": - { - byte[] plxtBufSmall; - plxtBuf = new byte[256 * 4]; - for(byte i = 0; i < 4; i++) - { - plxtSense = dev.PlextorReadEepromBlock(out plxtBufSmall, out senseBuf, i, 256, - dev.Timeout, out duration); - if(plxtSense) break; + bool plxtSense = true; + bool plxtDvd = false; + byte[] plxtBuf = null; - Array.Copy(plxtBufSmall, 0, plxtBuf, i * 256, 256); + switch(dev.Model) + { + case "DVDR PX-708A": + case "DVDR PX-708A2": + case "DVDR PX-712A": + plxtDvd = true; + plxtSense = dev.PlextorReadEeprom(out plxtBuf, out senseBuf, dev.Timeout, + out duration); + break; + case "DVDR PX-714A": + case "DVDR PX-716A": + case "DVDR PX-716AL": + case "DVDR PX-755A": + case "DVDR PX-760A": + { + byte[] plxtBufSmall; + plxtBuf = new byte[256 * 4]; + for(byte i = 0; i < 4; i++) + { + plxtSense = dev.PlextorReadEepromBlock(out plxtBufSmall, out senseBuf, i, 256, + dev.Timeout, out duration); + if(plxtSense) break; + + Array.Copy(plxtBufSmall, 0, plxtBuf, i * 256, 256); + } + + plxtDvd = true; + break; } - - plxtDvd = true; - break; - } - default: - { - if(dev.Model.StartsWith("CD-R ", StringComparison.Ordinal)) - plxtSense = dev.PlextorReadEepromCdr(out plxtBuf, out senseBuf, dev.Timeout, - out duration); - break; - } - } - - if(!plxtSense) - { - DataFile.WriteTo("Device-Info command", options.OutputPrefix, "_plextor_eeprom.bin", - "PLEXTOR READ EEPROM", plxtBuf); - - ushort discs; - uint cdReadTime, cdWriteTime, dvdReadTime = 0, dvdWriteTime = 0; - - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - if(plxtDvd) - { - discs = BigEndianBitConverter.ToUInt16(plxtBuf, 0x0120); - cdReadTime = BigEndianBitConverter.ToUInt32(plxtBuf, 0x0122); - cdWriteTime = BigEndianBitConverter.ToUInt32(plxtBuf, 0x0126); - dvdReadTime = BigEndianBitConverter.ToUInt32(plxtBuf, 0x012A); - dvdWriteTime = BigEndianBitConverter.ToUInt32(plxtBuf, 0x012E); - } - else - { - discs = BigEndianBitConverter.ToUInt16(plxtBuf, 0x0078); - cdReadTime = BigEndianBitConverter.ToUInt32(plxtBuf, 0x006C); - cdWriteTime = BigEndianBitConverter.ToUInt32(plxtBuf, 0x007A); - } - - DicConsole.WriteLine("Drive has loaded a total of {0} discs", discs); - DicConsole - .WriteLine("Drive has spent {0} hours, {1} minutes and {2} seconds reading CDs", - cdReadTime / 3600, cdReadTime / 60 % 60, cdReadTime % 60); - DicConsole - .WriteLine("Drive has spent {0} hours, {1} minutes and {2} seconds writing CDs", - cdWriteTime / 3600, cdWriteTime / 60 % 60, cdWriteTime % 60); - if(plxtDvd) - { - DicConsole - .WriteLine("Drive has spent {0} hours, {1} minutes and {2} seconds reading DVDs", - dvdReadTime / 3600, dvdReadTime / 60 % 60, dvdReadTime % 60); - DicConsole - .WriteLine("Drive has spent {0} hours, {1} minutes and {2} seconds writing DVDs", - dvdWriteTime / 3600, dvdWriteTime / 60 % 60, dvdWriteTime % 60); - } - } - - bool plxtPwrRecEnabled; - ushort plxtPwrRecSpeed; - plxtSense = dev.PlextorGetPoweRec(out senseBuf, out plxtPwrRecEnabled, out plxtPwrRecSpeed, - dev.Timeout, out duration); - if(!plxtSense) - { - DicConsole.Write("Drive supports PoweRec"); - if(plxtPwrRecEnabled) - { - DicConsole.Write(", has it enabled"); - - if(plxtPwrRecSpeed > 0) - DicConsole.WriteLine(" and recommends {0} Kb/sec.", plxtPwrRecSpeed); - else DicConsole.WriteLine("."); - - ushort plxtPwrRecSelected, plxtPwrRecMax, plxtPwrRecLast; - plxtSense = dev.PlextorGetSpeeds(out senseBuf, out plxtPwrRecSelected, - out plxtPwrRecMax, out plxtPwrRecLast, dev.Timeout, - out duration); - - if(!plxtSense) + default: { - if(plxtPwrRecSelected > 0) - DicConsole - .WriteLine("Selected PoweRec speed for currently inserted media is {0} Kb/sec ({1}x)", - plxtPwrRecSelected, plxtPwrRecSelected / 177); - if(plxtPwrRecMax > 0) - DicConsole - .WriteLine("Maximum PoweRec speed for currently inserted media is {0} Kb/sec ({1}x)", - plxtPwrRecMax, plxtPwrRecMax / 177); - if(plxtPwrRecLast > 0) - DicConsole.WriteLine("Last used PoweRec was {0} Kb/sec ({1}x)", - plxtPwrRecLast, plxtPwrRecLast / 177); + if(dev.Model.StartsWith("CD-R ", StringComparison.Ordinal)) + plxtSense = dev.PlextorReadEepromCdr(out plxtBuf, out senseBuf, dev.Timeout, + out duration); + break; } } - else DicConsole.WriteLine("PoweRec is disabled"); - } - // TODO: Check it with a drive - plxtSense = dev.PlextorGetSilentMode(out plxtBuf, out senseBuf, dev.Timeout, out duration); - if(!plxtSense) - { - DicConsole.WriteLine("Drive supports Plextor SilentMode"); - if(plxtBuf[0] == 1) + if(!plxtSense) { - DicConsole.WriteLine("Plextor SilentMode is enabled:"); - if(plxtBuf[1] == 2) DicConsole.WriteLine("\tAccess time is slow"); - else DicConsole.WriteLine("\tAccess time is fast"); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, "_plextor_eeprom.bin", + "PLEXTOR READ EEPROM", plxtBuf); - if(plxtBuf[2] > 0) - DicConsole.WriteLine("\tCD read speed limited to {0}x", plxtBuf[2]); - if(plxtBuf[3] > 0 && plxtDvd) - DicConsole.WriteLine("\tDVD read speed limited to {0}x", plxtBuf[3]); - if(plxtBuf[4] > 0) - DicConsole.WriteLine("\tCD write speed limited to {0}x", plxtBuf[4]); - if(plxtBuf[6] > 0) - DicConsole.WriteLine("\tTray eject speed limited to {0}", -(plxtBuf[6] + 48)); - if(plxtBuf[7] > 0) - DicConsole.WriteLine("\tTray eject speed limited to {0}", plxtBuf[7] - 47); + ushort discs; + uint cdReadTime, cdWriteTime, dvdReadTime = 0, dvdWriteTime = 0; + + BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; + if(plxtDvd) + { + discs = BigEndianBitConverter.ToUInt16(plxtBuf, 0x0120); + cdReadTime = BigEndianBitConverter.ToUInt32(plxtBuf, 0x0122); + cdWriteTime = BigEndianBitConverter.ToUInt32(plxtBuf, 0x0126); + dvdReadTime = BigEndianBitConverter.ToUInt32(plxtBuf, 0x012A); + dvdWriteTime = BigEndianBitConverter.ToUInt32(plxtBuf, 0x012E); + } + else + { + discs = BigEndianBitConverter.ToUInt16(plxtBuf, 0x0078); + cdReadTime = BigEndianBitConverter.ToUInt32(plxtBuf, 0x006C); + cdWriteTime = BigEndianBitConverter.ToUInt32(plxtBuf, 0x007A); + } + + DicConsole.WriteLine("Drive has loaded a total of {0} discs", discs); + DicConsole + .WriteLine("Drive has spent {0} hours, {1} minutes and {2} seconds reading CDs", + cdReadTime / 3600, cdReadTime / 60 % 60, cdReadTime % 60); + DicConsole + .WriteLine("Drive has spent {0} hours, {1} minutes and {2} seconds writing CDs", + cdWriteTime / 3600, cdWriteTime / 60 % 60, cdWriteTime % 60); + if(plxtDvd) + { + DicConsole + .WriteLine("Drive has spent {0} hours, {1} minutes and {2} seconds reading DVDs", + dvdReadTime / 3600, dvdReadTime / 60 % 60, dvdReadTime % 60); + DicConsole + .WriteLine("Drive has spent {0} hours, {1} minutes and {2} seconds writing DVDs", + dvdWriteTime / 3600, dvdWriteTime / 60 % 60, dvdWriteTime % 60); + } } - } - plxtSense = dev.PlextorGetGigaRec(out plxtBuf, out senseBuf, dev.Timeout, out duration); - if(!plxtSense) DicConsole.WriteLine("Drive supports Plextor GigaRec"); + bool plxtPwrRecEnabled; + ushort plxtPwrRecSpeed; + plxtSense = dev.PlextorGetPoweRec(out senseBuf, out plxtPwrRecEnabled, out plxtPwrRecSpeed, + dev.Timeout, out duration); + if(!plxtSense) + { + DicConsole.Write("Drive supports PoweRec"); + if(plxtPwrRecEnabled) + { + DicConsole.Write(", has it enabled"); - plxtSense = dev.PlextorGetSecuRec(out plxtBuf, out senseBuf, dev.Timeout, out duration); - if(!plxtSense) DicConsole.WriteLine("Drive supports Plextor SecuRec"); + if(plxtPwrRecSpeed > 0) + DicConsole.WriteLine(" and recommends {0} Kb/sec.", plxtPwrRecSpeed); + else DicConsole.WriteLine("."); - plxtSense = dev.PlextorGetSpeedRead(out plxtBuf, out senseBuf, dev.Timeout, out duration); - if(!plxtSense) - { - DicConsole.Write("Drive supports Plextor SpeedRead"); - if((plxtBuf[2] & 0x01) == 0x01) DicConsole.WriteLine("and has it enabled"); - else DicConsole.WriteLine(); - } + ushort plxtPwrRecSelected, plxtPwrRecMax, plxtPwrRecLast; + plxtSense = dev.PlextorGetSpeeds(out senseBuf, out plxtPwrRecSelected, + out plxtPwrRecMax, out plxtPwrRecLast, dev.Timeout, + out duration); - plxtSense = dev.PlextorGetHiding(out plxtBuf, out senseBuf, dev.Timeout, out duration); - if(!plxtSense) - { - DicConsole.WriteLine("Drive supports hiding CD-Rs and forcing single session"); + if(!plxtSense) + { + if(plxtPwrRecSelected > 0) + DicConsole + .WriteLine("Selected PoweRec speed for currently inserted media is {0} Kb/sec ({1}x)", + plxtPwrRecSelected, plxtPwrRecSelected / 177); + if(plxtPwrRecMax > 0) + DicConsole + .WriteLine("Maximum PoweRec speed for currently inserted media is {0} Kb/sec ({1}x)", + plxtPwrRecMax, plxtPwrRecMax / 177); + if(plxtPwrRecLast > 0) + DicConsole.WriteLine("Last used PoweRec was {0} Kb/sec ({1}x)", + plxtPwrRecLast, plxtPwrRecLast / 177); + } + } + else DicConsole.WriteLine("PoweRec is disabled"); + } - if((plxtBuf[2] & 0x02) == 0x02) DicConsole.WriteLine("Drive currently hides CD-Rs"); - if((plxtBuf[2] & 0x01) == 0x01) - DicConsole.WriteLine("Drive currently forces single session"); - } + // TODO: Check it with a drive + plxtSense = dev.PlextorGetSilentMode(out plxtBuf, out senseBuf, dev.Timeout, out duration); + if(!plxtSense) + { + DicConsole.WriteLine("Drive supports Plextor SilentMode"); + if(plxtBuf[0] == 1) + { + DicConsole.WriteLine("Plextor SilentMode is enabled:"); + if(plxtBuf[1] == 2) DicConsole.WriteLine("\tAccess time is slow"); + else DicConsole.WriteLine("\tAccess time is fast"); - plxtSense = dev.PlextorGetVariRec(out plxtBuf, out senseBuf, false, dev.Timeout, - out duration); - if(!plxtSense) DicConsole.WriteLine("Drive supports Plextor VariRec"); + if(plxtBuf[2] > 0) + DicConsole.WriteLine("\tCD read speed limited to {0}x", plxtBuf[2]); + if(plxtBuf[3] > 0 && plxtDvd) + DicConsole.WriteLine("\tDVD read speed limited to {0}x", plxtBuf[3]); + if(plxtBuf[4] > 0) + DicConsole.WriteLine("\tCD write speed limited to {0}x", plxtBuf[4]); + if(plxtBuf[6] > 0) + DicConsole.WriteLine("\tTray eject speed limited to {0}", -(plxtBuf[6] + 48)); + if(plxtBuf[7] > 0) + DicConsole.WriteLine("\tTray eject speed limited to {0}", plxtBuf[7] - 47); + } + } - if(plxtDvd) - { - plxtSense = dev.PlextorGetVariRec(out plxtBuf, out senseBuf, true, dev.Timeout, + plxtSense = dev.PlextorGetGigaRec(out plxtBuf, out senseBuf, dev.Timeout, out duration); + if(!plxtSense) DicConsole.WriteLine("Drive supports Plextor GigaRec"); + + plxtSense = dev.PlextorGetSecuRec(out plxtBuf, out senseBuf, dev.Timeout, out duration); + if(!plxtSense) DicConsole.WriteLine("Drive supports Plextor SecuRec"); + + plxtSense = dev.PlextorGetSpeedRead(out plxtBuf, out senseBuf, dev.Timeout, out duration); + if(!plxtSense) + { + DicConsole.Write("Drive supports Plextor SpeedRead"); + if((plxtBuf[2] & 0x01) == 0x01) DicConsole.WriteLine("and has it enabled"); + else DicConsole.WriteLine(); + } + + plxtSense = dev.PlextorGetHiding(out plxtBuf, out senseBuf, dev.Timeout, out duration); + if(!plxtSense) + { + DicConsole.WriteLine("Drive supports hiding CD-Rs and forcing single session"); + + if((plxtBuf[2] & 0x02) == 0x02) DicConsole.WriteLine("Drive currently hides CD-Rs"); + if((plxtBuf[2] & 0x01) == 0x01) + DicConsole.WriteLine("Drive currently forces single session"); + } + + plxtSense = dev.PlextorGetVariRec(out plxtBuf, out senseBuf, false, dev.Timeout, out duration); - if(!plxtSense) DicConsole.WriteLine("Drive supports Plextor VariRec for DVDs"); + if(!plxtSense) DicConsole.WriteLine("Drive supports Plextor VariRec"); - plxtSense = dev.PlextorGetBitsetting(out plxtBuf, out senseBuf, false, dev.Timeout, - out duration); - if(!plxtSense) DicConsole.WriteLine("Drive supports bitsetting DVD+R book type"); - plxtSense = dev.PlextorGetBitsetting(out plxtBuf, out senseBuf, true, dev.Timeout, - out duration); - if(!plxtSense) DicConsole.WriteLine("Drive supports bitsetting DVD+R DL book type"); - plxtSense = dev.PlextorGetTestWriteDvdPlus(out plxtBuf, out senseBuf, dev.Timeout, - out duration); - if(!plxtSense) DicConsole.WriteLine("Drive supports test writing DVD+"); + if(plxtDvd) + { + plxtSense = dev.PlextorGetVariRec(out plxtBuf, out senseBuf, true, dev.Timeout, + out duration); + if(!plxtSense) DicConsole.WriteLine("Drive supports Plextor VariRec for DVDs"); + + plxtSense = dev.PlextorGetBitsetting(out plxtBuf, out senseBuf, false, dev.Timeout, + out duration); + if(!plxtSense) DicConsole.WriteLine("Drive supports bitsetting DVD+R book type"); + plxtSense = dev.PlextorGetBitsetting(out plxtBuf, out senseBuf, true, dev.Timeout, + out duration); + if(!plxtSense) DicConsole.WriteLine("Drive supports bitsetting DVD+R DL book type"); + plxtSense = dev.PlextorGetTestWriteDvdPlus(out plxtBuf, out senseBuf, dev.Timeout, + out duration); + if(!plxtSense) DicConsole.WriteLine("Drive supports test writing DVD+"); + } } - } - #endregion Plextor + #endregion Plextor - if(inq.Value.KreonPresent) - { - KreonFeatures krFeatures; - if(!dev.KreonGetFeatureList(out senseBuf, out krFeatures, dev.Timeout, out duration)) + if(inq.Value.KreonPresent) { - DicConsole.WriteLine("Drive has kreon firmware:"); - if(krFeatures.HasFlag(KreonFeatures.ChallengeResponse)) - DicConsole.WriteLine("\tCan do challenge/response with Xbox discs"); - if(krFeatures.HasFlag(KreonFeatures.DecryptSs)) - DicConsole.WriteLine("\tCan read and descrypt SS from Xbox discs"); - if(krFeatures.HasFlag(KreonFeatures.XtremeUnlock)) - DicConsole.WriteLine("\tCan set xtreme unlock state with Xbox discs"); - if(krFeatures.HasFlag(KreonFeatures.WxripperUnlock)) - DicConsole.WriteLine("\tCan set wxripper unlock state with Xbox discs"); - if(krFeatures.HasFlag(KreonFeatures.ChallengeResponse360)) - DicConsole.WriteLine("\tCan do challenge/response with Xbox 360 discs"); - if(krFeatures.HasFlag(KreonFeatures.DecryptSs360)) - DicConsole.WriteLine("\tCan read and descrypt SS from Xbox 360 discs"); - if(krFeatures.HasFlag(KreonFeatures.XtremeUnlock360)) - DicConsole.WriteLine("\tCan set xtreme unlock state with Xbox 360 discs"); - if(krFeatures.HasFlag(KreonFeatures.WxripperUnlock360)) - DicConsole.WriteLine("\tCan set wxripper unlock state with Xbox 360 discs"); - if(krFeatures.HasFlag(KreonFeatures.Lock)) - DicConsole.WriteLine("\tCan set locked state"); - if(krFeatures.HasFlag(KreonFeatures.ErrorSkipping)) - DicConsole.WriteLine("\tCan skip read errors"); + KreonFeatures krFeatures; + if(!dev.KreonGetFeatureList(out senseBuf, out krFeatures, dev.Timeout, out duration)) + { + DicConsole.WriteLine("Drive has kreon firmware:"); + if(krFeatures.HasFlag(KreonFeatures.ChallengeResponse)) + DicConsole.WriteLine("\tCan do challenge/response with Xbox discs"); + if(krFeatures.HasFlag(KreonFeatures.DecryptSs)) + DicConsole.WriteLine("\tCan read and descrypt SS from Xbox discs"); + if(krFeatures.HasFlag(KreonFeatures.XtremeUnlock)) + DicConsole.WriteLine("\tCan set xtreme unlock state with Xbox discs"); + if(krFeatures.HasFlag(KreonFeatures.WxripperUnlock)) + DicConsole.WriteLine("\tCan set wxripper unlock state with Xbox discs"); + if(krFeatures.HasFlag(KreonFeatures.ChallengeResponse360)) + DicConsole.WriteLine("\tCan do challenge/response with Xbox 360 discs"); + if(krFeatures.HasFlag(KreonFeatures.DecryptSs360)) + DicConsole.WriteLine("\tCan read and descrypt SS from Xbox 360 discs"); + if(krFeatures.HasFlag(KreonFeatures.XtremeUnlock360)) + DicConsole.WriteLine("\tCan set xtreme unlock state with Xbox 360 discs"); + if(krFeatures.HasFlag(KreonFeatures.WxripperUnlock360)) + DicConsole.WriteLine("\tCan set wxripper unlock state with Xbox 360 discs"); + if(krFeatures.HasFlag(KreonFeatures.Lock)) + DicConsole.WriteLine("\tCan set locked state"); + if(krFeatures.HasFlag(KreonFeatures.ErrorSkipping)) + DicConsole.WriteLine("\tCan skip read errors"); + } } - } - } + break; + case Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess: + byte[] seqBuf; - if(devType == Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess) - { - byte[] seqBuf; - - sense = dev.ReadBlockLimits(out seqBuf, out senseBuf, dev.Timeout, out duration); - if(sense) - DicConsole.ErrorWriteLine("READ BLOCK LIMITS:\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - DataFile.WriteTo("Device-Info command", options.OutputPrefix, "_ssc_readblocklimits.bin", - "SSC READ BLOCK LIMITS", seqBuf); - DicConsole.WriteLine("Block limits for device:"); - DicConsole.WriteLine(Decoders.SCSI.SSC.BlockLimits.Prettify(seqBuf)); - } - - sense = dev.ReportDensitySupport(out seqBuf, out senseBuf, dev.Timeout, out duration); - if(sense) - DicConsole.ErrorWriteLine("REPORT DENSITY SUPPORT:\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - "_ssc_reportdensitysupport.bin", "SSC REPORT DENSITY SUPPORT", seqBuf); - Decoders.SCSI.SSC.DensitySupport.DensitySupportHeader? dens = - Decoders.SCSI.SSC.DensitySupport.DecodeDensity(seqBuf); - if(dens.HasValue) + sense = dev.ReadBlockLimits(out seqBuf, out senseBuf, dev.Timeout, out duration); + if(sense) + DicConsole.ErrorWriteLine("READ BLOCK LIMITS:\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else { - DicConsole.WriteLine("Densities supported by device:"); - DicConsole.WriteLine(Decoders.SCSI.SSC.DensitySupport.PrettifyDensity(dens)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, "_ssc_readblocklimits.bin", + "SSC READ BLOCK LIMITS", seqBuf); + DicConsole.WriteLine("Block limits for device:"); + DicConsole.WriteLine(Decoders.SCSI.SSC.BlockLimits.Prettify(seqBuf)); } - } - sense = dev.ReportDensitySupport(out seqBuf, out senseBuf, true, false, dev.Timeout, - out duration); - if(sense) - DicConsole.ErrorWriteLine("REPORT DENSITY SUPPORT (MEDIUM):\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - "_ssc_reportdensitysupport_medium.bin", - "SSC REPORT DENSITY SUPPORT (MEDIUM)", seqBuf); - Decoders.SCSI.SSC.DensitySupport.MediaTypeSupportHeader? meds = - Decoders.SCSI.SSC.DensitySupport.DecodeMediumType(seqBuf); - if(meds.HasValue) + sense = dev.ReportDensitySupport(out seqBuf, out senseBuf, dev.Timeout, out duration); + if(sense) + DicConsole.ErrorWriteLine("REPORT DENSITY SUPPORT:\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else { - DicConsole.WriteLine("Medium types supported by device:"); - DicConsole.WriteLine(Decoders.SCSI.SSC.DensitySupport.PrettifyMediumType(meds)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + "_ssc_reportdensitysupport.bin", "SSC REPORT DENSITY SUPPORT", seqBuf); + Decoders.SCSI.SSC.DensitySupport.DensitySupportHeader? dens = + Decoders.SCSI.SSC.DensitySupport.DecodeDensity(seqBuf); + if(dens.HasValue) + { + DicConsole.WriteLine("Densities supported by device:"); + DicConsole.WriteLine(Decoders.SCSI.SSC.DensitySupport.PrettifyDensity(dens)); + } } - DicConsole.WriteLine(Decoders.SCSI.SSC.DensitySupport.PrettifyMediumType(seqBuf)); - } + + sense = dev.ReportDensitySupport(out seqBuf, out senseBuf, true, false, dev.Timeout, + out duration); + if(sense) + DicConsole.ErrorWriteLine("REPORT DENSITY SUPPORT (MEDIUM):\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + { + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + "_ssc_reportdensitysupport_medium.bin", + "SSC REPORT DENSITY SUPPORT (MEDIUM)", seqBuf); + Decoders.SCSI.SSC.DensitySupport.MediaTypeSupportHeader? meds = + Decoders.SCSI.SSC.DensitySupport.DecodeMediumType(seqBuf); + if(meds.HasValue) + { + DicConsole.WriteLine("Medium types supported by device:"); + DicConsole.WriteLine(Decoders.SCSI.SSC.DensitySupport.PrettifyMediumType(meds)); + } + DicConsole.WriteLine(Decoders.SCSI.SSC.DensitySupport.PrettifyMediumType(seqBuf)); + } + break; } break; diff --git a/DiscImageChef/Commands/MediaInfo.cs b/DiscImageChef/Commands/MediaInfo.cs index ea001c7ad..ba43317a4 100644 --- a/DiscImageChef/Commands/MediaInfo.cs +++ b/DiscImageChef/Commands/MediaInfo.cs @@ -220,101 +220,99 @@ namespace DiscImageChef.Commands containsFloppyPage |= modePage.Page == 0x05; } - if(dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.DirectAccess || - dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice || - dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.OCRWDevice || - dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.OpticalDevice || - dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.SimplifiedDevice || - dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.WriteOnceDevice) - { - sense = dev.ReadCapacity(out cmdBuf, out senseBuf, dev.Timeout, out duration); - if(!sense) - { - DataFile.WriteTo("Media-Info command", outputPrefix, "_readcapacity.bin", "SCSI READ CAPACITY", - cmdBuf); - blocks = (ulong)((cmdBuf[0] << 24) + (cmdBuf[1] << 16) + (cmdBuf[2] << 8) + cmdBuf[3]); - blockSize = (uint)((cmdBuf[5] << 24) + (cmdBuf[5] << 16) + (cmdBuf[6] << 8) + cmdBuf[7]); - } - - if(sense || blocks == 0xFFFFFFFF) - { - sense = dev.ReadCapacity16(out cmdBuf, out senseBuf, dev.Timeout, out duration); - - if(sense && blocks == 0) - if(dev.ScsiType != Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice) - { - DicConsole.ErrorWriteLine("Unable to get media capacity"); - DicConsole.ErrorWriteLine("{0}", Decoders.SCSI.Sense.PrettifySense(senseBuf)); - } - + switch(dev.ScsiType) { + case Decoders.SCSI.PeripheralDeviceTypes.DirectAccess: + case Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice: + case Decoders.SCSI.PeripheralDeviceTypes.OCRWDevice: + case Decoders.SCSI.PeripheralDeviceTypes.OpticalDevice: + case Decoders.SCSI.PeripheralDeviceTypes.SimplifiedDevice: + case Decoders.SCSI.PeripheralDeviceTypes.WriteOnceDevice: + sense = dev.ReadCapacity(out cmdBuf, out senseBuf, dev.Timeout, out duration); if(!sense) { - DataFile.WriteTo("Media-Info command", outputPrefix, "_readcapacity16.bin", - "SCSI READ CAPACITY(16)", cmdBuf); - byte[] temp = new byte[8]; - - Array.Copy(cmdBuf, 0, temp, 0, 8); - Array.Reverse(temp); - blocks = BitConverter.ToUInt64(temp, 0); + DataFile.WriteTo("Media-Info command", outputPrefix, "_readcapacity.bin", "SCSI READ CAPACITY", + cmdBuf); + blocks = (ulong)((cmdBuf[0] << 24) + (cmdBuf[1] << 16) + (cmdBuf[2] << 8) + cmdBuf[3]); blockSize = (uint)((cmdBuf[5] << 24) + (cmdBuf[5] << 16) + (cmdBuf[6] << 8) + cmdBuf[7]); } - } - if(blocks != 0 && blockSize != 0) - { - blocks++; - DicConsole.WriteLine("Media has {0} blocks of {1} bytes/each. (for a total of {2} bytes)", blocks, - blockSize, blocks * blockSize); - } - } - - if(dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess) - { - byte[] seqBuf; - byte[] medBuf; - - sense = dev.ReportDensitySupport(out seqBuf, out senseBuf, false, dev.Timeout, out duration); - if(!sense) - { - sense = dev.ReportDensitySupport(out medBuf, out senseBuf, true, dev.Timeout, out duration); - - if(!sense && !seqBuf.SequenceEqual(medBuf)) + if(sense || blocks == 0xFFFFFFFF) { - DataFile.WriteTo("Media-Info command", outputPrefix, "_ssc_reportdensitysupport_media.bin", - "SSC REPORT DENSITY SUPPORT (MEDIA)", seqBuf); - Decoders.SCSI.SSC.DensitySupport.DensitySupportHeader? dens = - Decoders.SCSI.SSC.DensitySupport.DecodeDensity(seqBuf); - if(dens.HasValue) + sense = dev.ReadCapacity16(out cmdBuf, out senseBuf, dev.Timeout, out duration); + + if(sense && blocks == 0) + if(dev.ScsiType != Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice) + { + DicConsole.ErrorWriteLine("Unable to get media capacity"); + DicConsole.ErrorWriteLine("{0}", Decoders.SCSI.Sense.PrettifySense(senseBuf)); + } + + if(!sense) { - DicConsole.WriteLine("Densities supported by currently inserted media:"); - DicConsole.WriteLine(Decoders.SCSI.SSC.DensitySupport.PrettifyDensity(dens)); + DataFile.WriteTo("Media-Info command", outputPrefix, "_readcapacity16.bin", + "SCSI READ CAPACITY(16)", cmdBuf); + byte[] temp = new byte[8]; + + Array.Copy(cmdBuf, 0, temp, 0, 8); + Array.Reverse(temp); + blocks = BitConverter.ToUInt64(temp, 0); + blockSize = (uint)((cmdBuf[5] << 24) + (cmdBuf[5] << 16) + (cmdBuf[6] << 8) + cmdBuf[7]); } } - } - sense = dev.ReportDensitySupport(out seqBuf, out senseBuf, true, false, dev.Timeout, out duration); - if(!sense) - { - sense = dev.ReportDensitySupport(out medBuf, out senseBuf, true, true, dev.Timeout, out duration); - - if(!sense && !seqBuf.SequenceEqual(medBuf)) + if(blocks != 0 && blockSize != 0) { - DataFile.WriteTo("Media-Info command", outputPrefix, - "_ssc_reportdensitysupport_medium_media.bin", - "SSC REPORT DENSITY SUPPORT (MEDIUM & MEDIA)", seqBuf); - Decoders.SCSI.SSC.DensitySupport.MediaTypeSupportHeader? meds = - Decoders.SCSI.SSC.DensitySupport.DecodeMediumType(seqBuf); - if(meds.HasValue) - { - DicConsole.WriteLine("Medium types currently inserted in device:"); - DicConsole.WriteLine(Decoders.SCSI.SSC.DensitySupport.PrettifyMediumType(meds)); - } - DicConsole.WriteLine(Decoders.SCSI.SSC.DensitySupport.PrettifyMediumType(seqBuf)); + blocks++; + DicConsole.WriteLine("Media has {0} blocks of {1} bytes/each. (for a total of {2} bytes)", blocks, + blockSize, blocks * blockSize); } - } + break; + case Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess: + byte[] seqBuf; + byte[] medBuf; - // TODO: Get a machine where 16-byte CDBs don't get DID_ABORT - /* + sense = dev.ReportDensitySupport(out seqBuf, out senseBuf, false, dev.Timeout, out duration); + if(!sense) + { + sense = dev.ReportDensitySupport(out medBuf, out senseBuf, true, dev.Timeout, out duration); + + if(!sense && !seqBuf.SequenceEqual(medBuf)) + { + DataFile.WriteTo("Media-Info command", outputPrefix, "_ssc_reportdensitysupport_media.bin", + "SSC REPORT DENSITY SUPPORT (MEDIA)", seqBuf); + Decoders.SCSI.SSC.DensitySupport.DensitySupportHeader? dens = + Decoders.SCSI.SSC.DensitySupport.DecodeDensity(seqBuf); + if(dens.HasValue) + { + DicConsole.WriteLine("Densities supported by currently inserted media:"); + DicConsole.WriteLine(Decoders.SCSI.SSC.DensitySupport.PrettifyDensity(dens)); + } + } + } + + sense = dev.ReportDensitySupport(out seqBuf, out senseBuf, true, false, dev.Timeout, out duration); + if(!sense) + { + sense = dev.ReportDensitySupport(out medBuf, out senseBuf, true, true, dev.Timeout, out duration); + + if(!sense && !seqBuf.SequenceEqual(medBuf)) + { + DataFile.WriteTo("Media-Info command", outputPrefix, + "_ssc_reportdensitysupport_medium_media.bin", + "SSC REPORT DENSITY SUPPORT (MEDIUM & MEDIA)", seqBuf); + Decoders.SCSI.SSC.DensitySupport.MediaTypeSupportHeader? meds = + Decoders.SCSI.SSC.DensitySupport.DecodeMediumType(seqBuf); + if(meds.HasValue) + { + DicConsole.WriteLine("Medium types currently inserted in device:"); + DicConsole.WriteLine(Decoders.SCSI.SSC.DensitySupport.PrettifyMediumType(meds)); + } + DicConsole.WriteLine(Decoders.SCSI.SSC.DensitySupport.PrettifyMediumType(seqBuf)); + } + } + + // TODO: Get a machine where 16-byte CDBs don't get DID_ABORT + /* sense = dev.ReadAttribute(out seqBuf, out senseBuf, ScsiAttributeAction.List, 0, dev.Timeout, out duration); if (sense) DicConsole.ErrorWriteLine("SCSI READ ATTRIBUTE:\n{0}", Decoders.SCSI.Sense.PrettifySense(senseBuf)); @@ -323,6 +321,7 @@ namespace DiscImageChef.Commands DataFile.WriteTo("Media-Info command", outputPrefix, "_scsi_readattribute.bin", "SCSI READ ATTRIBUTE", seqBuf); } */ + break; } if(dev.ScsiType == Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice) @@ -590,25 +589,78 @@ namespace DiscImageChef.Commands #endregion DVD-ROM #region DVD-ROM and HD DVD-ROM - if(dskType == MediaType.DVDDownload || dskType == MediaType.DVDROM || dskType == MediaType.HDDVDROM) - { - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.BurstCuttingArea, 0, dev.Timeout, - out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: BCA\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_bca.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.DvdAacs, 0, dev.Timeout, out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: DVD AACS\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_aacs.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); + switch(dskType) { + case MediaType.DVDDownload: + case MediaType.DVDROM: + case MediaType.HDDVDROM: + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.BurstCuttingArea, 0, dev.Timeout, + out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: BCA\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_bca.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.DvdAacs, 0, dev.Timeout, out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: DVD AACS\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_aacs.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + break; + case MediaType.DVDRAM: + case MediaType.HDDVDRAM: + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.DvdramDds, 0, dev.Timeout, out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: DDS\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + { + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdram_dds.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + DicConsole.WriteLine("Disc Definition Structure:\n{0}", Decoders.DVD.DDS.Prettify(cmdBuf)); + } + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.DvdramMediumStatus, 0, dev.Timeout, + out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: Medium Status\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + { + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdram_status.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + DicConsole.WriteLine("Medium Status:\n{0}", Decoders.DVD.Cartridge.Prettify(cmdBuf)); + } + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.DvdramSpareAreaInformation, 0, dev.Timeout, + out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: SAI\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + { + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdram_spare.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + DicConsole.WriteLine("Spare Area Information:\n{0}", Decoders.DVD.Spare.Prettify(cmdBuf)); + } + break; + case MediaType.DVDR: + case MediaType.HDDVDR: + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.LastBorderOutRmd, 0, dev.Timeout, + out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: Last-Out Border RMD\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_lastrmd.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + break; } #endregion DVD-ROM and HD DVD-ROM @@ -673,59 +725,9 @@ namespace DiscImageChef.Commands #endregion Require drive authentication, won't work #region DVD-RAM and HD DVD-RAM - if(dskType == MediaType.DVDRAM || dskType == MediaType.HDDVDRAM) - { - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.DvdramDds, 0, dev.Timeout, out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: DDS\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdram_dds.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - DicConsole.WriteLine("Disc Definition Structure:\n{0}", Decoders.DVD.DDS.Prettify(cmdBuf)); - } - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.DvdramMediumStatus, 0, dev.Timeout, - out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: Medium Status\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdram_status.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - DicConsole.WriteLine("Medium Status:\n{0}", Decoders.DVD.Cartridge.Prettify(cmdBuf)); - } - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.DvdramSpareAreaInformation, 0, dev.Timeout, - out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: SAI\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdram_spare.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - DicConsole.WriteLine("Spare Area Information:\n{0}", Decoders.DVD.Spare.Prettify(cmdBuf)); - } - } #endregion DVD-RAM and HD DVD-RAM #region DVD-R and HD DVD-R - if(dskType == MediaType.DVDR || dskType == MediaType.HDDVDR) - { - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.LastBorderOutRmd, 0, dev.Timeout, - out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: Last-Out Border RMD\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_lastrmd.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - } #endregion DVD-R and HD DVD-R #region DVD-R and DVD-RW @@ -742,68 +744,69 @@ namespace DiscImageChef.Commands } #endregion DVD-R and DVD-RW - #region DVD-R, DVD-RW and HD DVD-R - if(dskType == MediaType.DVDR || dskType == MediaType.DVDRW || dskType == MediaType.HDDVDR) - { - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.DvdrMediaIdentifier, 0, dev.Timeout, - out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: DVD-R Media ID\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdr_mediaid.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.DvdrPhysicalInformation, 0, dev.Timeout, - out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: DVD-R PFI\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdr_pfi.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - } - #endregion DVD-R, DVD-RW and HD DVD-R + switch(dskType) { + #region DVD-R, DVD-RW and HD DVD-R + case MediaType.DVDR: + case MediaType.DVDRW: + case MediaType.HDDVDR: + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.DvdrMediaIdentifier, 0, dev.Timeout, + out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: DVD-R Media ID\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdr_mediaid.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.DvdrPhysicalInformation, 0, dev.Timeout, + out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: DVD-R PFI\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvdr_pfi.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + break; + #endregion DVD-R, DVD-RW and HD DVD-R + #region All DVD+ + case MediaType.DVDPR: + case MediaType.DVDPRDL: + case MediaType.DVDPRW: + case MediaType.DVDPRWDL: + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.Adip, 0, dev.Timeout, out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: ADIP\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd+_adip.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); - #region All DVD+ - if(dskType == MediaType.DVDPR || dskType == MediaType.DVDPRDL || dskType == MediaType.DVDPRW || - dskType == MediaType.DVDPRWDL) - { - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.Adip, 0, dev.Timeout, out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: ADIP\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd+_adip.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.Dcb, 0, dev.Timeout, out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: DCB\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd+_dcb.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.Dcb, 0, dev.Timeout, out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: DCB\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd+_dcb.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + break; + #endregion All DVD+ + #region HD DVD-ROM + case MediaType.HDDVDROM: + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.HddvdCopyrightInformation, 0, dev.Timeout, + out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: HDDVD CMI\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_hddvd_cmi.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + break; + #endregion HD DVD-ROM } - #endregion All DVD+ - - #region HD DVD-ROM - if(dskType == MediaType.HDDVDROM) - { - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.HddvdCopyrightInformation, 0, dev.Timeout, - out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: HDDVD CMI\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_hddvd_cmi.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - } - #endregion HD DVD-ROM #region HD DVD-R if(dskType == MediaType.HDDVDR) @@ -845,337 +848,343 @@ namespace DiscImageChef.Commands } #endregion DVD-R DL, DVD-RW DL, DVD+R DL, DVD+RW DL - #region DVD-R DL - if(dskType == MediaType.DVDRDL) - { - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.MiddleZoneStart, 0, dev.Timeout, out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: Middle Zone Start\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_mzs.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.JumpIntervalSize, 0, dev.Timeout, - out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: Jump Interval Size\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_jis.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.ManualLayerJumpStartLba, 0, dev.Timeout, - out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", - "READ DISC STRUCTURE: Manual Layer Jump Start LBA\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_manuallj.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.RemapAnchorPoint, 0, dev.Timeout, - out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: Remap Anchor Point\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_remapanchor.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - } - #endregion DVD-R DL - - #region All Blu-ray - if(dskType == MediaType.BDR || dskType == MediaType.BDRE || dskType == MediaType.BDROM || - dskType == MediaType.BDRXL || dskType == MediaType.BDREXL) - { - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, - MmcDiscStructureFormat.DiscInformation, 0, dev.Timeout, out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: DI\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_di.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - DicConsole.WriteLine("Blu-ray Disc Information:\n{0}", Decoders.Bluray.DI.Prettify(cmdBuf)); - } - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, - MmcDiscStructureFormat.Pac, 0, dev.Timeout, out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: PAC\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_pac.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - } - #endregion All Blu-ray - - #region BD-ROM only - if(dskType == MediaType.BDROM) - { - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, - MmcDiscStructureFormat.BdBurstCuttingArea, 0, dev.Timeout, - out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: BCA\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_bca.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - DicConsole.WriteLine("Blu-ray Burst Cutting Area:\n{0}", Decoders.Bluray.BCA.Prettify(cmdBuf)); - } - } - #endregion BD-ROM only - - #region Writable Blu-ray only - if(dskType == MediaType.BDR || dskType == MediaType.BDRE || dskType == MediaType.BDRXL || - dskType == MediaType.BDREXL) - { - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, - MmcDiscStructureFormat.BdDds, 0, dev.Timeout, out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: DDS\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_dds.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - DicConsole.WriteLine("Blu-ray Disc Definition Structure:\n{0}", - Decoders.Bluray.DDS.Prettify(cmdBuf)); - } - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, - MmcDiscStructureFormat.CartridgeStatus, 0, dev.Timeout, out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: Cartridge Status\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_cartstatus.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - DicConsole.WriteLine("Blu-ray Cartridge Status:\n{0}", Decoders.Bluray.DI.Prettify(cmdBuf)); - } - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, - MmcDiscStructureFormat.BdSpareAreaInformation, 0, dev.Timeout, - out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", - "READ DISC STRUCTURE: Spare Area Information\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_spare.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - DicConsole.WriteLine("Blu-ray Spare Area Information:\n{0}", - Decoders.Bluray.DI.Prettify(cmdBuf)); - } - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, - MmcDiscStructureFormat.RawDfl, 0, dev.Timeout, out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: Raw DFL\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_dfl.bin", - "SCSI READ DISC STRUCTURE", cmdBuf); - sense = dev.ReadDiscInformation(out cmdBuf, out senseBuf, - MmcDiscInformationDataTypes.TrackResources, dev.Timeout, - out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC INFORMATION 001b\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - DicConsole.WriteLine("Track Resources Information:\n{0}", - Decoders.SCSI.MMC.DiscInformation.Prettify(cmdBuf)); - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscinformation_001b.bin", - "SCSI READ DISC INFORMATION", cmdBuf); - } - sense = dev.ReadDiscInformation(out cmdBuf, out senseBuf, MmcDiscInformationDataTypes.PowResources, - dev.Timeout, out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC INFORMATION 010b\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - DicConsole.WriteLine("POW Resources Information:\n{0}", - Decoders.SCSI.MMC.DiscInformation.Prettify(cmdBuf)); - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscinformation_010b.bin", - "SCSI READ DISC INFORMATION", cmdBuf); - } - } - #endregion Writable Blu-ray only - - #region CDs - if(dskType == MediaType.CD || dskType == MediaType.CDR || dskType == MediaType.CDROM || - dskType == MediaType.CDRW || dskType == MediaType.Unknown) - { - Decoders.CD.TOC.CDTOC? toc = null; - - // We discarded all discs that falsify a TOC before requesting a real TOC - // No TOC, no CD (or an empty one) - bool tocSense = - dev.ReadTocPmaAtip(out cmdBuf, out senseBuf, false, 0, 0, dev.Timeout, out duration); - if(tocSense) - DicConsole.DebugWriteLine("Media-Info command", "READ TOC/PMA/ATIP: TOC\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - toc = Decoders.CD.TOC.Decode(cmdBuf); - DicConsole.WriteLine("TOC:\n{0}", Decoders.CD.TOC.Prettify(toc)); - DataFile.WriteTo("Media-Info command", outputPrefix, "_toc.bin", "SCSI READ TOC/PMA/ATIP", - cmdBuf); - - // As we have a TOC we know it is a CD - if(dskType == MediaType.Unknown) dskType = MediaType.CD; - } - - // ATIP exists on blank CDs - sense = dev.ReadAtip(out cmdBuf, out senseBuf, dev.Timeout, out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ TOC/PMA/ATIP: ATIP\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - DataFile.WriteTo("Media-Info command", outputPrefix, "_atip.bin", "SCSI READ TOC/PMA/ATIP", - cmdBuf); - Decoders.CD.ATIP.CDATIP? atip = Decoders.CD.ATIP.Decode(cmdBuf); - if(atip.HasValue) + switch(dskType) { + #region DVD-R DL + case MediaType.DVDRDL: + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.MiddleZoneStart, 0, dev.Timeout, out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: Middle Zone Start\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_mzs.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.JumpIntervalSize, 0, dev.Timeout, + out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: Jump Interval Size\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_jis.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.ManualLayerJumpStartLba, 0, dev.Timeout, + out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", + "READ DISC STRUCTURE: Manual Layer Jump Start LBA\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_manuallj.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.RemapAnchorPoint, 0, dev.Timeout, + out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: Remap Anchor Point\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_dvd_remapanchor.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + break; + #endregion DVD-R DL + #region All Blu-ray + case MediaType.BDR: + case MediaType.BDRE: + case MediaType.BDROM: + case MediaType.BDRXL: + case MediaType.BDREXL: + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, + MmcDiscStructureFormat.DiscInformation, 0, dev.Timeout, out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: DI\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else { - DicConsole.WriteLine("ATIP:\n{0}", Decoders.CD.ATIP.Prettify(atip)); - // Only CD-R and CD-RW have ATIP - dskType = atip.Value.DiscType ? MediaType.CDRW : MediaType.CDR; + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_di.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + DicConsole.WriteLine("Blu-ray Disc Information:\n{0}", Decoders.Bluray.DI.Prettify(cmdBuf)); } - } + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, + MmcDiscStructureFormat.Pac, 0, dev.Timeout, out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: PAC\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_pac.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + break; + #endregion All Blu-ray + } - // We got a TOC, get information about a recorded/mastered CD - if(!tocSense) - { + + switch(dskType) { + #region BD-ROM only + case MediaType.BDROM: + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, + MmcDiscStructureFormat.BdBurstCuttingArea, 0, dev.Timeout, + out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: BCA\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + { + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_bca.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + DicConsole.WriteLine("Blu-ray Burst Cutting Area:\n{0}", Decoders.Bluray.BCA.Prettify(cmdBuf)); + } + break; + #endregion BD-ROM only + #region Writable Blu-ray only + case MediaType.BDR: + case MediaType.BDRE: + case MediaType.BDRXL: + case MediaType.BDREXL: + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, + MmcDiscStructureFormat.BdDds, 0, dev.Timeout, out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: DDS\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + { + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_dds.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + DicConsole.WriteLine("Blu-ray Disc Definition Structure:\n{0}", + Decoders.Bluray.DDS.Prettify(cmdBuf)); + } + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, + MmcDiscStructureFormat.CartridgeStatus, 0, dev.Timeout, out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: Cartridge Status\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + { + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_cartstatus.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + DicConsole.WriteLine("Blu-ray Cartridge Status:\n{0}", Decoders.Bluray.DI.Prettify(cmdBuf)); + } + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, + MmcDiscStructureFormat.BdSpareAreaInformation, 0, dev.Timeout, + out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", + "READ DISC STRUCTURE: Spare Area Information\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + { + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_spare.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); + DicConsole.WriteLine("Blu-ray Spare Area Information:\n{0}", + Decoders.Bluray.DI.Prettify(cmdBuf)); + } + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Bd, 0, 0, + MmcDiscStructureFormat.RawDfl, 0, dev.Timeout, out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC STRUCTURE: Raw DFL\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscstructure_bd_dfl.bin", + "SCSI READ DISC STRUCTURE", cmdBuf); sense = dev.ReadDiscInformation(out cmdBuf, out senseBuf, - MmcDiscInformationDataTypes.DiscInformation, dev.Timeout, + MmcDiscInformationDataTypes.TrackResources, dev.Timeout, out duration); if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ DISC INFORMATION 000b\n{0}", + DicConsole.DebugWriteLine("Media-Info command", "READ DISC INFORMATION 001b\n{0}", Decoders.SCSI.Sense.PrettifySense(senseBuf)); else { - Decoders.SCSI.MMC.DiscInformation.StandardDiscInformation? discInfo = - Decoders.SCSI.MMC.DiscInformation.Decode000b(cmdBuf); - if(discInfo.HasValue) - { - DicConsole.WriteLine("Standard Disc Information:\n{0}", - Decoders.SCSI.MMC.DiscInformation.Prettify000b(discInfo)); - DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscinformation_000b.bin", - "SCSI READ DISC INFORMATION", cmdBuf); - - // If it is a read-only CD, check CD type if available - if(dskType == MediaType.CD) - switch(discInfo.Value.DiscType) - { - case 0x10: - dskType = MediaType.CDI; - break; - case 0x20: - dskType = MediaType.CDROMXA; - break; - } - } + DicConsole.WriteLine("Track Resources Information:\n{0}", + Decoders.SCSI.MMC.DiscInformation.Prettify(cmdBuf)); + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscinformation_001b.bin", + "SCSI READ DISC INFORMATION", cmdBuf); } - - int sessions = 1; - int firstTrackLastSession = 0; - - sense = dev.ReadSessionInfo(out cmdBuf, out senseBuf, dev.Timeout, out duration); + sense = dev.ReadDiscInformation(out cmdBuf, out senseBuf, MmcDiscInformationDataTypes.PowResources, + dev.Timeout, out duration); if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ TOC/PMA/ATIP: Session info\n{0}", + DicConsole.DebugWriteLine("Media-Info command", "READ DISC INFORMATION 010b\n{0}", Decoders.SCSI.Sense.PrettifySense(senseBuf)); else { - DataFile.WriteTo("Media-Info command", outputPrefix, "_session.bin", - "SCSI READ TOC/PMA/ATIP", cmdBuf); - Decoders.CD.Session.CDSessionInfo? session = Decoders.CD.Session.Decode(cmdBuf); - DicConsole.WriteLine("Session information:\n{0}", Decoders.CD.Session.Prettify(session)); - if(session.HasValue) - { - sessions = session.Value.LastCompleteSession; - firstTrackLastSession = session.Value.TrackDescriptors[0].TrackNumber; - } + DicConsole.WriteLine("POW Resources Information:\n{0}", + Decoders.SCSI.MMC.DiscInformation.Prettify(cmdBuf)); + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscinformation_010b.bin", + "SCSI READ DISC INFORMATION", cmdBuf); } + break; + #endregion Writable Blu-ray only + #region CDs + case MediaType.CD: + case MediaType.CDR: + case MediaType.CDROM: + case MediaType.CDRW: + case MediaType.Unknown: + Decoders.CD.TOC.CDTOC? toc = null; - if(dskType == MediaType.CD) - { - bool hasDataTrack = false; - bool hasAudioTrack = false; - bool allFirstSessionTracksAreAudio = true; - bool hasVideoTrack = false; - - if(toc.HasValue) - foreach(Decoders.CD.TOC.CDTOCTrackDataDescriptor track in toc.Value.TrackDescriptors) - { - if(track.TrackNumber == 1 && - ((Decoders.CD.TOC_CONTROL)(track.CONTROL & 0x0D) == - Decoders.CD.TOC_CONTROL.DataTrack || - (Decoders.CD.TOC_CONTROL)(track.CONTROL & 0x0D) == - Decoders.CD.TOC_CONTROL.DataTrackIncremental)) allFirstSessionTracksAreAudio &= firstTrackLastSession != 1; - - if((Decoders.CD.TOC_CONTROL)(track.CONTROL & 0x0D) == - Decoders.CD.TOC_CONTROL.DataTrack || - (Decoders.CD.TOC_CONTROL)(track.CONTROL & 0x0D) == - Decoders.CD.TOC_CONTROL.DataTrackIncremental) - { - hasDataTrack = true; - allFirstSessionTracksAreAudio &= track.TrackNumber >= firstTrackLastSession; - } - else hasAudioTrack = true; - - hasVideoTrack |= track.ADR == 4; - } - - if(hasDataTrack && hasAudioTrack && allFirstSessionTracksAreAudio && sessions == 2) - dskType = MediaType.CDPLUS; - if(!hasDataTrack && hasAudioTrack && sessions == 1) dskType = MediaType.CDDA; - if(hasDataTrack && !hasAudioTrack && sessions == 1) dskType = MediaType.CDROM; - if(hasVideoTrack && !hasDataTrack && sessions == 1) dskType = MediaType.CDV; - } - - sense = dev.ReadRawToc(out cmdBuf, out senseBuf, 1, dev.Timeout, out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ TOC/PMA/ATIP: Raw TOC\n{0}", + // We discarded all discs that falsify a TOC before requesting a real TOC + // No TOC, no CD (or an empty one) + bool tocSense = + dev.ReadTocPmaAtip(out cmdBuf, out senseBuf, false, 0, 0, dev.Timeout, out duration); + if(tocSense) + DicConsole.DebugWriteLine("Media-Info command", "READ TOC/PMA/ATIP: TOC\n{0}", Decoders.SCSI.Sense.PrettifySense(senseBuf)); else { - DataFile.WriteTo("Media-Info command", outputPrefix, "_rawtoc.bin", - "SCSI READ TOC/PMA/ATIP", cmdBuf); - DicConsole.WriteLine("Raw TOC:\n{0}", Decoders.CD.FullTOC.Prettify(cmdBuf)); - } - sense = dev.ReadPma(out cmdBuf, out senseBuf, dev.Timeout, out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ TOC/PMA/ATIP: PMA\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - { - DataFile.WriteTo("Media-Info command", outputPrefix, "_pma.bin", "SCSI READ TOC/PMA/ATIP", + toc = Decoders.CD.TOC.Decode(cmdBuf); + DicConsole.WriteLine("TOC:\n{0}", Decoders.CD.TOC.Prettify(toc)); + DataFile.WriteTo("Media-Info command", outputPrefix, "_toc.bin", "SCSI READ TOC/PMA/ATIP", cmdBuf); - DicConsole.WriteLine("PMA:\n{0}", Decoders.CD.PMA.Prettify(cmdBuf)); + + // As we have a TOC we know it is a CD + if(dskType == MediaType.Unknown) dskType = MediaType.CD; } - sense = dev.ReadCdText(out cmdBuf, out senseBuf, dev.Timeout, out duration); + // ATIP exists on blank CDs + sense = dev.ReadAtip(out cmdBuf, out senseBuf, dev.Timeout, out duration); if(sense) - DicConsole.DebugWriteLine("Media-Info command", "READ TOC/PMA/ATIP: CD-TEXT\n{0}", + DicConsole.DebugWriteLine("Media-Info command", "READ TOC/PMA/ATIP: ATIP\n{0}", Decoders.SCSI.Sense.PrettifySense(senseBuf)); else { - DataFile.WriteTo("Media-Info command", outputPrefix, "_cdtext.bin", - "SCSI READ TOC/PMA/ATIP", cmdBuf); - if(Decoders.CD.CDTextOnLeadIn.Decode(cmdBuf).HasValue) - DicConsole.WriteLine("CD-TEXT on Lead-In:\n{0}", - Decoders.CD.CDTextOnLeadIn.Prettify(cmdBuf)); + DataFile.WriteTo("Media-Info command", outputPrefix, "_atip.bin", "SCSI READ TOC/PMA/ATIP", + cmdBuf); + Decoders.CD.ATIP.CDATIP? atip = Decoders.CD.ATIP.Decode(cmdBuf); + if(atip.HasValue) + { + DicConsole.WriteLine("ATIP:\n{0}", Decoders.CD.ATIP.Prettify(atip)); + // Only CD-R and CD-RW have ATIP + dskType = atip.Value.DiscType ? MediaType.CDRW : MediaType.CDR; + } } - } + + // We got a TOC, get information about a recorded/mastered CD + if(!tocSense) + { + sense = dev.ReadDiscInformation(out cmdBuf, out senseBuf, + MmcDiscInformationDataTypes.DiscInformation, dev.Timeout, + out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ DISC INFORMATION 000b\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + { + Decoders.SCSI.MMC.DiscInformation.StandardDiscInformation? discInfo = + Decoders.SCSI.MMC.DiscInformation.Decode000b(cmdBuf); + if(discInfo.HasValue) + { + DicConsole.WriteLine("Standard Disc Information:\n{0}", + Decoders.SCSI.MMC.DiscInformation.Prettify000b(discInfo)); + DataFile.WriteTo("Media-Info command", outputPrefix, "_readdiscinformation_000b.bin", + "SCSI READ DISC INFORMATION", cmdBuf); + + // If it is a read-only CD, check CD type if available + if(dskType == MediaType.CD) + switch(discInfo.Value.DiscType) + { + case 0x10: + dskType = MediaType.CDI; + break; + case 0x20: + dskType = MediaType.CDROMXA; + break; + } + } + } + + int sessions = 1; + int firstTrackLastSession = 0; + + sense = dev.ReadSessionInfo(out cmdBuf, out senseBuf, dev.Timeout, out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ TOC/PMA/ATIP: Session info\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + { + DataFile.WriteTo("Media-Info command", outputPrefix, "_session.bin", + "SCSI READ TOC/PMA/ATIP", cmdBuf); + Decoders.CD.Session.CDSessionInfo? session = Decoders.CD.Session.Decode(cmdBuf); + DicConsole.WriteLine("Session information:\n{0}", Decoders.CD.Session.Prettify(session)); + if(session.HasValue) + { + sessions = session.Value.LastCompleteSession; + firstTrackLastSession = session.Value.TrackDescriptors[0].TrackNumber; + } + } + + if(dskType == MediaType.CD) + { + bool hasDataTrack = false; + bool hasAudioTrack = false; + bool allFirstSessionTracksAreAudio = true; + bool hasVideoTrack = false; + + if(toc.HasValue) + foreach(Decoders.CD.TOC.CDTOCTrackDataDescriptor track in toc.Value.TrackDescriptors) + { + if(track.TrackNumber == 1 && + ((Decoders.CD.TOC_CONTROL)(track.CONTROL & 0x0D) == + Decoders.CD.TOC_CONTROL.DataTrack || + (Decoders.CD.TOC_CONTROL)(track.CONTROL & 0x0D) == + Decoders.CD.TOC_CONTROL.DataTrackIncremental)) allFirstSessionTracksAreAudio &= firstTrackLastSession != 1; + + if((Decoders.CD.TOC_CONTROL)(track.CONTROL & 0x0D) == + Decoders.CD.TOC_CONTROL.DataTrack || + (Decoders.CD.TOC_CONTROL)(track.CONTROL & 0x0D) == + Decoders.CD.TOC_CONTROL.DataTrackIncremental) + { + hasDataTrack = true; + allFirstSessionTracksAreAudio &= track.TrackNumber >= firstTrackLastSession; + } + else hasAudioTrack = true; + + hasVideoTrack |= track.ADR == 4; + } + + if(hasDataTrack && hasAudioTrack && allFirstSessionTracksAreAudio && sessions == 2) + dskType = MediaType.CDPLUS; + if(!hasDataTrack && hasAudioTrack && sessions == 1) dskType = MediaType.CDDA; + if(hasDataTrack && !hasAudioTrack && sessions == 1) dskType = MediaType.CDROM; + if(hasVideoTrack && !hasDataTrack && sessions == 1) dskType = MediaType.CDV; + } + + sense = dev.ReadRawToc(out cmdBuf, out senseBuf, 1, dev.Timeout, out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ TOC/PMA/ATIP: Raw TOC\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + { + DataFile.WriteTo("Media-Info command", outputPrefix, "_rawtoc.bin", + "SCSI READ TOC/PMA/ATIP", cmdBuf); + DicConsole.WriteLine("Raw TOC:\n{0}", Decoders.CD.FullTOC.Prettify(cmdBuf)); + } + sense = dev.ReadPma(out cmdBuf, out senseBuf, dev.Timeout, out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ TOC/PMA/ATIP: PMA\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + { + DataFile.WriteTo("Media-Info command", outputPrefix, "_pma.bin", "SCSI READ TOC/PMA/ATIP", + cmdBuf); + DicConsole.WriteLine("PMA:\n{0}", Decoders.CD.PMA.Prettify(cmdBuf)); + } + + sense = dev.ReadCdText(out cmdBuf, out senseBuf, dev.Timeout, out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "READ TOC/PMA/ATIP: CD-TEXT\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + { + DataFile.WriteTo("Media-Info command", outputPrefix, "_cdtext.bin", + "SCSI READ TOC/PMA/ATIP", cmdBuf); + if(Decoders.CD.CDTextOnLeadIn.Decode(cmdBuf).HasValue) + DicConsole.WriteLine("CD-TEXT on Lead-In:\n{0}", + Decoders.CD.CDTextOnLeadIn.Prettify(cmdBuf)); + } + } + + break; + #endregion CDs } - #endregion CDs #region Nintendo if(dskType == MediaType.Unknown && blocks > 0) @@ -1196,9 +1205,12 @@ namespace DiscImageChef.Commands DicConsole.WriteLine("PFI:\n{0}", Decoders.DVD.PFI.Prettify(cmdBuf)); if(nintendoPfi.Value.DiskCategory == Decoders.DVD.DiskCategory.Nintendo && nintendoPfi.Value.PartVersion == 15) - if(nintendoPfi.Value.DiscSize == Decoders.DVD.DVDSize.Eighty) dskType = MediaType.GOD; - else if(nintendoPfi.Value.DiscSize == Decoders.DVD.DVDSize.OneTwenty) - dskType = MediaType.WOD; + switch(nintendoPfi.Value.DiscSize) { + case Decoders.DVD.DVDSize.Eighty: dskType = MediaType.GOD; + break; + case Decoders.DVD.DVDSize.OneTwenty: dskType = MediaType.WOD; + break; + } } } sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, @@ -1215,131 +1227,135 @@ namespace DiscImageChef.Commands } #region Xbox - if(dskType == MediaType.XGD || dskType == MediaType.XGD2 || dskType == MediaType.XGD3) - { - // We need to get INQUIRY to know if it is a Kreon drive - byte[] inqBuffer; - Decoders.SCSI.Inquiry.SCSIInquiry? inq; + switch(dskType) { + case MediaType.XGD: + case MediaType.XGD2: + case MediaType.XGD3: + // We need to get INQUIRY to know if it is a Kreon drive + byte[] inqBuffer; + Decoders.SCSI.Inquiry.SCSIInquiry? inq; - sense = dev.ScsiInquiry(out inqBuffer, out senseBuf); - if(!sense) - { - inq = Decoders.SCSI.Inquiry.Decode(inqBuffer); - if(inq.HasValue && inq.Value.KreonPresent) + sense = dev.ScsiInquiry(out inqBuffer, out senseBuf); + if(!sense) { - sense = dev.KreonExtractSs(out cmdBuf, out senseBuf, dev.Timeout, out duration); - if(sense) - DicConsole.DebugWriteLine("Media-Info command", "KREON EXTRACT SS:\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - else - DataFile.WriteTo("Media-Info command", outputPrefix, "_xbox_ss.bin", "KREON EXTRACT SS", - cmdBuf); - - if(Decoders.Xbox.SS.Decode(cmdBuf).HasValue) - DicConsole.WriteLine("Xbox Security Sector:\n{0}", Decoders.Xbox.SS.Prettify(cmdBuf)); - - ulong l0Video, l1Video, middleZone, gameSize, totalSize, layerBreak; - - // Get video partition size - DicConsole.DebugWriteLine("Dump-media command", "Getting video partition size"); - sense = dev.KreonLock(out senseBuf, dev.Timeout, out duration); - if(sense) + inq = Decoders.SCSI.Inquiry.Decode(inqBuffer); + if(inq.HasValue && inq.Value.KreonPresent) { - DicConsole.ErrorWriteLine("Cannot lock drive, not continuing."); - return; + sense = dev.KreonExtractSs(out cmdBuf, out senseBuf, dev.Timeout, out duration); + if(sense) + DicConsole.DebugWriteLine("Media-Info command", "KREON EXTRACT SS:\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + else + DataFile.WriteTo("Media-Info command", outputPrefix, "_xbox_ss.bin", "KREON EXTRACT SS", + cmdBuf); + + if(Decoders.Xbox.SS.Decode(cmdBuf).HasValue) + DicConsole.WriteLine("Xbox Security Sector:\n{0}", Decoders.Xbox.SS.Prettify(cmdBuf)); + + ulong l0Video, l1Video, middleZone, gameSize, totalSize, layerBreak; + + // Get video partition size + DicConsole.DebugWriteLine("Dump-media command", "Getting video partition size"); + sense = dev.KreonLock(out senseBuf, dev.Timeout, out duration); + if(sense) + { + DicConsole.ErrorWriteLine("Cannot lock drive, not continuing."); + return; + } + + sense = dev.ReadCapacity(out cmdBuf, out senseBuf, dev.Timeout, out duration); + if(sense) + { + DicConsole.ErrorWriteLine("Cannot get disc capacity."); + return; + } + + totalSize = (ulong)((cmdBuf[0] << 24) + (cmdBuf[1] << 16) + (cmdBuf[2] << 8) + cmdBuf[3]); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.PhysicalInformation, 0, 0, out duration); + if(sense) + { + DicConsole.ErrorWriteLine("Cannot get PFI."); + return; + } + + DicConsole.DebugWriteLine("Dump-media command", "Video partition total size: {0} sectors", + totalSize); + l0Video = Decoders.DVD.PFI.Decode(cmdBuf).Value.Layer0EndPSN - + Decoders.DVD.PFI.Decode(cmdBuf).Value.DataAreaStartPSN + 1; + l1Video = totalSize - l0Video + 1; + + // Get game partition size + DicConsole.DebugWriteLine("Dump-media command", "Getting game partition size"); + sense = dev.KreonUnlockXtreme(out senseBuf, dev.Timeout, out duration); + if(sense) + { + DicConsole.ErrorWriteLine("Cannot unlock drive, not continuing."); + return; + } + + sense = dev.ReadCapacity(out cmdBuf, out senseBuf, dev.Timeout, out duration); + if(sense) + { + DicConsole.ErrorWriteLine("Cannot get disc capacity."); + return; + } + + gameSize = (ulong)((cmdBuf[0] << 24) + (cmdBuf[1] << 16) + (cmdBuf[2] << 8) + cmdBuf[3]) + 1; + DicConsole.DebugWriteLine("Dump-media command", "Game partition total size: {0} sectors", + gameSize); + + // Get middle zone size + DicConsole.DebugWriteLine("Dump-media command", "Getting middle zone size"); + sense = dev.KreonUnlockWxripper(out senseBuf, dev.Timeout, out duration); + if(sense) + { + DicConsole.ErrorWriteLine("Cannot unlock drive, not continuing."); + return; + } + + sense = dev.ReadCapacity(out cmdBuf, out senseBuf, dev.Timeout, out duration); + if(sense) + { + DicConsole.ErrorWriteLine("Cannot get disc capacity."); + return; + } + + totalSize = (ulong)((cmdBuf[0] << 24) + (cmdBuf[1] << 16) + (cmdBuf[2] << 8) + cmdBuf[3]); + sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, + MmcDiscStructureFormat.PhysicalInformation, 0, 0, out duration); + if(sense) + { + DicConsole.ErrorWriteLine("Cannot get PFI."); + return; + } + + DicConsole.DebugWriteLine("Dump-media command", "Unlocked total size: {0} sectors", totalSize); + middleZone = + totalSize - (Decoders.DVD.PFI.Decode(cmdBuf).Value.Layer0EndPSN - + Decoders.DVD.PFI.Decode(cmdBuf).Value.DataAreaStartPSN + 1) - gameSize + 1; + + totalSize = l0Video + l1Video + middleZone * 2 + gameSize; + layerBreak = l0Video + middleZone + gameSize / 2; + + DicConsole.WriteLine("Video layer 0 size: {0} sectors", l0Video); + DicConsole.WriteLine("Video layer 1 size: {0} sectors", l1Video); + DicConsole.WriteLine("Middle zone size: {0} sectors", middleZone); + DicConsole.WriteLine("Game data size: {0} sectors", gameSize); + DicConsole.WriteLine("Total size: {0} sectors", totalSize); + DicConsole.WriteLine("Real layer break: {0}", layerBreak); + DicConsole.WriteLine(); } - - sense = dev.ReadCapacity(out cmdBuf, out senseBuf, dev.Timeout, out duration); - if(sense) - { - DicConsole.ErrorWriteLine("Cannot get disc capacity."); - return; - } - - totalSize = (ulong)((cmdBuf[0] << 24) + (cmdBuf[1] << 16) + (cmdBuf[2] << 8) + cmdBuf[3]); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.PhysicalInformation, 0, 0, out duration); - if(sense) - { - DicConsole.ErrorWriteLine("Cannot get PFI."); - return; - } - - DicConsole.DebugWriteLine("Dump-media command", "Video partition total size: {0} sectors", - totalSize); - l0Video = Decoders.DVD.PFI.Decode(cmdBuf).Value.Layer0EndPSN - - Decoders.DVD.PFI.Decode(cmdBuf).Value.DataAreaStartPSN + 1; - l1Video = totalSize - l0Video + 1; - - // Get game partition size - DicConsole.DebugWriteLine("Dump-media command", "Getting game partition size"); - sense = dev.KreonUnlockXtreme(out senseBuf, dev.Timeout, out duration); - if(sense) - { - DicConsole.ErrorWriteLine("Cannot unlock drive, not continuing."); - return; - } - - sense = dev.ReadCapacity(out cmdBuf, out senseBuf, dev.Timeout, out duration); - if(sense) - { - DicConsole.ErrorWriteLine("Cannot get disc capacity."); - return; - } - - gameSize = (ulong)((cmdBuf[0] << 24) + (cmdBuf[1] << 16) + (cmdBuf[2] << 8) + cmdBuf[3]) + 1; - DicConsole.DebugWriteLine("Dump-media command", "Game partition total size: {0} sectors", - gameSize); - - // Get middle zone size - DicConsole.DebugWriteLine("Dump-media command", "Getting middle zone size"); - sense = dev.KreonUnlockWxripper(out senseBuf, dev.Timeout, out duration); - if(sense) - { - DicConsole.ErrorWriteLine("Cannot unlock drive, not continuing."); - return; - } - - sense = dev.ReadCapacity(out cmdBuf, out senseBuf, dev.Timeout, out duration); - if(sense) - { - DicConsole.ErrorWriteLine("Cannot get disc capacity."); - return; - } - - totalSize = (ulong)((cmdBuf[0] << 24) + (cmdBuf[1] << 16) + (cmdBuf[2] << 8) + cmdBuf[3]); - sense = dev.ReadDiscStructure(out cmdBuf, out senseBuf, MmcDiscStructureMediaType.Dvd, 0, 0, - MmcDiscStructureFormat.PhysicalInformation, 0, 0, out duration); - if(sense) - { - DicConsole.ErrorWriteLine("Cannot get PFI."); - return; - } - - DicConsole.DebugWriteLine("Dump-media command", "Unlocked total size: {0} sectors", totalSize); - middleZone = - totalSize - (Decoders.DVD.PFI.Decode(cmdBuf).Value.Layer0EndPSN - - Decoders.DVD.PFI.Decode(cmdBuf).Value.DataAreaStartPSN + 1) - gameSize + 1; - - totalSize = l0Video + l1Video + middleZone * 2 + gameSize; - layerBreak = l0Video + middleZone + gameSize / 2; - - DicConsole.WriteLine("Video layer 0 size: {0} sectors", l0Video); - DicConsole.WriteLine("Video layer 1 size: {0} sectors", l1Video); - DicConsole.WriteLine("Middle zone size: {0} sectors", middleZone); - DicConsole.WriteLine("Game data size: {0} sectors", gameSize); - DicConsole.WriteLine("Total size: {0} sectors", totalSize); - DicConsole.WriteLine("Real layer break: {0}", layerBreak); - DicConsole.WriteLine(); } - } + + break; + case MediaType.Unknown: + dskType = MediaTypeFromScsi.Get((byte)dev.ScsiType, dev.Manufacturer, dev.Model, scsiMediumType, + scsiDensityCode, blocks, blockSize); + break; } #endregion Xbox - if(dskType == MediaType.Unknown) - dskType = MediaTypeFromScsi.Get((byte)dev.ScsiType, dev.Manufacturer, dev.Model, scsiMediumType, - scsiDensityCode, blocks, blockSize); - if(dskType == MediaType.Unknown && dev.IsUsb && containsFloppyPage) dskType = MediaType.FlashDrive; DicConsole.WriteLine("Media identified as {0}", dskType);