From 9dc57c2bd897f097cddfdb3d673898cca08a4cc7 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 14 Sep 2021 20:44:06 +0100 Subject: [PATCH] Remove deprecated FreeBSD code. --- .../Devices/Dumping/CompactDisc/CdiReady.cs | 1 - Aaru.Core/Devices/Dumping/CompactDisc/Data.cs | 1 - Aaru.Core/Devices/Dumping/CompactDisc/Dump.cs | 132 ++-- Aaru.Devices/Aaru.Devices.csproj | 129 ++-- Aaru.Devices/Command.cs | 44 -- Aaru.Devices/Device/Constructor.cs | 23 +- Aaru.Devices/Device/Destructor.cs | 7 +- Aaru.Devices/Device/List.cs | 1 - Aaru.Devices/FreeBSD/Command.cs | 630 ---------------- Aaru.Devices/FreeBSD/Enums.cs | 572 -------------- Aaru.Devices/FreeBSD/Extern.cs | 66 -- Aaru.Devices/FreeBSD/ListDevices.cs | 169 ----- Aaru.Devices/FreeBSD/Structs.cs | 711 ------------------ Aaru.Gui/ViewModels/Dialogs/AboutViewModel.cs | 7 +- README.md | 7 +- 15 files changed, 122 insertions(+), 2378 deletions(-) delete mode 100644 Aaru.Devices/FreeBSD/Command.cs delete mode 100644 Aaru.Devices/FreeBSD/Enums.cs delete mode 100644 Aaru.Devices/FreeBSD/Extern.cs delete mode 100644 Aaru.Devices/FreeBSD/ListDevices.cs delete mode 100644 Aaru.Devices/FreeBSD/Structs.cs diff --git a/Aaru.Core/Devices/Dumping/CompactDisc/CdiReady.cs b/Aaru.Core/Devices/Dumping/CompactDisc/CdiReady.cs index 86dbcbfd7..047fffcd3 100644 --- a/Aaru.Core/Devices/Dumping/CompactDisc/CdiReady.cs +++ b/Aaru.Core/Devices/Dumping/CompactDisc/CdiReady.cs @@ -197,7 +197,6 @@ namespace Aaru.Core.Devices.Dumping if(cdiReadyReadAsAudio) { - // TODO: FreeBSD bug if(offsetBytes < 0) { if(i == 0) diff --git a/Aaru.Core/Devices/Dumping/CompactDisc/Data.cs b/Aaru.Core/Devices/Dumping/CompactDisc/Data.cs index 2844c9187..bc04948e3 100644 --- a/Aaru.Core/Devices/Dumping/CompactDisc/Data.cs +++ b/Aaru.Core/Devices/Dumping/CompactDisc/Data.cs @@ -221,7 +221,6 @@ namespace Aaru.Core.Devices.Dumping if(_fixOffset && !inData) { - // TODO: FreeBSD bug if(offsetBytes < 0) { if(i == 0) diff --git a/Aaru.Core/Devices/Dumping/CompactDisc/Dump.cs b/Aaru.Core/Devices/Dumping/CompactDisc/Dump.cs index 327e8565e..92a00d058 100644 --- a/Aaru.Core/Devices/Dumping/CompactDisc/Dump.cs +++ b/Aaru.Core/Devices/Dumping/CompactDisc/Dump.cs @@ -46,7 +46,6 @@ using Aaru.Database.Models; using Aaru.Decoders.CD; using Aaru.Devices; using Schemas; -using PlatformID = Aaru.CommonTypes.Interop.PlatformID; using TrackType = Aaru.CommonTypes.Enums.TrackType; using Version = Aaru.CommonTypes.Interop.Version; @@ -64,63 +63,63 @@ namespace Aaru.Core.Devices.Dumping /// Dumps a compact disc void CompactDisc() { - ExtentsULong audioExtents; // Extents with audio sectors - ulong blocks; // Total number of positive sectors - uint blockSize; // Size of the read sector in bytes - CdOffset cdOffset; // Read offset from database - byte[] cmdBuf; // Data buffer - DumpHardwareType currentTry = null; // Current dump hardware try - double currentSpeed = 0; // Current read speed - int? discOffset = null; // Disc write offset - DateTime dumpStart = DateTime.UtcNow; // Time of dump start - DateTime end; // Time of operation end - ExtentsULong extents = null; // Extents - bool hiddenData; // Hidden track is data - IbgLog ibgLog; // IMGBurn log - double imageWriteDuration = 0; // Duration of image write - long lastSector; // Last sector number + ExtentsULong audioExtents; // Extents with audio sectors + ulong blocks; // Total number of positive sectors + uint blockSize; // Size of the read sector in bytes + CdOffset cdOffset; // Read offset from database + byte[] cmdBuf; // Data buffer + DumpHardwareType currentTry = null; // Current dump hardware try + double currentSpeed = 0; // Current read speed + int? discOffset = null; // Disc write offset + DateTime dumpStart = DateTime.UtcNow; // Time of dump start + DateTime end; // Time of operation end + ExtentsULong extents = null; // Extents + bool hiddenData; // Hidden track is data + IbgLog ibgLog; // IMGBurn log + double imageWriteDuration = 0; // Duration of image write + long lastSector; // Last sector number var leadOutExtents = new ExtentsULong(); // Lead-out extents - Dictionary leadOutStarts = new Dictionary(); // Lead-out starts - double maxSpeed = double.MinValue; // Maximum speed - MhddLog mhddLog; // MHDD log - double minSpeed = double.MaxValue; // Minimum speed - bool newTrim; // Is trim a new one? - int offsetBytes = 0; // Read offset - bool read6 = false; // Device supports READ(6) - bool read10 = false; // Device supports READ(10) - bool read12 = false; // Device supports READ(12) - bool read16 = false; // Device supports READ(16) - bool readcd; // Device supports READ CD - bool ret; // Image writing return status - const uint sectorSize = 2352; // Full sector size - int sectorsForOffset = 0; // Sectors needed to fix offset - bool sense = true; // Sense indicator - int sessions; // Number of sessions in disc - DateTime start; // Start of operation - SubchannelLog subLog = null; // Subchannel log - uint subSize; // Subchannel size in bytes - TrackSubchannelType subType; // Track subchannel type - bool supportsLongSectors = true; // Supports reading EDC and ECC - bool supportsPqSubchannel; // Supports reading PQ subchannel - bool supportsRwSubchannel; // Supports reading RW subchannel - byte[] tmpBuf; // Temporary buffer - FullTOC.CDFullTOC? toc; // Full CD TOC - double totalDuration = 0; // Total commands duration - Dictionary trackFlags = new Dictionary(); // Track flags - Track[] tracks; // Tracks in disc - int firstTrackLastSession; // Number of first track in last session - bool hiddenTrack; // Disc has a hidden track before track 1 - MmcSubchannel supportedSubchannel; // Drive's maximum supported subchannel - MmcSubchannel desiredSubchannel; // User requested subchannel - bool bcdSubchannel = false; // Subchannel positioning is in BCD - Dictionary isrcs = new Dictionary(); + Dictionary leadOutStarts = new(); // Lead-out starts + double maxSpeed = double.MinValue; // Maximum speed + MhddLog mhddLog; // MHDD log + double minSpeed = double.MaxValue; // Minimum speed + bool newTrim; // Is trim a new one? + int offsetBytes = 0; // Read offset + bool read6 = false; // Device supports READ(6) + bool read10 = false; // Device supports READ(10) + bool read12 = false; // Device supports READ(12) + bool read16 = false; // Device supports READ(16) + bool readcd; // Device supports READ CD + bool ret; // Image writing return status + const uint sectorSize = 2352; // Full sector size + int sectorsForOffset = 0; // Sectors needed to fix offset + bool sense = true; // Sense indicator + int sessions; // Number of sessions in disc + DateTime start; // Start of operation + SubchannelLog subLog = null; // Subchannel log + uint subSize; // Subchannel size in bytes + TrackSubchannelType subType; // Track subchannel type + bool supportsLongSectors = true; // Supports reading EDC and ECC + bool supportsPqSubchannel; // Supports reading PQ subchannel + bool supportsRwSubchannel; // Supports reading RW subchannel + byte[] tmpBuf; // Temporary buffer + FullTOC.CDFullTOC? toc; // Full CD TOC + double totalDuration = 0; // Total commands duration + Dictionary trackFlags = new(); // Track flags + Track[] tracks; // Tracks in disc + int firstTrackLastSession; // Number of first track in last session + bool hiddenTrack; // Disc has a hidden track before track 1 + MmcSubchannel supportedSubchannel; // Drive's maximum supported subchannel + MmcSubchannel desiredSubchannel; // User requested subchannel + bool bcdSubchannel = false; // Subchannel positioning is in BCD + Dictionary isrcs = new(); string mcn = null; - HashSet subchannelExtents = new HashSet(); + HashSet subchannelExtents = new(); bool cdiReadyReadAsAudio = false; uint firstLba; - Dictionary mediaTags = new Dictionary(); // Media tags - Dictionary smallestPregapLbaPerTrack = new Dictionary(); + Dictionary mediaTags = new(); // Media tags + Dictionary smallestPregapLbaPerTrack = new(); MediaType dskType = MediaType.CD; @@ -565,7 +564,7 @@ namespace Aaru.Core.Devices.Dumping _dumpLog.WriteLine("Disc contains a hidden track..."); UpdateStatus?.Invoke("Disc contains a hidden track..."); - List trkList = new List + List trkList = new() { new Track { @@ -721,31 +720,6 @@ namespace Aaru.Core.Devices.Dumping // Check if something prevents from dumping the first track pregap if(_dumpFirstTrackPregap && readcd) { - if(_dev.PlatformId == PlatformID.FreeBSD && - !_dev.IsRemote) - { - if(_force) - { - _dumpLog. - WriteLine("FreeBSD panics when reading CD first track pregap, see upstream bug #224253. continuing"); - - ErrorMessage?. - Invoke("FreeBSD panics when reading CD first track pregap, see upstream bug #224253. continuing"); - } - else - { - _dumpLog. - WriteLine("FreeBSD panics when reading CD first track pregap, see upstream bug #224253. Not continuing"); - - StoppingErrorMessage?. - Invoke("FreeBSD panics when reading CD first track pregap, see upstream bug #224253. Not continuing"); - - return; - } - - _dumpFirstTrackPregap = false; - } - if(!_outputPlugin.SupportedMediaTags.Contains(MediaTagType.CD_FirstTrackPregap)) { if(_force) diff --git a/Aaru.Devices/Aaru.Devices.csproj b/Aaru.Devices/Aaru.Devices.csproj index faf19f52a..4a2a0a571 100644 --- a/Aaru.Devices/Aaru.Devices.csproj +++ b/Aaru.Devices/Aaru.Devices.csproj @@ -56,87 +56,82 @@ false - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - + + + + - + {CCAA7AFE-C094-4D82-A66D-630DE8A3F545} Aaru.Console diff --git a/Aaru.Devices/Command.cs b/Aaru.Devices/Command.cs index 0b60ee5fc..09949aab2 100644 --- a/Aaru.Devices/Command.cs +++ b/Aaru.Devices/Command.cs @@ -33,7 +33,6 @@ using System; using Aaru.CommonTypes.Interop; using Aaru.Decoders.ATA; -using Aaru.Devices.FreeBSD; using Aaru.Devices.Windows; using Microsoft.Win32.SafeHandles; using PlatformID = Aaru.CommonTypes.Interop.PlatformID; @@ -142,36 +141,6 @@ namespace Aaru.Devices return Linux.Command.SendScsiCommand((int)fd, cdb, ref buffer, out senseBuffer, timeout, dir, out duration, out sense); } - case PlatformID.FreeBSD: - { - CcbFlags flags = 0; - - switch(direction) - { - case ScsiDirection.In: - flags = CcbFlags.CamDirIn; - - break; - case ScsiDirection.Out: - flags = CcbFlags.CamDirOut; - - break; - case ScsiDirection.Bidirectional: - flags = CcbFlags.CamDirBoth; - - break; - case ScsiDirection.None: - flags = CcbFlags.CamDirNone; - - break; - } - - return IntPtr.Size == 8 - ? FreeBSD.Command.SendScsiCommand64((IntPtr)fd, cdb, ref buffer, out senseBuffer, - timeout, flags, out duration, out sense) - : FreeBSD.Command.SendScsiCommand((IntPtr)fd, cdb, ref buffer, out senseBuffer, timeout, - flags, out duration, out sense); - } default: throw new InvalidOperationException($"Platform {ptId} not yet supported."); } } @@ -242,11 +211,6 @@ namespace Aaru.Devices transferRegister, ref buffer, timeout, transferBlocks, out duration, out sense); } - case PlatformID.FreeBSD: - { - return FreeBSD.Command.SendAtaCommand((IntPtr)fd, registers, out errorRegisters, protocol, - ref buffer, timeout, out duration, out sense); - } default: throw new InvalidOperationException($"Platform {ptId} not yet supported."); } } @@ -317,11 +281,6 @@ namespace Aaru.Devices transferRegister, ref buffer, timeout, transferBlocks, out duration, out sense); } - case PlatformID.FreeBSD: - { - return FreeBSD.Command.SendAtaCommand((IntPtr)fd, registers, out errorRegisters, protocol, - ref buffer, timeout, out duration, out sense); - } default: throw new InvalidOperationException($"Platform {ptId} not yet supported."); } } @@ -379,9 +338,6 @@ namespace Aaru.Devices return Linux.Command.SendAtaCommand((int)fd, registers, out errorRegisters, protocol, transferRegister, ref buffer, timeout, transferBlocks, out duration, out sense); - case PlatformID.FreeBSD: - return FreeBSD.Command.SendAtaCommand((IntPtr)fd, registers, out errorRegisters, protocol, - ref buffer, timeout, out duration, out sense); default: throw new InvalidOperationException($"Platform {ptId} not yet supported."); } } diff --git a/Aaru.Devices/Device/Constructor.cs b/Aaru.Devices/Device/Constructor.cs index cc8db989c..a4d83536a 100644 --- a/Aaru.Devices/Device/Constructor.cs +++ b/Aaru.Devices/Device/Constructor.cs @@ -42,14 +42,13 @@ using Aaru.CommonTypes.Structs.Devices.SCSI; using Aaru.Decoders.SCSI; using Aaru.Decoders.SCSI.MMC; using Aaru.Decoders.SecureDigital; -using Aaru.Devices.FreeBSD; +using Aaru.Devices.Linux; using Aaru.Devices.Windows; using Aaru.Helpers; using Microsoft.Win32.SafeHandles; using Extern = Aaru.Devices.Windows.Extern; using FileAccess = Aaru.Devices.Windows.FileAccess; using FileAttributes = Aaru.Devices.Windows.FileAttributes; -using FileFlags = Aaru.Devices.Linux.FileFlags; using FileMode = Aaru.Devices.Windows.FileMode; using FileShare = Aaru.Devices.Windows.FileShare; using Inquiry = Aaru.CommonTypes.Structs.Devices.SCSI.Inquiry; @@ -151,25 +150,7 @@ namespace Aaru.Devices break; } - case PlatformID.FreeBSD: - { - FileHandle = FreeBSD.Extern.cam_open_device(devicePath, FreeBSD.FileFlags.ReadWrite); - - if(((IntPtr)FileHandle).ToInt64() == 0) - { - Error = true; - LastError = Marshal.GetLastWin32Error(); - } - - var camDevice = (CamDevice)Marshal.PtrToStructure((IntPtr)FileHandle, typeof(CamDevice)); - - if(StringHandlers.CToString(camDevice.SimName) == "ata") - throw new - DeviceException("Parallel ATA devices are not supported on FreeBSD due to upstream bug #224250."); - - break; - } - default: throw new DeviceException($"Platform {PlatformId} not yet supported."); + default: throw new DeviceException($"Platform {PlatformId} not supported."); } } diff --git a/Aaru.Devices/Device/Destructor.cs b/Aaru.Devices/Device/Destructor.cs index b520a6d8c..18eb58df1 100644 --- a/Aaru.Devices/Device/Destructor.cs +++ b/Aaru.Devices/Device/Destructor.cs @@ -30,10 +30,9 @@ // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ -using System; +using Aaru.CommonTypes.Interop; using Aaru.Devices.Linux; using Microsoft.Win32.SafeHandles; -using PlatformID = Aaru.CommonTypes.Interop.PlatformID; namespace Aaru.Devices { @@ -68,10 +67,6 @@ namespace Aaru.Devices case PlatformID.Linux: Extern.close((int)FileHandle); - break; - case PlatformID.FreeBSD: - FreeBSD.Extern.cam_close_device((IntPtr)FileHandle); - break; } diff --git a/Aaru.Devices/Device/List.cs b/Aaru.Devices/Device/List.cs index 70ebaedb9..d93c5e671 100644 --- a/Aaru.Devices/Device/List.cs +++ b/Aaru.Devices/Device/List.cs @@ -107,7 +107,6 @@ namespace Aaru.Devices { case PlatformID.Win32NT: return Windows.ListDevices.GetList(); case PlatformID.Linux: return Linux.ListDevices.GetList(); - case PlatformID.FreeBSD: return FreeBSD.ListDevices.GetList(); default: throw new InvalidOperationException($"Platform {DetectOS.GetRealPlatformID()} not yet supported."); diff --git a/Aaru.Devices/FreeBSD/Command.cs b/Aaru.Devices/FreeBSD/Command.cs deleted file mode 100644 index adc9c2b3d..000000000 --- a/Aaru.Devices/FreeBSD/Command.cs +++ /dev/null @@ -1,630 +0,0 @@ -// /*************************************************************************** -// Aaru Data Preservation Suite -// ---------------------------------------------------------------------------- -// -// Filename : Command.cs -// Author(s) : Natalia Portillo -// -// Component : FreeBSD direct device access. -// -// --[ Description ] ---------------------------------------------------------- -// -// Contains a high level representation of the FreeBSD syscalls used to -// directly interface devices. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; -using Aaru.Console; -using Aaru.Decoders.ATA; -using static Aaru.Devices.FreeBSD.Extern; - -namespace Aaru.Devices.FreeBSD -{ - [SuppressMessage("ReSharper", "BitwiseOperatorOnEnumWithoutFlags"), Obsolete] - internal static class Command - { - const int CAM_MAX_CDBLEN = 16; - - /// Sends a SCSI command (64-bit arch) - /// 0 if no error occurred, otherwise, errno - /// CAM device - /// SCSI CDB - /// Buffer for SCSI command response - /// Buffer with the SCSI sense - /// Timeout in seconds - /// SCSI command transfer direction - /// Time it took to execute the command in milliseconds - /// - /// True if SCSI error returned non-OK status and contains SCSI - /// sense - /// - [Obsolete] - internal static int SendScsiCommand64(IntPtr dev, byte[] cdb, ref byte[] buffer, out byte[] senseBuffer, - uint timeout, CcbFlags direction, out double duration, out bool sense) - { - senseBuffer = null; - duration = 0; - sense = false; - - if(buffer == null) - return -1; - - IntPtr ccbPtr = cam_getccb(dev); - IntPtr cdbPtr = IntPtr.Zero; - - if(ccbPtr.ToInt64() == 0) - { - sense = true; - - return Marshal.GetLastWin32Error(); - } - - var csio = (CcbScsiio64)Marshal.PtrToStructure(ccbPtr, typeof(CcbScsiio64)); - csio.ccb_h.func_code = XptOpcode.XptScsiIo; - csio.ccb_h.flags = direction; - csio.ccb_h.xflags = 0; - csio.ccb_h.retry_count = 1; - csio.ccb_h.cbfcnp = IntPtr.Zero; - csio.ccb_h.timeout = timeout; - csio.data_ptr = Marshal.AllocHGlobal(buffer.Length); - csio.dxfer_len = (uint)buffer.Length; - csio.sense_len = 32; - csio.cdb_len = (byte)cdb.Length; - - // TODO: Create enum? - csio.tag_action = 0x20; - csio.cdb_bytes = new byte[CAM_MAX_CDBLEN]; - - if(cdb.Length <= CAM_MAX_CDBLEN) - Array.Copy(cdb, 0, csio.cdb_bytes, 0, cdb.Length); - else - { - cdbPtr = Marshal.AllocHGlobal(cdb.Length); - byte[] cdbPtrBytes = BitConverter.GetBytes(cdbPtr.ToInt64()); - Array.Copy(cdbPtrBytes, 0, csio.cdb_bytes, 0, IntPtr.Size); - csio.ccb_h.flags |= CcbFlags.CamCdbPointer; - } - - csio.ccb_h.flags |= CcbFlags.CamDevQfrzdis; - - Marshal.Copy(buffer, 0, csio.data_ptr, buffer.Length); - Marshal.StructureToPtr(csio, ccbPtr, false); - - DateTime start = DateTime.UtcNow; - int error = cam_send_ccb(dev, ccbPtr); - DateTime end = DateTime.UtcNow; - - if(error < 0) - error = Marshal.GetLastWin32Error(); - - csio = (CcbScsiio64)Marshal.PtrToStructure(ccbPtr, typeof(CcbScsiio64)); - - if((csio.ccb_h.status & CamStatus.CamStatusMask) != CamStatus.CamReqCmp && - (csio.ccb_h.status & CamStatus.CamStatusMask) != CamStatus.CamScsiStatusError) - { - error = Marshal.GetLastWin32Error(); - AaruConsole.DebugWriteLine("FreeBSD devices", "CAM status {0} error {1}", csio.ccb_h.status, error); - sense = true; - } - - if((csio.ccb_h.status & CamStatus.CamStatusMask) == CamStatus.CamScsiStatusError) - { - sense = true; - senseBuffer = new byte[1]; - senseBuffer[0] = csio.scsi_status; - } - - if((csio.ccb_h.status & CamStatus.CamAutosnsValid) != 0) - if(csio.sense_len - csio.sense_resid > 0) - { - sense = (csio.ccb_h.status & CamStatus.CamStatusMask) == CamStatus.CamScsiStatusError; - senseBuffer = new byte[csio.sense_len - csio.sense_resid]; - senseBuffer[0] = csio.sense_data.error_code; - Array.Copy(csio.sense_data.sense_buf, 0, senseBuffer, 1, senseBuffer.Length - 1); - } - - buffer = new byte[csio.dxfer_len]; - cdb = new byte[csio.cdb_len]; - - Marshal.Copy(csio.data_ptr, buffer, 0, buffer.Length); - - if(csio.ccb_h.flags.HasFlag(CcbFlags.CamCdbPointer)) - Marshal.Copy(new IntPtr(BitConverter.ToInt64(csio.cdb_bytes, 0)), cdb, 0, cdb.Length); - else - Array.Copy(csio.cdb_bytes, 0, cdb, 0, cdb.Length); - - duration = (end - start).TotalMilliseconds; - - if(csio.ccb_h.flags.HasFlag(CcbFlags.CamCdbPointer)) - Marshal.FreeHGlobal(cdbPtr); - - Marshal.FreeHGlobal(csio.data_ptr); - cam_freeccb(ccbPtr); - - return error; - } - - /// Sends a SCSI command (32-bit arch) - /// 0 if no error occurred, otherwise, errno - /// CAM device - /// SCSI CDB - /// Buffer for SCSI command response - /// Buffer with the SCSI sense - /// Timeout in seconds - /// SCSI command transfer direction - /// Time it took to execute the command in milliseconds - /// - /// True if SCSI error returned non-OK status and contains SCSI - /// sense - /// - [Obsolete] - internal static int SendScsiCommand(IntPtr dev, byte[] cdb, ref byte[] buffer, out byte[] senseBuffer, - uint timeout, CcbFlags direction, out double duration, out bool sense) - { - senseBuffer = null; - duration = 0; - sense = false; - - if(buffer == null) - return -1; - - IntPtr ccbPtr = cam_getccb(dev); - IntPtr cdbPtr = IntPtr.Zero; - - if(ccbPtr.ToInt32() == 0) - { - sense = true; - - return Marshal.GetLastWin32Error(); - } - - var csio = (CcbScsiio)Marshal.PtrToStructure(ccbPtr, typeof(CcbScsiio)); - csio.ccb_h.func_code = XptOpcode.XptScsiIo; - csio.ccb_h.flags = direction; - csio.ccb_h.xflags = 0; - csio.ccb_h.retry_count = 1; - csio.ccb_h.cbfcnp = IntPtr.Zero; - csio.ccb_h.timeout = timeout; - csio.data_ptr = Marshal.AllocHGlobal(buffer.Length); - csio.dxfer_len = (uint)buffer.Length; - csio.sense_len = 32; - csio.cdb_len = (byte)cdb.Length; - - // TODO: Create enum? - csio.tag_action = 0x20; - csio.cdb_bytes = new byte[CAM_MAX_CDBLEN]; - - if(cdb.Length <= CAM_MAX_CDBLEN) - Array.Copy(cdb, 0, csio.cdb_bytes, 0, cdb.Length); - else - { - cdbPtr = Marshal.AllocHGlobal(cdb.Length); - byte[] cdbPtrBytes = BitConverter.GetBytes(cdbPtr.ToInt32()); - Array.Copy(cdbPtrBytes, 0, csio.cdb_bytes, 0, IntPtr.Size); - csio.ccb_h.flags |= CcbFlags.CamCdbPointer; - } - - csio.ccb_h.flags |= CcbFlags.CamDevQfrzdis; - - Marshal.Copy(buffer, 0, csio.data_ptr, buffer.Length); - Marshal.StructureToPtr(csio, ccbPtr, false); - - DateTime start = DateTime.UtcNow; - int error = cam_send_ccb(dev, ccbPtr); - DateTime end = DateTime.UtcNow; - - if(error < 0) - error = Marshal.GetLastWin32Error(); - - csio = (CcbScsiio)Marshal.PtrToStructure(ccbPtr, typeof(CcbScsiio)); - - if((csio.ccb_h.status & CamStatus.CamStatusMask) != CamStatus.CamReqCmp && - (csio.ccb_h.status & CamStatus.CamStatusMask) != CamStatus.CamScsiStatusError) - { - error = Marshal.GetLastWin32Error(); - AaruConsole.DebugWriteLine("FreeBSD devices", "CAM status {0} error {1}", csio.ccb_h.status, error); - sense = true; - } - - if((csio.ccb_h.status & CamStatus.CamStatusMask) == CamStatus.CamScsiStatusError) - { - sense = true; - senseBuffer = new byte[1]; - senseBuffer[0] = csio.scsi_status; - } - - if((csio.ccb_h.status & CamStatus.CamAutosnsValid) != 0) - if(csio.sense_len - csio.sense_resid > 0) - { - sense = (csio.ccb_h.status & CamStatus.CamStatusMask) == CamStatus.CamScsiStatusError; - senseBuffer = new byte[csio.sense_len - csio.sense_resid]; - senseBuffer[0] = csio.sense_data.error_code; - Array.Copy(csio.sense_data.sense_buf, 0, senseBuffer, 1, senseBuffer.Length - 1); - } - - buffer = new byte[csio.dxfer_len]; - cdb = new byte[csio.cdb_len]; - - Marshal.Copy(csio.data_ptr, buffer, 0, buffer.Length); - - if(csio.ccb_h.flags.HasFlag(CcbFlags.CamCdbPointer)) - Marshal.Copy(new IntPtr(BitConverter.ToInt32(csio.cdb_bytes, 0)), cdb, 0, cdb.Length); - else - Array.Copy(csio.cdb_bytes, 0, cdb, 0, cdb.Length); - - duration = (end - start).TotalMilliseconds; - - if(csio.ccb_h.flags.HasFlag(CcbFlags.CamCdbPointer)) - Marshal.FreeHGlobal(cdbPtr); - - Marshal.FreeHGlobal(csio.data_ptr); - cam_freeccb(ccbPtr); - - return error; - } - - /// Converts ATA protocol to CAM flags - /// ATA protocol - /// CAM flags - [Obsolete] - static CcbFlags AtaProtocolToCamFlags(AtaProtocol protocol) - { - switch(protocol) - { - case AtaProtocol.DeviceDiagnostic: - case AtaProtocol.DeviceReset: - case AtaProtocol.HardReset: - case AtaProtocol.NonData: - case AtaProtocol.SoftReset: - case AtaProtocol.ReturnResponse: return CcbFlags.CamDirNone; - case AtaProtocol.PioIn: - case AtaProtocol.UDmaIn: return CcbFlags.CamDirIn; - case AtaProtocol.PioOut: - case AtaProtocol.UDmaOut: return CcbFlags.CamDirOut; - default: return CcbFlags.CamDirNone; - } - } - - /// Sends an ATA command in CHS mode - /// 0 if no error occurred, otherwise, errno - /// CAM device - /// Buffer for SCSI command response - /// Timeout in seconds - /// Time it took to execute the command in milliseconds - /// True if ATA error returned non-OK status - /// Registers to send to drive - /// Registers returned by drive - /// ATA protocol to use - [Obsolete] - internal static int SendAtaCommand(IntPtr dev, AtaRegistersChs registers, - out AtaErrorRegistersChs errorRegisters, AtaProtocol protocol, - ref byte[] buffer, uint timeout, out double duration, out bool sense) - { - duration = 0; - sense = false; - errorRegisters = new AtaErrorRegistersChs(); - - if(buffer == null) - return -1; - - IntPtr ccbPtr = cam_getccb(dev); - - var ataio = (CcbAtaio)Marshal.PtrToStructure(ccbPtr, typeof(CcbAtaio)); - ataio.ccb_h.func_code = XptOpcode.XptAtaIo; - ataio.ccb_h.flags = AtaProtocolToCamFlags(protocol); - ataio.ccb_h.xflags = 0; - ataio.ccb_h.retry_count = 1; - ataio.ccb_h.cbfcnp = IntPtr.Zero; - ataio.ccb_h.timeout = timeout; - ataio.data_ptr = Marshal.AllocHGlobal(buffer.Length); - ataio.dxfer_len = (uint)buffer.Length; - ataio.ccb_h.flags |= CcbFlags.CamDevQfrzdis; - ataio.cmd.flags = CamAtaIoFlags.NeedResult; - - switch(protocol) - { - case AtaProtocol.Dma: - case AtaProtocol.DmaQueued: - case AtaProtocol.UDmaIn: - case AtaProtocol.UDmaOut: - ataio.cmd.flags |= CamAtaIoFlags.Dma; - - break; - case AtaProtocol.FpDma: - ataio.cmd.flags |= CamAtaIoFlags.Fpdma; - - break; - } - - ataio.cmd.command = registers.Command; - ataio.cmd.lba_high = registers.CylinderHigh; - ataio.cmd.lba_mid = registers.CylinderLow; - ataio.cmd.device = (byte)(0x40 | registers.DeviceHead); - ataio.cmd.features = registers.Feature; - ataio.cmd.sector_count = registers.SectorCount; - ataio.cmd.lba_low = registers.Sector; - - Marshal.Copy(buffer, 0, ataio.data_ptr, buffer.Length); - Marshal.StructureToPtr(ataio, ccbPtr, false); - - DateTime start = DateTime.UtcNow; - int error = cam_send_ccb(dev, ccbPtr); - DateTime end = DateTime.UtcNow; - - if(error < 0) - error = Marshal.GetLastWin32Error(); - - ataio = (CcbAtaio)Marshal.PtrToStructure(ccbPtr, typeof(CcbAtaio)); - - if((ataio.ccb_h.status & CamStatus.CamStatusMask) != CamStatus.CamReqCmp && - (ataio.ccb_h.status & CamStatus.CamStatusMask) != CamStatus.CamAtaStatusError) - { - error = Marshal.GetLastWin32Error(); - AaruConsole.DebugWriteLine("FreeBSD devices", "CAM status {0} error {1}", ataio.ccb_h.status, error); - sense = true; - } - - if((ataio.ccb_h.status & CamStatus.CamStatusMask) == CamStatus.CamAtaStatusError) - sense = true; - - errorRegisters.CylinderHigh = ataio.res.lba_high; - errorRegisters.CylinderLow = ataio.res.lba_mid; - errorRegisters.DeviceHead = ataio.res.device; - errorRegisters.Error = ataio.res.error; - errorRegisters.Sector = ataio.res.lba_low; - errorRegisters.SectorCount = ataio.res.sector_count; - errorRegisters.Status = ataio.res.status; - - buffer = new byte[ataio.dxfer_len]; - - Marshal.Copy(ataio.data_ptr, buffer, 0, buffer.Length); - duration = (end - start).TotalMilliseconds; - - Marshal.FreeHGlobal(ataio.data_ptr); - cam_freeccb(ccbPtr); - - sense = errorRegisters.Error != 0 || (errorRegisters.Status & 0xA5) != 0 || error != 0; - - return error; - } - - /// Sends an ATA command in 28-bit LBA mode - /// 0 if no error occurred, otherwise, errno - /// CAM device - /// Buffer for SCSI command response - /// Timeout in seconds - /// Time it took to execute the command in milliseconds - /// True if ATA error returned non-OK status - /// Registers to send to drive - /// Registers returned by drive - /// ATA protocol to use - [Obsolete] - internal static int SendAtaCommand(IntPtr dev, AtaRegistersLba28 registers, - out AtaErrorRegistersLba28 errorRegisters, AtaProtocol protocol, - ref byte[] buffer, uint timeout, out double duration, out bool sense) - { - duration = 0; - sense = false; - errorRegisters = new AtaErrorRegistersLba28(); - - if(buffer == null) - return -1; - - IntPtr ccbPtr = cam_getccb(dev); - - var ataio = (CcbAtaio)Marshal.PtrToStructure(ccbPtr, typeof(CcbAtaio)); - ataio.ccb_h.func_code = XptOpcode.XptAtaIo; - ataio.ccb_h.flags = AtaProtocolToCamFlags(protocol); - ataio.ccb_h.xflags = 0; - ataio.ccb_h.retry_count = 1; - ataio.ccb_h.cbfcnp = IntPtr.Zero; - ataio.ccb_h.timeout = timeout; - ataio.data_ptr = Marshal.AllocHGlobal(buffer.Length); - ataio.dxfer_len = (uint)buffer.Length; - ataio.ccb_h.flags |= CcbFlags.CamDevQfrzdis; - ataio.cmd.flags = CamAtaIoFlags.NeedResult; - - switch(protocol) - { - case AtaProtocol.Dma: - case AtaProtocol.DmaQueued: - case AtaProtocol.UDmaIn: - case AtaProtocol.UDmaOut: - ataio.cmd.flags |= CamAtaIoFlags.Dma; - - break; - case AtaProtocol.FpDma: - ataio.cmd.flags |= CamAtaIoFlags.Fpdma; - - break; - } - - ataio.cmd.command = registers.Command; - ataio.cmd.lba_high = registers.LbaHigh; - ataio.cmd.lba_mid = registers.LbaMid; - ataio.cmd.device = (byte)(0x40 | registers.DeviceHead); - ataio.cmd.features = registers.Feature; - ataio.cmd.sector_count = registers.SectorCount; - ataio.cmd.lba_low = registers.LbaLow; - - Marshal.Copy(buffer, 0, ataio.data_ptr, buffer.Length); - Marshal.StructureToPtr(ataio, ccbPtr, false); - - DateTime start = DateTime.UtcNow; - int error = cam_send_ccb(dev, ccbPtr); - DateTime end = DateTime.UtcNow; - - if(error < 0) - error = Marshal.GetLastWin32Error(); - - ataio = (CcbAtaio)Marshal.PtrToStructure(ccbPtr, typeof(CcbAtaio)); - - if((ataio.ccb_h.status & CamStatus.CamStatusMask) != CamStatus.CamReqCmp && - (ataio.ccb_h.status & CamStatus.CamStatusMask) != CamStatus.CamAtaStatusError) - { - error = Marshal.GetLastWin32Error(); - AaruConsole.DebugWriteLine("FreeBSD devices", "CAM status {0} error {1}", ataio.ccb_h.status, error); - sense = true; - } - - if((ataio.ccb_h.status & CamStatus.CamStatusMask) == CamStatus.CamAtaStatusError) - sense = true; - - errorRegisters.LbaHigh = ataio.res.lba_high; - errorRegisters.LbaMid = ataio.res.lba_mid; - errorRegisters.DeviceHead = ataio.res.device; - errorRegisters.Error = ataio.res.error; - errorRegisters.LbaLow = ataio.res.lba_low; - errorRegisters.SectorCount = ataio.res.sector_count; - errorRegisters.Status = ataio.res.status; - - buffer = new byte[ataio.dxfer_len]; - - Marshal.Copy(ataio.data_ptr, buffer, 0, buffer.Length); - duration = (end - start).TotalMilliseconds; - - Marshal.FreeHGlobal(ataio.data_ptr); - cam_freeccb(ccbPtr); - - sense = errorRegisters.Error != 0 || (errorRegisters.Status & 0xA5) != 0 || error != 0; - - return error; - } - - /// Sends an ATA command in 48-bit mode - /// 0 if no error occurred, otherwise, errno - /// CAM device - /// Buffer for SCSI command response - /// Timeout in seconds - /// Time it took to execute the command in milliseconds - /// True if ATA error returned non-OK status - /// Registers to send to drive - /// Registers returned by drive - /// ATA protocol to use - [Obsolete] - internal static int SendAtaCommand(IntPtr dev, AtaRegistersLba48 registers, - out AtaErrorRegistersLba48 errorRegisters, AtaProtocol protocol, - ref byte[] buffer, uint timeout, out double duration, out bool sense) - { - duration = 0; - sense = false; - errorRegisters = new AtaErrorRegistersLba48(); - - // 48-bit ATA CAM commands can crash FreeBSD < 9.2-RELEASE - if((Environment.Version.Major == 9 && Environment.Version.Minor < 2) || - Environment.Version.Major < 9) - return -1; - - if(buffer == null) - return -1; - - IntPtr ccbPtr = cam_getccb(dev); - - var ataio = (CcbAtaio)Marshal.PtrToStructure(ccbPtr, typeof(CcbAtaio)); - ataio.ccb_h.func_code = XptOpcode.XptAtaIo; - ataio.ccb_h.flags = AtaProtocolToCamFlags(protocol); - ataio.ccb_h.xflags = 0; - ataio.ccb_h.retry_count = 1; - ataio.ccb_h.cbfcnp = IntPtr.Zero; - ataio.ccb_h.timeout = timeout; - ataio.data_ptr = Marshal.AllocHGlobal(buffer.Length); - ataio.dxfer_len = (uint)buffer.Length; - ataio.ccb_h.flags |= CcbFlags.CamDevQfrzdis; - ataio.cmd.flags = CamAtaIoFlags.NeedResult | CamAtaIoFlags.ExtendedCommand; - - switch(protocol) - { - case AtaProtocol.Dma: - case AtaProtocol.DmaQueued: - case AtaProtocol.UDmaIn: - case AtaProtocol.UDmaOut: - ataio.cmd.flags |= CamAtaIoFlags.Dma; - - break; - case AtaProtocol.FpDma: - ataio.cmd.flags |= CamAtaIoFlags.Fpdma; - - break; - } - - ataio.cmd.lba_high_exp = registers.LbaHighCurrent; - ataio.cmd.lba_mid_exp = registers.LbaMidCurrent; - ataio.cmd.features_exp = (byte)((registers.Feature & 0xFF00) >> 8); - ataio.cmd.sector_count_exp = (byte)((registers.SectorCount & 0xFF00) >> 8); - ataio.cmd.lba_low_exp = registers.LbaLowCurrent; - ataio.cmd.lba_high = registers.LbaHighPrevious; - ataio.cmd.lba_mid = registers.LbaMidPrevious; - ataio.cmd.features = (byte)(registers.Feature & 0xFF); - ataio.cmd.sector_count = (byte)(registers.SectorCount & 0xFF); - ataio.cmd.lba_low = registers.LbaLowPrevious; - ataio.cmd.command = registers.Command; - ataio.cmd.device = (byte)(0x40 | registers.DeviceHead); - - Marshal.Copy(buffer, 0, ataio.data_ptr, buffer.Length); - Marshal.StructureToPtr(ataio, ccbPtr, false); - - DateTime start = DateTime.UtcNow; - int error = cam_send_ccb(dev, ccbPtr); - DateTime end = DateTime.UtcNow; - - if(error < 0) - error = Marshal.GetLastWin32Error(); - - ataio = (CcbAtaio)Marshal.PtrToStructure(ccbPtr, typeof(CcbAtaio)); - - if((ataio.ccb_h.status & CamStatus.CamStatusMask) != CamStatus.CamReqCmp && - (ataio.ccb_h.status & CamStatus.CamStatusMask) != CamStatus.CamAtaStatusError) - { - error = Marshal.GetLastWin32Error(); - AaruConsole.DebugWriteLine("FreeBSD devices", "CAM status {0} error {1}", ataio.ccb_h.status, error); - sense = true; - } - - if((ataio.ccb_h.status & CamStatus.CamStatusMask) == CamStatus.CamAtaStatusError) - sense = true; - - errorRegisters.SectorCount = (ushort)((ataio.res.sector_count_exp << 8) + ataio.res.sector_count); - errorRegisters.LbaLowCurrent = ataio.res.lba_low_exp; - errorRegisters.LbaMidCurrent = ataio.res.lba_mid_exp; - errorRegisters.LbaHighCurrent = ataio.res.lba_high_exp; - errorRegisters.LbaLowPrevious = ataio.res.lba_low; - errorRegisters.LbaMidPrevious = ataio.res.lba_mid; - errorRegisters.LbaHighPrevious = ataio.res.lba_high; - errorRegisters.DeviceHead = ataio.res.device; - errorRegisters.Error = ataio.res.error; - errorRegisters.Status = ataio.res.status; - - buffer = new byte[ataio.dxfer_len]; - - Marshal.Copy(ataio.data_ptr, buffer, 0, buffer.Length); - duration = (end - start).TotalMilliseconds; - - Marshal.FreeHGlobal(ataio.data_ptr); - cam_freeccb(ccbPtr); - - sense = errorRegisters.Error != 0 || (errorRegisters.Status & 0xA5) != 0 || error != 0; - - return error; - } - } -} \ No newline at end of file diff --git a/Aaru.Devices/FreeBSD/Enums.cs b/Aaru.Devices/FreeBSD/Enums.cs deleted file mode 100644 index 69b3cd097..000000000 --- a/Aaru.Devices/FreeBSD/Enums.cs +++ /dev/null @@ -1,572 +0,0 @@ -// /*************************************************************************** -// Aaru Data Preservation Suite -// ---------------------------------------------------------------------------- -// -// Filename : Enums.cs -// Author(s) : Natalia Portillo -// -// Component : FreeBSD direct device access. -// -// --[ Description ] ---------------------------------------------------------- -// -// Contains enumerations necessary for directly interfacing devices under -// FreeBSD. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo -// ****************************************************************************/ - -using System; - -namespace Aaru.Devices.FreeBSD -{ - [Flags, Obsolete] - internal enum FileFlags - { - /// O_RDONLY - ReadOnly = 0x00000000, - /// O_WRONLY - WriteOnly = 0x00000001, - /// O_RDWR - ReadWrite = 0x00000002, - /// O_NONBLOCK - NonBlocking = 0x00000004, - /// O_APPEND - Append = 0x00000008, - /// O_SHLOCK - SharedLock = 0x00000010, - /// O_EXLOCK - ExclusiveLock = 0x00000020, - /// O_ASYNC - Async = 0x00000040, - /// O_FSYNC - SyncWrites = 0x00000080, - /// O_NOFOLLOW - NoFollowSymlink = 0x00000100, - /// O_CREAT - OpenOrCreate = 0x00000200, - /// O_TRUNC - Truncate = 0x00000400, - /// O_EXCL - CreateNew = 0x00000800, - /// O_NOCTTY - NoControlTty = 0x00008000, - /// O_DIRECT - Direct = 0x00010000, - /// O_DIRECTORY - Directory = 0x00020000, - /// O_EXEC - Execute = 0x00040000, - /// O_TTY_INIT - InitializeTty = 0x00080000, - /// O_CLOEXEC - CloseOnExec = 0x00100000 - } - - [Flags, Obsolete] - internal enum CamAtaIoFlags : byte - { - /// 48-bit command - ExtendedCommand = 0x01, - /// FPDMA command - Fpdma = 0x02, - /// Control, not a command - Control = 0x04, - /// Needs result - NeedResult = 0x08, - /// DMA command - Dma = 0x10 - } - - /// XPT Opcodes for xpt_action - [Flags, Obsolete] - internal enum XptOpcode - { - // Function code flags are bits greater than 0xff - - /// Non-immediate function code - XptFcQueued = 0x100, XptFcUserCcb = 0x200, - /// Only for the transport layer device - XptFcXptOnly = 0x400, - /// Passes through the device queues - XptFcDevQueued = 0x800 | XptFcQueued, - - // Common function commands: 0x00->0x0F - - /// Execute Nothing - XptNoop = 0x00, - /// Execute the requested I/O operation - XptScsiIo = 0x01 | XptFcDevQueued, - /// Get type information for specified device - XptGdevType = 0x02, - /// Get a list of peripheral devices - XptGdevlist = 0x03, - /// Path routing inquiry - XptPathInq = 0x04, - /// Release a frozen device queue - XptRelSimq = 0x05, - /// Set Asynchronous Callback Parameters - XptSasyncCb = 0x06, - /// Set device type information - XptSdevType = 0x07, - /// (Re)Scan the SCSI Bus - XptScanBus = 0x08 | XptFcQueued | XptFcUserCcb | XptFcXptOnly, - /// Get EDT entries matching the given pattern - XptDevMatch = 0x09 | XptFcXptOnly, - /// Turn on debugging for a bus, target or lun - XptDebug = 0x0a, - /// Path statistics (error counts, etc.) - XptPathStats = 0x0b, - /// Device statistics (error counts, etc.) - XptGdevStats = 0x0c, - /// Get/Set Device advanced information - XptDevAdvinfo = 0x0e, - /// Asynchronous event - XptAsync = 0x0f | XptFcQueued | XptFcUserCcb | XptFcXptOnly, - - /// SCSI Control Functions: 0x10->0x1F - /// Abort the specified CCB - XptAbort = 0x10, - /// Reset the specified SCSI bus - XptResetBus = 0x11 | XptFcXptOnly, - /// Bus Device Reset the specified SCSI device - XptResetDev = 0x12 | XptFcDevQueued, - /// Terminate the I/O process - XptTermIo = 0x13, - /// Scan Logical Unit - XptScanLun = 0x14 | XptFcQueued | XptFcUserCcb | XptFcXptOnly, - /// Get default/user transfer settings for the target - XptGetTranSettings = 0x15, - /// Set transfer rate/width negotiation settings - XptSetTranSettings = 0x16, - /// Calculate the geometry parameters for a device give the sector size and volume size. - XptCalcGeometry = 0x17, - /// Execute the requested ATA I/O operation - XptAtaIo = 0x18 | XptFcDevQueued, - - /// Compat only - XptGetSimKnobOld = 0x18, - - /// Set SIM specific knob values. - XptSetSimKnob = 0x19, - /// Get SIM specific knob values. - XptGetSimKnob = 0x1a, - /// Serial Management Protocol - XptSmpIo = 0x1b | XptFcDevQueued, - /// Scan Target - XptScanTgt = 0x1E | XptFcQueued | XptFcUserCcb | XptFcXptOnly, - - // HBA engine commands 0x20->0x2F - - /// HBA engine feature inquiry - XptEngInq = 0x20 | XptFcXptOnly, - /// HBA execute engine request - XptEngExec = 0x21 | XptFcDevQueued, - - // Target mode commands: 0x30->0x3F - - /// Enable LUN as a target - XptEnLun = 0x30, - /// Execute target I/O request - XptTargetIo = 0x31 | XptFcDevQueued, - /// Accept Host Target Mode CDB - XptAcceptTargetIo = 0x32 | XptFcQueued | XptFcUserCcb, - /// Continue Host Target I/O Connection - XptContTargetIo = 0x33 | XptFcDevQueued, - /// Notify Host Target driver of event (obsolete) - XptImmedNotify = 0x34 | XptFcQueued | XptFcUserCcb, - /// Acknowledgement of event (obsolete) - XptNotifyAck = 0x35, - /// Notify Host Target driver of event - XptImmediateNotify = 0x36 | XptFcQueued | XptFcUserCcb, - /// Acknowledgement of event - XptNotifyAcknowledge = 0x37 | XptFcQueued | XptFcUserCcb, - - /// Vendor Unique codes: 0x80->0x8F - XptVunique = 0x80 - } - - [Obsolete] - internal enum CcbDevMatchStatus - { - CamDevMatchLast, CamDevMatchMore, CamDevMatchListChanged, - CamDevMatchSizeError, CamDevMatchError - } - - [Obsolete] - internal enum DevMatchType - { - DevMatchPeriph = 0, DevMatchDevice, DevMatchBus - } - - [Flags, Obsolete] - internal enum PeriphPatternFlags - { - PeriphMatchNone = 0x000, PeriphMatchPath = 0x001, PeriphMatchTarget = 0x002, - PeriphMatchLun = 0x004, PeriphMatchName = 0x008, PeriphMatchUnit = 0x010 - - // PERIPH_MATCH_ANY = 0x01f - } - - [Flags, Obsolete] - internal enum DevPatternFlags - { - DevMatchNone = 0x000, DevMatchPath = 0x001, DevMatchTarget = 0x002, - DevMatchLun = 0x004, DevMatchInquiry = 0x008, DevMatchDevid = 0x010 - - // DEV_MATCH_ANY = 0x00f - } - - [Flags, Obsolete] - internal enum BusPatternFlags - { - BusMatchNone = 0x000, BusMatchPath = 0x001, BusMatchName = 0x002, - BusMatchUnit = 0x004, BusMatchBusId = 0x008 - - // BUS_MATCH_ANY = 0x00f - } - - [Flags, Obsolete] - internal enum DevResultFlags - { - DevResultNoflag = 0x00, DevResultUnconfigured = 0x01 - } - - [Obsolete] - internal enum CamProto - { - ProtoUnknown, ProtoUnspecified, - - /// Small Computer System Interface - ProtoScsi, - - /// AT Attachment - ProtoAta, - - /// AT Attachment Packetized Interface - ProtoAtapi, - - /// SATA Port Multiplier - ProtoSatapm, - - /// SATA Enclosure Management Bridge - ProtoSemb, - - /// NVMe - ProtoNvme, - - /// MMC, SD, SDIO - ProtoMmcsd - } - - [Flags, Obsolete] - internal enum MmcCardFeatures - { - CardFeatureMemory = 0x1, CardFeatureSdhc = 0x1 << 1, CardFeatureSdio = 0x1 << 2, - CardFeatureSd20 = 0x1 << 3, CardFeatureMmc = 0x1 << 4, CardFeature18V = 0x1 << 5 - } - - [Obsolete] - internal enum CamGenerations : uint - { - CamBusGeneration = 0x00, CamTargetGeneration = 0x01, CamDevGeneration = 0x02, - CamPeriphGeneration = 0x03 - } - - [Flags, Obsolete] - internal enum DevPosType - { - CamDevPosNone = 0x000, CamDevPosBus = 0x001, CamDevPosTarget = 0x002, - CamDevPosDevice = 0x004, CamDevPosPeriph = 0x008, CamDevPosPdptr = 0x010, - - // CAM_DEV_POS_TYPEMASK = 0xf00, - CamDevPosEdt = 0x100, CamDevPosPdrv = 0x200 - } - - [Obsolete] - internal enum FreebsdIoctl : uint - { - Camiocommand = 0xC4D81802 - } - - [Flags, Obsolete] - internal enum CcbFlags : uint - { - /// The CDB field is a pointer - CamCdbPointer = 0x00000001, - /// SIM queue actions are enabled - CamQueueEnable = 0x00000002, - /// CCB contains a linked CDB - CamCdbLinked = 0x00000004, - /// Perform transport negotiation with this command. - CamNegotiate = 0x00000008, - /// Data type with physical addrs - CamDataIsphys = 0x00000010, - /// Disable autosense feature - CamDisAutosense = 0x00000020, - /// Data direction (00:IN/OUT) - CamDirBoth = 0x00000000, - /// Data direction (01:DATA IN) - CamDirIn = 0x00000040, - /// Data direction (10:DATA OUT) - CamDirOut = 0x00000080, - /// Data direction (11:no data) - CamDirNone = 0x000000C0, - /// Data type (000:Virtual) - CamDataVaddr = 0x00000000, - /// Data type (001:Physical) - CamDataPaddr = 0x00000010, - /// Data type (010:sglist) - CamDataSg = 0x00040000, - /// Data type (011:sglist phys) - CamDataSgPaddr = 0x00040010, - /// Data type (100:bio) - CamDataBio = 0x00200000, - /// Use Soft reset alternative - CamSoftRstOp = 0x00000100, - /// Flush resid bytes on complete - CamEngSync = 0x00000200, - /// Disable DEV Q freezing - CamDevQfrzdis = 0x00000400, - /// Freeze DEV Q on execution - CamDevQfreeze = 0x00000800, - /// Command takes a lot of power - CamHighPower = 0x00001000, - /// Sense data is a pointer - CamSensePtr = 0x00002000, - /// Sense pointer is physical addr - CamSensePhys = 0x00004000, - /// Use the tag action in this ccb - CamTagActionValid = 0x00008000, - /// Pass driver does err. recovery - CamPassErrRecover = 0x00010000, - /// Disable disconnect - CamDisDisconnect = 0x00020000, - /// Message buffer ptr is physical - CamMsgBufPhys = 0x00080000, - /// Autosense data ptr is physical - CamSnsBufPhys = 0x00100000, - /// CDB poiner is physical - CamCdbPhys = 0x00400000, - /// SG list is for the HBA engine - CamEngSglist = 0x00800000, - - /* Phase cognizant mode flags */ - /// Disable autosave/restore ptrs - CamDisAutosrp = 0x01000000, - /// Disable auto disconnect - CamDisAutodisc = 0x02000000, - /// Target CCB available - CamTgtCcbAvail = 0x04000000, - /// The SIM runs in phase mode - CamTgtPhaseMode = 0x08000000, - /// Message buffer valid - CamMsgbValid = 0x10000000, - /// Status buffer valid - CamStatusValid = 0x20000000, - /// Data buffer valid - CamDatabValid = 0x40000000, - /* Host target Mode flags */ - /// Send sense data with status - CamSendSense = 0x08000000, - /// Terminate I/O Message sup. - CamTermIo = 0x10000000, - /// Disconnects are mandatory - CamDisconnect = 0x20000000, - /// Send status after data phase - CamSendStatus = 0x40000000, - /// Call callback without lock. - CamUnlocked = 0x80000000 - } - - [Obsolete] - internal enum CamStatus : uint - { - /// CCB request is in progress - CamReqInprog = 0x00, - - /// CCB request completed without error - CamReqCmp = 0x01, - - /// CCB request aborted by the host - CamReqAborted = 0x02, - - /// Unable to abort CCB request - CamUaAbort = 0x03, - - /// CCB request completed with an error - CamReqCmpErr = 0x04, - - /// CAM subsystem is busy - CamBusy = 0x05, - - /// CCB request was invalid - CamReqInvalid = 0x06, - - /// Supplied Path ID is invalid - CamPathInvalid = 0x07, - - /// SCSI Device Not Installed/there - CamDevNotThere = 0x08, - - /// Unable to terminate I/O CCB request - CamUaTermio = 0x09, - - /// Target Selection Timeout - CamSelTimeout = 0x0a, - - /// Command timeout - CamCmdTimeout = 0x0b, - - /// SCSI error, look at error code in CCB - CamScsiStatusError = 0x0c, - - /// Message Reject Received - CamMsgRejectRec = 0x0d, - - /// SCSI Bus Reset Sent/Received - CamScsiBusReset = 0x0e, - - /// Uncorrectable parity error occurred - CamUncorParity = 0x0f, - - /// Autosense: request sense cmd fail - CamAutosenseFail = 0x10, - - /// No HBA Detected error - CamNoHba = 0x11, - - /// Data Overrun error - CamDataRunErr = 0x12, - - /// Unexpected Bus Free - CamUnexpBusfree = 0x13, - - /// Target Bus Phase Sequence Failure - CamSequenceFail = 0x14, - - /// CCB length supplied is inadequate - CamCcbLenErr = 0x15, - - /// Unable to provide requested capability - CamProvideFail = 0x16, - - /// A SCSI BDR msg was sent to target - CamBdrSent = 0x17, - - /// CCB request terminated by the host - CamReqTermio = 0x18, - - /// Unrecoverable Host Bus Adapter Error - CamUnrecHbaError = 0x19, - - /// Request was too large for this host - CamReqTooBig = 0x1a, - - /// - /// This request should be requeued to preserve transaction ordering. This typically occurs when the SIM - /// recognizes an error that should freeze the queue and must place additional requests for the target at the sim level - /// back into the XPT queue. - /// - CamRequeueReq = 0x1b, - - /// ATA error, look at error code in CCB - CamAtaStatusError = 0x1c, - - /// Initiator/Target Nexus lost. - CamScsiItNexusLost = 0x1d, - - /// SMP error, look at error code in CCB - CamSmpStatusError = 0x1e, - - /// Command completed without error but exceeded the soft timeout threshold. - CamReqSofttimeout = 0x1f, - - /* - * 0x20 - 0x32 are unassigned - */ - - /// Initiator Detected Error - CamIde = 0x33, - - /// Resource Unavailable - CamResrcUnavail = 0x34, - - /// Unacknowledged Event by Host - CamUnackedEvent = 0x35, - - /// Message Received in Host Target Mode - CamMessageRecv = 0x36, - - /// Invalid CDB received in Host Target Mode - CamInvalidCdb = 0x37, - - /// Lun supplied is invalid - CamLunInvalid = 0x38, - - /// Target ID supplied is invalid - CamTidInvalid = 0x39, - - /// The requested function is not available - CamFuncNotavail = 0x3a, - - /// Nexus is not established - CamNoNexus = 0x3b, - - /// The initiator ID is invalid - CamIidInvalid = 0x3c, - - /// The SCSI CDB has been received - CamCdbRecvd = 0x3d, - - /// The LUN is already enabled for target mode - CamLunAlrdyEna = 0x3e, - - /// SCSI Bus Busy - CamScsiBusy = 0x3f, - - /* - * Flags - */ - - /// The DEV queue is frozen w/this err - CamDevQfrzn = 0x40, - - /// Autosense data valid for target - CamAutosnsValid = 0x80, - - /// SIM ready to take more commands - CamReleaseSimq = 0x100, - - /// SIM has this command in its queue - CamSimQueued = 0x200, - - /// Quality of service data is valid - CamQosValid = 0x400, - - /// Mask bits for just the status # - CamStatusMask = 0x3F, - - /* - * Target Specific Adjunct Status - */ - - /// sent sense with status - CamSentSense = 0x40000000 - } -} \ No newline at end of file diff --git a/Aaru.Devices/FreeBSD/Extern.cs b/Aaru.Devices/FreeBSD/Extern.cs deleted file mode 100644 index 88b65352b..000000000 --- a/Aaru.Devices/FreeBSD/Extern.cs +++ /dev/null @@ -1,66 +0,0 @@ -// /*************************************************************************** -// Aaru Data Preservation Suite -// ---------------------------------------------------------------------------- -// -// Filename : Extern.cs -// Author(s) : Natalia Portillo -// -// Component : FreeBSD direct device access. -// -// --[ Description ] ---------------------------------------------------------- -// -// Contains the P/Invoke definitions of FreeBSD syscalls used to directly -// interface devices. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Runtime.InteropServices; - -namespace Aaru.Devices.FreeBSD -{ - [Obsolete] - internal static class Extern - { - [DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern int open(string pathname, [MarshalAs(UnmanagedType.U4)] FileFlags flags); - - [DllImport("libc")] - internal static extern int close(int fd); - - [DllImport("libcam", CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern IntPtr cam_open_device(string path, [MarshalAs(UnmanagedType.U4)] FileFlags flags); - - [DllImport("libcam", CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern void cam_close_device(IntPtr dev); - - [DllImport("libcam", CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern IntPtr cam_getccb(IntPtr dev); - - [DllImport("libcam", CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern void cam_freeccb(IntPtr ccb); - - [DllImport("libcam", CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern int cam_send_ccb(IntPtr dev, IntPtr ccb); - - [DllImport("libc")] - internal static extern int ioctl(int fd, FreebsdIoctl request, IntPtr argp); - } -} \ No newline at end of file diff --git a/Aaru.Devices/FreeBSD/ListDevices.cs b/Aaru.Devices/FreeBSD/ListDevices.cs deleted file mode 100644 index e3b4e3994..000000000 --- a/Aaru.Devices/FreeBSD/ListDevices.cs +++ /dev/null @@ -1,169 +0,0 @@ -// /*************************************************************************** -// Aaru Data Preservation Suite -// ---------------------------------------------------------------------------- -// -// Filename : ListDevices.cs -// Author(s) : Natalia Portillo -// -// Component : FreeBSD direct device access. -// -// --[ Description ] ---------------------------------------------------------- -// -// Gets a list of known devices. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Aaru.CommonTypes.Structs.Devices.ATA; -using Aaru.CommonTypes.Structs.Devices.SCSI; -using Aaru.Helpers; -using static Aaru.Devices.FreeBSD.Extern; -using Marshal = System.Runtime.InteropServices.Marshal; - -namespace Aaru.Devices.FreeBSD -{ - [Obsolete] - internal static class ListDevices - { - /// Gets a list of all known storage devices on FreeBSD - /// List of devices - [Obsolete] - internal static DeviceInfo[] GetList() - { - string[] passDevices = Directory.GetFiles("/dev/", "pass*", SearchOption.TopDirectoryOnly); - List listDevices = new List(); - - foreach(string passDevice in passDevices) - { - var deviceInfo = new DeviceInfo(); - IntPtr dev = cam_open_device(passDevice, FileFlags.ReadWrite); - var camDevice = (CamDevice)Marshal.PtrToStructure(dev, typeof(CamDevice)); - - IntPtr ccbPtr = cam_getccb(dev); - - if(ccbPtr.ToInt64() == 0) - continue; - - var cgd = (CcbGetdev)Marshal.PtrToStructure(ccbPtr, typeof(CcbGetdev)); - - cgd.ccb_h.func_code = XptOpcode.XptGdevType; - - Marshal.StructureToPtr(cgd, ccbPtr, false); - - int error = cam_send_ccb(dev, ccbPtr); - - if(error < 0) - { - cam_freeccb(ccbPtr); - - continue; - } - - cgd = (CcbGetdev)Marshal.PtrToStructure(ccbPtr, typeof(CcbGetdev)); - - cam_freeccb(ccbPtr); - cam_close_device(dev); - - string simName = StringHandlers.CToString(camDevice.SimName); - deviceInfo.Path = passDevice; - byte[] serialNumber = new byte[camDevice.SerialNumLen]; - Array.Copy(camDevice.SerialNum, 0, serialNumber, 0, serialNumber.Length); - deviceInfo.Serial = StringHandlers.CToString(serialNumber); - - switch(cgd.protocol) - { - case CamProto.ProtoAta: - case CamProto.ProtoAtapi: - case CamProto.ProtoSatapm: - { - // Little-endian FreeBSD gives it resorted - // Big-endian FreeBSD, no idea - byte[] atadTneid = new byte[512]; - - for(int aIndex = 0; aIndex < 512; aIndex += 2) - { - atadTneid[aIndex] = cgd.ident_data[aIndex + 1]; - atadTneid[aIndex + 1] = cgd.ident_data[aIndex]; - } - - Identify.IdentifyDevice? idt = Identify.Decode(atadTneid); - - if(idt.HasValue) - { - string[] separated = idt.Value.Model.Split(' '); - - if(separated.Length == 1) - { - deviceInfo.Vendor = "ATA"; - deviceInfo.Model = separated[0]; - } - else - { - deviceInfo.Vendor = separated[0]; - deviceInfo.Model = separated[^1]; - } - - deviceInfo.Serial = idt.Value.SerialNumber; - deviceInfo.Bus = simName == "ahcich" ? "SATA" : "ATA"; - deviceInfo.Supported = simName != "ata"; - } - - if(cgd.protocol == CamProto.ProtoAtapi) - goto case CamProto.ProtoScsi; - - break; - } - case CamProto.ProtoScsi: - { - Inquiry? inq = Inquiry.Decode(cgd.inq_data); - - if(inq.HasValue) - { - deviceInfo.Vendor = StringHandlers.CToString(inq.Value.VendorIdentification).Trim(); - deviceInfo.Model = StringHandlers.CToString(inq.Value.ProductIdentification).Trim(); - deviceInfo.Bus = simName == "ata" || simName == "ahcich" ? "ATAPI" : "SCSI"; - deviceInfo.Supported = simName != "ata"; - } - - break; - } - case CamProto.ProtoNvme: - deviceInfo.Bus = "NVMe"; - deviceInfo.Supported = false; - - break; - case CamProto.ProtoMmcsd: - deviceInfo.Model = "Unknown card"; - deviceInfo.Bus = "MMC/SD"; - deviceInfo.Supported = false; - - break; - } - - listDevices.Add(deviceInfo); - } - - return listDevices.Count > 0 ? listDevices.OrderBy(t => t.Path).ToArray() : null; - } - } -} \ No newline at end of file diff --git a/Aaru.Devices/FreeBSD/Structs.cs b/Aaru.Devices/FreeBSD/Structs.cs deleted file mode 100644 index 337e17be8..000000000 --- a/Aaru.Devices/FreeBSD/Structs.cs +++ /dev/null @@ -1,711 +0,0 @@ -// /*************************************************************************** -// Aaru Data Preservation Suite -// ---------------------------------------------------------------------------- -// -// Filename : Structs.cs -// Author(s) : Natalia Portillo -// -// Component : FreeBSD direct device access. -// -// --[ Description ] ---------------------------------------------------------- -// -// Contains structures necessary for directly interfacing devices under -// FreeBSD. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; -using lun_id_t = System.UInt32; -using path_id_t = System.UInt32; -using target_id_t = System.UInt32; - -// ReSharper disable BuiltInTypeReferenceStyle - -#pragma warning disable 649 -#pragma warning disable 169 - -namespace Aaru.Devices.FreeBSD -{ - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct AtaCmd - { - public CamAtaIoFlags flags; - public byte command; - public byte features; - public byte lba_low; - public byte lba_mid; - public byte lba_high; - public byte device; - public byte lba_low_exp; - public byte lba_mid_exp; - public byte lba_high_exp; - public byte features_exp; - public byte sector_count; - public byte sector_count_exp; - public byte control; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct AtaRes - { - public CamAtaIoFlags flags; - public byte status; - public byte error; - public byte lba_low; - public byte lba_mid; - public byte lba_high; - public byte device; - public byte lba_low_exp; - public byte lba_mid_exp; - public byte lba_high_exp; - public byte sector_count; - public byte sector_count_exp; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct CamPinfo - { - public uint priority; - public uint generation; - public int index; - } - - [SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct ListEntry - { - /// LIST_ENTRY(ccb_hdr)=le->*le_next - public IntPtr LeNext; - /// LIST_ENTRY(ccb_hdr)=le->**le_prev - public IntPtr LePrev; - } - - [SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct SlistEntry - { - /// SLIST_ENTRY(ccb_hdr)=sle->*sle_next - public IntPtr SleNext; - } - - [SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct TailqEntry - { - /// TAILQ_ENTRY(ccb_hdr)=tqe->*tqe_next - public IntPtr TqeNext; - /// TAILQ_ENTRY(ccb_hdr)=tqe->**tqe_prev - public IntPtr TqePrev; - } - - [SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct StailqEntry - { - /// STAILQ_ENTRY(ccb_hdr)=stqe->*stqe_next - public IntPtr StqeNext; - } - - [StructLayout(LayoutKind.Explicit), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct CamqEntry - { - [FieldOffset(0)] - public ListEntry le; - [FieldOffset(0)] - public SlistEntry sle; - [FieldOffset(0)] - public TailqEntry tqe; - [FieldOffset(0)] - public StailqEntry stqe; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct Timeval - { - public long tv_sec; - /// long - public IntPtr tv_usec; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct CcbQosArea - { - public Timeval etime; - public UIntPtr sim_data; - public UIntPtr periph_data; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct CcbHdr - { - public CamPinfo pinfo; - public CamqEntry xpt_links; - public CamqEntry sim_links; - public CamqEntry periph_links; - public uint retry_count; - public IntPtr cbfcnp; - public XptOpcode func_code; - public CamStatus status; - public IntPtr path; - public uint path_id; - public uint target_id; - public ulong target_lun; - public CcbFlags flags; - public uint xflags; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] - public IntPtr[] periph_priv; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] - public IntPtr[] sim_priv; - public CcbQosArea qos; - public uint timeout; - public Timeval softtimeout; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct ScsiSenseData - { - const int SSD_FULL_SIZE = 252; - public byte error_code; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = SSD_FULL_SIZE - 1)] - public byte[] sense_buf; - } - - /// SCSI I/O Request CCB used for the XPT_SCSI_IO and XPT_CONT_TARGET_IO function codes. - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct CcbScsiio - { - public CcbHdr ccb_h; - /// Ptr for next CCB for action - public IntPtr next_ccb; - /// Ptr to mapping info - public IntPtr req_map; - /// Ptr to the data buf/SG list - public IntPtr data_ptr; - /// Data transfer length - public uint dxfer_len; - /// Autosense storage - public ScsiSenseData sense_data; - /// Number of bytes to autosense - public byte sense_len; - /// Number of bytes for the CDB - public byte cdb_len; - /// Number of SG list entries - public short sglist_cnt; - /// Returned SCSI status - public byte scsi_status; - /// Autosense resid length: 2's comp - public sbyte sense_resid; - /// Transfer residual length: 2's comp - public int resid; - /// Area for the CDB send, or pointer to the CDB bytes to send - const int IOCDBLEN = 16; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = IOCDBLEN)] - public byte[] cdb_bytes; - /// Pointer to the message buffer - public IntPtr msg_ptr; - /// Number of bytes for the Message - public short msg_len; - /// - /// What to do for tag queueing. The tag action should be either the define below (to send a non-tagged - /// transaction) or one of the defined scsi tag messages from scsi_message.h. - /// - public byte tag_action; - /// tag id from initator (target mode) - public uint tag_id; - /// initiator id of who selected - public uint init_id; - } - - /// SCSI I/O Request CCB used for the XPT_SCSI_IO and XPT_CONT_TARGET_IO function codes. - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct CcbScsiio64 - { - public CcbHdr ccb_h; - /// Ptr for next CCB for action - public IntPtr next_ccb; - /// Ptr to mapping info - public IntPtr req_map; - /// Ptr to the data buf/SG list - public IntPtr data_ptr; - /// Data transfer length - public uint dxfer_len; - /// Autosense storage - public ScsiSenseData sense_data; - /// Number of bytes to autosense - public byte sense_len; - /// Number of bytes for the CDB - public byte cdb_len; - /// Number of SG list entries - public short sglist_cnt; - /// Returned SCSI status - public byte scsi_status; - /// Autosense resid length: 2's comp - public sbyte sense_resid; - /// Transfer residual length: 2's comp - public int resid; - public uint alignment; - /// Area for the CDB send, or pointer to the CDB bytes to send - const int IOCDBLEN = 16; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = IOCDBLEN)] - public byte[] cdb_bytes; - /// Pointer to the message buffer - public IntPtr msg_ptr; - /// Number of bytes for the Message - public short msg_len; - /// - /// What to do for tag queueing. The tag action should be either the define below (to send a non-tagged - /// transaction) or one of the defined scsi tag messages from scsi_message.h. - /// - public byte tag_action; - /// tag id from initator (target mode) - public uint tag_id; - /// initiator id of who selected - public uint init_id; - } - - /// ATA I/O Request CCB used for the XPT_ATA_IO function code. - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct CcbAtaio - { - public CcbHdr ccb_h; - /// Ptr for next CCB for action - public IntPtr next_ccb; - /// ATA command register set - public AtaCmd cmd; - /// ATA result register set - public AtaRes res; - /// Ptr to the data buf/SG list - public IntPtr data_ptr; - /// Data transfer length - public uint dxfer_len; - /// Transfer residual length: 2's comp - public int resid; - /// Flags for the rest of the buffer - public byte ata_flags; - public uint aux; - public uint unused; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct NvmeCommand - { - readonly ushort opc_fuse_rsvd1; - /// command identifier - public ushort cid; - /// namespace identifier - public uint nsid; - /// reserved - public uint rsvd2; - /// reserved - public uint rsvd3; - /// metadata pointer - public ulong mptr; - /// prp entry 1 - public ulong prp1; - /// prp entry 2 - public ulong prp2; - /// command-specific - public uint cdw10; - /// command-specific - public uint cdw11; - /// command-specific - public uint cdw12; - /// command-specific - public uint cdw13; - /// command-specific - public uint cdw14; - /// command-specific - public uint cdw15; - - /// opcode - public byte Opc => (byte)((opc_fuse_rsvd1 & 0xFF00) >> 8); - /// fused operation - public byte Fuse => (byte)((opc_fuse_rsvd1 & 0xC0) >> 6); - /// reserved - public byte Rsvd1 => (byte)(opc_fuse_rsvd1 & 0x3F); - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct NvmeStatus - { - readonly ushort status; - - /// phase tag - public byte P => (byte)((status & 0x8000) >> 15); - - /// status code - public byte Sc => (byte)((status & 0x7F80) >> 7); - - /// status code type - public byte Sct => (byte)((status & 0x70) >> 4); - - /// reserved - public byte Rsvd2 => (byte)((status & 0xC) >> 15); - - /// more - public byte M => (byte)((status & 0x2) >> 1); - - /// do not retry - public byte Dnr => (byte)(status & 0x1); - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct NvmeCompletion - { - /// command-specific - public uint cdw0; - - /// reserved - public uint rsvd1; - - /// submission queue head pointer - public ushort sqhd; - - /// submission queue identifier - public ushort sqid; - - /// command identifier - public ushort cid; - - public NvmeStatus status; - } - - /// NVMe I/O Request CCB used for the XPT_NVME_IO and XPT_NVME_ADMIN function codes. - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct CcbNvmeio - { - public CcbHdr ccb_h; - /// Ptr for next CCB for action - public IntPtr next_ccb; - /// NVME command, per NVME standard - public NvmeCommand cmd; - /// NVME completion, per NVME standard - public NvmeCompletion cpl; - /// Ptr to the data buf/SG list - public IntPtr data_ptr; - /// Data transfer length - public uint dxfer_len; - /// Number of SG list entries - public ushort sglist_cnt; - /// padding for removed uint32_t - public ushort unused; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct PeriphMatchPattern - { - const int DEV_IDLEN = 16; - - [MarshalAs(UnmanagedType.ByValArray, SizeConst = DEV_IDLEN)] - public byte[] periph_name; - public uint unit_number; - public path_id_t path_id; - public target_id_t target_id; - public lun_id_t target_lun; - public PeriphPatternFlags flags; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct DeviceIdMatchPattern - { - public byte id_len; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] - public byte[] id; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct ScsiStaticInquiryPattern - { - const int SID_VENDOR_SIZE = 8; - const int SID_PRODUCT_SIZE = 16; - const int SID_REVISION_SIZE = 4; - public byte type; - public byte media_type; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = SID_VENDOR_SIZE + 1)] - public byte[] vendor; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = SID_PRODUCT_SIZE + 1)] - public byte[] product; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = SID_REVISION_SIZE + 1)] - public byte[] revision; - } - - [StructLayout(LayoutKind.Explicit), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct DeviceMatchPatternData - { - [FieldOffset(0)] - public ScsiStaticInquiryPattern inq_pat; - [FieldOffset(0)] - public DeviceIdMatchPattern devid_pat; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct DeviceMatchPattern - { - public uint path_id; - public uint target_id; - public uint target_lun; - public DevPatternFlags flags; - public DeviceMatchPatternData data; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct BusMatchPattern - { - const int DEV_IDLEN = 16; - - public path_id_t path_id; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = DEV_IDLEN)] - public byte[] dev_name; - public uint unit_number; - public uint bus_id; - readonly BusPatternFlags flags; - } - - [StructLayout(LayoutKind.Explicit), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct MatchPattern - { - [FieldOffset(0)] - public PeriphMatchPattern periph_pattern; - [FieldOffset(0)] - public DeviceMatchPattern device_pattern; - [FieldOffset(0)] - public BusMatchPattern bus_pattern; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct DevMatchPattern - { - public DevMatchType type; - public MatchPattern pattern; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct PeriphMatchResult - { - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] - public byte[] periph_name; - public uint unit_number; - public path_id_t path_id; - public target_id_t target_id; - public lun_id_t target_lun; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct MmcCid - { - public uint mid; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] - public byte[] pnm; - public uint psn; - public ushort oid; - public ushort mdt_year; - public byte mdt_month; - public byte prv; - public byte fwrev; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct MmcParams - { - /// Card model - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 40)] - public byte[] model; - - /// Card OCR - public uint card_ocr; - - /// OCR of the IO portion of the card - public uint io_ocr; - - /// Card CID -- raw - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] - public uint[] card_cid; - - /// Card CID -- parsed - public MmcCid cid; - - /// Card CSD -- raw - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] - public uint[] card_csd; - - /// Card RCA - public ushort card_rca; - - /// What kind of card is it - public MmcCardFeatures card_features; - - public byte sdio_func_count; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct DeviceMatchResult - { - public path_id_t path_id; - public target_id_t target_id; - public lun_id_t target_lun; - public CamProto protocol; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] - public byte[] inq_data; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)] - public byte[] ident_data; - public DevResultFlags flags; - public MmcParams mmc_ident_data; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct BusMatchResult - { - public path_id_t path_id; - const int DEV_IDLEN = 16; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = DEV_IDLEN)] - public byte[] dev_name; - public uint unit_number; - public uint bus_id; - } - - [StructLayout(LayoutKind.Explicit), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct MatchResult - { - [FieldOffset(0)] - public PeriphMatchResult periph_result; - [FieldOffset(0)] - public DeviceMatchResult device_result; - [FieldOffset(0)] - public BusMatchResult bus_result; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct DevMatchResult - { - public DevMatchType type; - public MatchResult result; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct CcbDmCookie - { - public IntPtr bus; - public IntPtr target; - public IntPtr device; - public IntPtr periph; - public IntPtr pdrv; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct CcbDevPosition - { - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] - public CamGenerations[] generations; - readonly DevPosType position_type; - public CcbDmCookie cookie; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct CcbDevMatch - { - public CcbHdr ccb_h; - readonly CcbDevMatchStatus status; - public uint num_patterns; - public uint pattern_buf_len; - - /// dev_match_pattern* - public IntPtr patterns; - - public uint num_matches; - public uint match_buf_len; - - /// dev_match_result* - public IntPtr matches; - - public CcbDevPosition pos; - } - - [SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct CamDevice - { - const int MAXPATHLEN = 1024; - const int DEV_IDLEN = 16; - const int SIM_IDLEN = 16; - /// - /// Pathname of the device given by the user. This may be null if the user states the device name and unit number - /// separately. - /// - [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAXPATHLEN)] - public byte[] DevicePath; - /// Device name given by the user. - [MarshalAs(UnmanagedType.ByValArray, SizeConst = DEV_IDLEN + 1)] - public byte[] GivenDevName; - /// Unit number given by the user. - public uint GivenUnitNumber; - /// Name of the device, e.g. 'pass' - [MarshalAs(UnmanagedType.ByValArray, SizeConst = DEV_IDLEN + 1)] - public byte[] DeviceName; - /// Unit number of the passthrough device associated with this particular device. - public uint DevUnitNum; - /// Controller name, e.g. 'ahc' - [MarshalAs(UnmanagedType.ByValArray, SizeConst = SIM_IDLEN + 1)] - public byte[] SimName; - /// Controller unit number - public uint SimUnitNumber; - /// Controller bus number - public uint BusId; - /// Logical Unit Number - public lun_id_t TargetLun; - /// Target ID - public target_id_t TargetId; - /// System SCSI bus number - public path_id_t PathId; - /// type of peripheral device - public ushort PdType; - /// SCSI Inquiry data - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] - public byte[] InqData; - /// device serial number - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 252)] - public byte[] SerialNum; - /// length of the serial number - public byte SerialNumLen; - /// Negotiated sync period - public byte SyncPeriod; - /// Negotiated sync offset - public byte SyncOffset; - /// Negotiated bus width - public byte BusWidth; - /// file descriptor for device - public int Fd; - } - - [StructLayout(LayoutKind.Sequential), SuppressMessage("ReSharper", "MemberCanBePrivate.Global"), Obsolete] - internal struct CcbGetdev - { - public CcbHdr ccb_h; - public CamProto protocol; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] - public byte[] inq_data; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)] - public byte[] ident_data; - /// device serial number - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 252)] - public byte[] serial_num; - public byte inq_flags; - /// length of the serial number - public byte serial_num_len; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] - public IntPtr[] padding; - } -} \ No newline at end of file diff --git a/Aaru.Gui/ViewModels/Dialogs/AboutViewModel.cs b/Aaru.Gui/ViewModels/Dialogs/AboutViewModel.cs index 4516efa53..4b6560822 100644 --- a/Aaru.Gui/ViewModels/Dialogs/AboutViewModel.cs +++ b/Aaru.Gui/ViewModels/Dialogs/AboutViewModel.cs @@ -153,15 +153,10 @@ Logo and art: process.StartInfo.FileName = "cmd"; process.StartInfo.Arguments = $"/c start {process.StartInfo.Arguments.Replace("&", "^&")}"; } - else if(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD) || - RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { + else if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) process.StartInfo.FileName = "xdg-open"; - } else if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { process.StartInfo.FileName = "open"; - } else return; diff --git a/README.md b/README.md index 72d49ec29..c2edebe93 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Stable releases in [Github](https://github.com/aaru-dps/Aaru/releases). System requirements =================== -Aaru is created using .NET 6 and can be compiled with all the major IDEs. To run it you require to use one of the -stable releases, or build it yourself. +Aaru is created using .NET 6 and can be compiled with all the major IDEs. To run it you require to use one of the stable +releases, or build it yourself. Usage ===== @@ -59,8 +59,7 @@ Features * Can create standard open XML metadata from existing images. * Can measure readability and speed of media (same that can be dumped, MHDD style) * Has an online database with drive capabilities, and can report the capabilities of any drive. -* Works on any operating system and architecture where .NET Core is supported (drive access requires Windows, Linux or - FreeBSD). +* Works on any operating system and architecture where .NET Core is supported (drive access requires Windows or Linux). * Has a graphical interface (work in progress) Supported disk image formats (read-only)