/// <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(); }
public void PhysicalDriveOpenTest(IoControl IoControl) { try { Trace.WriteLine(nameof(MassStorageExtensions.StorageGetDeviceNumber)); var number = IoControl.StorageGetDeviceNumber(); Trace.WriteLine(number); } catch (Exception e2) { Trace.WriteLine(e2); } try { Trace.WriteLine(nameof(DiskExtensions.DiskGetDriveGeometryEx)); var geometry = IoControl.DiskGetDriveGeometryEx(); Trace.WriteLine(geometry); } catch (Exception e2) { Trace.WriteLine(e2); } try { Trace.WriteLine(nameof(DiskExtensions.DiskGetLengthInfo)); var disksize = IoControl.DiskGetLengthInfo(); Trace.WriteLine(disksize); } catch (Exception e2) { Trace.WriteLine(e2); } try { Trace.WriteLine(nameof(DiskExtensions.DiskGetDriveLayoutEx)); var layout = IoControl.DiskGetDriveLayoutEx(); Trace.WriteLine(layout); }catch (Exception e) { Trace.WriteLine(e); } try { Trace.WriteLine(nameof(IOControlCode.StorageQueryProperty)); var dest = IoControl.StorageQueryProperty(StoragePropertyId.StorageDeviceSeekPenaltyProperty, default); Trace.WriteLine(dest); } catch (Exception e2) { Trace.WriteLine(e2); } try { Trace.WriteLine(nameof(ControllerExtentions.AtaPassThroughIdentifyDevice)); Trace.WriteLine(IoControl.AtaPassThroughIdentifyDevice()); } catch (Exception e2) { Trace.WriteLine(e2); } try { Trace.WriteLine(nameof(ControllerExtentions.AtaPassThroughSmartData)); var result = IoControl.AtaPassThroughSmartData(); Trace.WriteLine(result.Header); Trace.WriteLine(result.Data); } catch (Exception e2) { Trace.WriteLine(e2); } try { Trace.WriteLine(nameof(IOControlCode.AtaPassThrough) + " :STANDBY IMMEDIATE"); var Length = (ushort)Marshal.SizeOf(typeof(AtaPassThroughEx)); var id_query = IoControl.AtaPassThrough( AtaFlags: AtaFlags.DataIn | AtaFlags.NoMultiple, Command: 0xE0, DataSize: 512 ); Trace.WriteLine(id_query.Header); } catch (Exception e2) { Trace.WriteLine(e2); } try { Trace.WriteLine(nameof(IOControlCode.AtaPassThrough) + " :CHECK POWER MODE"); var Length = (ushort)Marshal.SizeOf(typeof(AtaPassThroughEx)); IoControl.AtaPassThrough( out var Header, out var Data, AtaFlags: AtaFlags.DataIn | AtaFlags.NoMultiple, TimeOutValue: 3, Command: 0xE5, DataSize: 512 ); Trace.WriteLine(Header); Trace.WriteLine(Data); } catch (Exception e2) { Trace.WriteLine(e2); } try { Trace.WriteLine(nameof(DiskExtensions.DiskPerformance)); IoControl.DiskPerformance(out var performance); Trace.WriteLine(performance); } catch (Exception e2) { Trace.WriteLine(e2); } try { Trace.WriteLine(nameof(IOControlCode.ScsiGetAddress)); var result = IoControl.DeviceIoControlOutOnly(IOControlCode.ScsiGetAddress, out ScsiAddress address, out var _); if (!result) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } Trace.WriteLine(address); } catch (Exception e2) { Trace.WriteLine(e2); } try { Trace.WriteLine(nameof(IOControlCode.ScsiGetInquiryData)); var Size = (uint)(Marshal.SizeOf(typeof(_ScsiAdapterBusInfo)) + Marshal.SizeOf(typeof(ScsiBusData)) + Marshal.SizeOf(typeof(ScsiInquiryData))); var OutPtr = Marshal.AllocCoTaskMem((int)Size); using (Disposable.Create(() => Marshal.FreeCoTaskMem(OutPtr))) { var result = IoControl.DeviceIoControlOutOnly(IOControlCode.ScsiGetInquiryData, OutPtr, Size, out var returnBytes); var lasterror = Marshal.GetHRForLastWin32Error(); if (!result) { Marshal.ThrowExceptionForHR(lasterror); } Trace.WriteLine(returnBytes); } } catch (Exception e2) { Trace.WriteLine(e2); } }