/// <summary> /// IOCTL_ATA_PASS_THROUGH IOCTL ( https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ntddscsi/ni-ntddscsi-ioctl_ata_pass_through ) /// </summary> /// <param name="IoControl"></param> /// <param name="Header"></param> /// <param name="Data"></param> /// <returns></returns> public static bool AtaPassThroughSmartData(this IoControl IoControl, out IAtaPassThroughEx <SmartData> value, out uint ReturnBytes) { if (IntPtr.Size == 4) { var request = new AtaPassThroughEx32WithSmartData( AtaFlags: AtaFlags.DataIn | AtaFlags.NoMultiple, TimeOutValue: 3, Feature: 0xd0, Cylinder: 0xc24f, Command: 0xb0 ); System.Diagnostics.Debug.Assert(request.DataTransferLength == 512, "データが不正"); var ptr = new StructPtr <AtaPassThroughEx32WithSmartData>(request); var result = IoControl.AtaPassThrough(ptr, out ReturnBytes); value = ptr.Get(); return(result); } else if (IntPtr.Size == 8) { var request = new AtaPassThroughExWithSmartData( AtaFlags: AtaFlags.DataIn | AtaFlags.NoMultiple, TimeOutValue: 3, Feature: 0xd0, Cylinder: 0xc24f, Command: 0xb0 ); System.Diagnostics.Debug.Assert(request.DataTransferLength == 512, "データが不正"); var ptr = new StructPtr <AtaPassThroughExWithSmartData>(request); var result = IoControl.AtaPassThrough(ptr, out ReturnBytes); value = ptr.Get(); return(result); } throw new NotSupportedException(); }
/// <summary> /// IOCTL_ATA_PASS_THROUGH IOCTL ( https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ntddscsi/ni-ntddscsi-ioctl_ata_pass_through ) /// </summary> /// <param name="IoControl"></param> /// <param name="Header"></param> /// <param name="Data"></param> /// <returns></returns> public static bool AtaPassThroughIdentifyDevice(this IoControl IoControl, out IAtaPassThroughEx <IdentifyDevice> value, out uint ReturnBytes) { if (IntPtr.Size == 4) { var ptr = new StructPtr <AtaPassThroughEx32WithIdentifyDevice>(new AtaPassThroughEx32WithIdentifyDevice( AtaFlags: AtaFlags.DataIn | AtaFlags.NoMultiple, TimeOutValue: 3, Feature: 0, Cylinder: 0, Command: 0xEC )); var result = IoControl.AtaPassThrough(ptr, out ReturnBytes); value = ptr.Get(); return(result); } else if (IntPtr.Size == 8) { var ptr = new StructPtr <AtaPassThroughExWithIdentifyDevice>(new AtaPassThroughExWithIdentifyDevice( AtaFlags: AtaFlags.DataIn | AtaFlags.NoMultiple, TimeOutValue: 3, Feature: 0, Cylinder: 0, Command: 0xEC )); var result = IoControl.AtaPassThrough(ptr, out ReturnBytes); value = ptr.Get(); return(result); } throw new NotSupportedException(); }
public static bool AtaPassThroughCheckPowerMode(this IoControl IoControl, out IAtaPassThroughEx value, out uint ReturnBytes) { var AtaFlags = Controller.AtaFlags.DataIn | Controller.AtaFlags.NoMultiple; if (IntPtr.Size == 4) { var _value = new AtaPassThroughEx32WithMiniBuffer( AtaFlags: AtaFlags, TimeOutValue: 20, TaskFile: new TaskFile( AtaFlags: AtaFlags, Feature: 0, Cylinder: 0, DeviceHead: 0, Command: 0xE5 ) ); var ptr = new StructPtr <AtaPassThroughEx32WithMiniBuffer>(_value); var result = IoControl.AtaPassThrough(ptr, out ReturnBytes); value = ptr.Get(); return(result); } else if (IntPtr.Size == 8) { var _value = new AtaPassThroughExWithMiniBuffer( AtaFlags: AtaFlags, TimeOutValue: 20, TaskFile: new TaskFile( AtaFlags: AtaFlags, Feature: 0, Cylinder: 0, DeviceHead: 0x0, Command: 0xE5 ) ); var ptr = new StructPtr <AtaPassThroughExWithMiniBuffer>(_value); var result = IoControl.AtaPassThrough(ptr, out ReturnBytes); value = ptr.Get(); return(result); } throw new NotSupportedException(); }
/// <summary> /// IOCTL_ATA_PASS_THROUGH_DIRECT IOCTL ( https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ntddscsi/ni-ntddscsi-ioctl_ata_pass_through_direct ) /// </summary> /// <param name="IoControl"></param> /// <param name="Header"></param> /// <param name="AtaFlags"></param> /// <param name="PathId"></param> /// <param name="TargetId"></param> /// <param name="Lun"></param> /// <param name="ReservedAsUchar"></param> /// <param name="TimeOutValue"></param> /// <param name="ReservedAsUlong"></param> /// <param name="DataTransferLength"></param> /// <param name="DataBuffer"></param> /// <param name="Feature"></param> /// <param name="SectorCouont"></param> /// <param name="SectorNumber"></param> /// <param name="Cylinder"></param> /// <param name="DeviceHead"></param> /// <param name="Command"></param> /// <param name="Reserved"></param> /// <returns></returns> public static bool AtaPassThroughDirect(this IoControl IoControl, out AtaPassThroughDirect Header, AtaFlags AtaFlags = default, byte PathId = default, byte TargetId = default, byte Lun = default, byte ReservedAsUchar = default, uint TimeOutValue = default, uint ReservedAsUlong = default, uint DataTransferLength = default, IntPtr DataBuffer = default, ushort Feature = default, ushort SectorCouont = default, ushort SectorNumber = default, uint Cylinder = default, byte DeviceHead = default, byte Command = default, ushort Reserved = default) { Header = new AtaPassThroughDirect( AtaFlags: AtaFlags, PathId: PathId, TargetId: TargetId, Lun: Lun, ReservedAsUchar: ReservedAsUchar, TimeOutValue: TimeOutValue, ReservedAsUlong: ReservedAsUlong, Feature: Feature, SectorCouont: SectorCouont, SectorNumber: SectorNumber, Cylinder: Cylinder, DeviceHead: DeviceHead, Command: Command, Reserved: Reserved, DataTransferLength: DataTransferLength, DataBuffer: DataBuffer ); return(IoControl.DeviceIoControl(IOControlCode.AtaPassThroughDirect, ref Header, out var _)); }
/// <summary> /// IOCTL_ATA_PASS_THROUGH IOCTL ( https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ntddscsi/ni-ntddscsi-ioctl_ata_pass_through ) /// </summary> /// <param name="IoControl"></param> /// <param name="Header"></param> /// <param name="Data"></param> /// <param name="AtaFlags"></param> /// <param name="PathId"></param> /// <param name="TargetId"></param> /// <param name="Lun"></param> /// <param name="ReservedAsUchar"></param> /// <param name="TimeOutValue"></param> /// <param name="ReservedAsUlong"></param> /// <param name="Feature"></param> /// <param name="SectorCouont"></param> /// <param name="SectorNumber"></param> /// <param name="Cylinder"></param> /// <param name="DeviceHead"></param> /// <param name="Command"></param> /// <param name="Reserved"></param> /// <param name="DataSize"></param> /// <returns></returns> public static bool AtaPassThrough(this IoControl IoControl, out IAtaPassThroughEx Header, out byte[] Data, AtaFlags AtaFlags, byte PathId = default, byte TargetId = default, byte Lun = default, byte ReservedAsUchar = default, uint TimeOutValue = default, uint ReservedAsUlong = default, ushort Feature = default, ushort SectorCouont = default, ushort SectorNumber = default, uint Cylinder = default, byte DeviceHead = default, byte Command = default, ushort Reserved = default, uint DataSize = default) { var _Size = Marshal.SizeOf <AtaPassThroughEx>(); var DataTransferLength = DataSize; var DataBufferOffset = DataSize == 0 ? 0 : _Size; Header = IntPtr.Size == 8 ? (IAtaPassThroughEx) new AtaPassThroughEx( AtaFlags: AtaFlags, PathId: PathId, TargetId: TargetId, Lun: Lun, ReservedAsUchar: ReservedAsUchar, TimeOutValue: TimeOutValue, ReservedAsUlong: ReservedAsUlong, Feature: Feature, SectorCouont: SectorCouont, SectorNumber: SectorNumber, Cylinder: Cylinder, DeviceHead: DeviceHead, Command: Command, Reserved: Reserved, DataTransferLength: DataTransferLength, DataBufferOffset: DataBufferOffset ): IntPtr.Size == 4 ? new AtaPassThroughEx32( AtaFlags: AtaFlags, PathId: PathId, TargetId: TargetId, Lun: Lun, ReservedAsUchar: ReservedAsUchar, TimeOutValue: TimeOutValue, ReservedAsUlong: ReservedAsUlong, Feature: Feature, SectorCouont: SectorCouont, SectorNumber: SectorNumber, Cylinder: Cylinder, DeviceHead: DeviceHead, Command: Command, Reserved: Reserved, DataTransferLength: DataTransferLength, DataBufferOffset: DataBufferOffset ): throw new NotSupportedException(); var Size = (uint)(_Size + DataSize); var Ptr = Marshal.AllocCoTaskMem((int)Size); using (Disposable.Create(() => Marshal.FreeCoTaskMem(Ptr))) { Marshal.StructureToPtr(Header, Ptr, false); var result = IoControl.DeviceIoControl(IOControlCode.AtaPassThrough, Ptr, Size, out var _); Header = result ? (AtaPassThroughEx)Marshal.PtrToStructure(Ptr, typeof(AtaPassThroughEx)) : default; if (DataSize > 0) { Data = new byte[DataSize]; Marshal.Copy(IntPtr.Add(Ptr, _Size), Data, 0, Data.Length); } else { Data = default; } return(result); } }