public bool ReadNameAndFirmwareRevision(IntPtr handle, int driveNumber,
                                                out string name, out string firmwareRevision)
        {
            var parameter = new DriveCommandParameter
            {
                DriveNumber = (byte)driveNumber,
                Registers   = { Command = RegisterCommand.IdCmd }
            };


            var valid = SystemCall.DeviceIoControl(handle,
                                                   DriveCommand.ReceiveDriveData, ref parameter, Marshal.SizeOf(parameter),
                                                   out DriveIdentifyResult result, Marshal.SizeOf(typeof(DriveIdentifyResult)),
                                                   out _, IntPtr.Zero);

            if (!valid)
            {
                name             = null;
                firmwareRevision = null;
                return(false);
            }

            name             = GetString(result.Identify.ModelNumber);
            firmwareRevision = GetString(result.Identify.FirmwareRevision);
            return(true);
        }
Example #2
0
        public static DriveAttribute[] ReadSmart(IntPtr handle, int driveNumber)
        {
            DriveCommandParameter parameter = new DriveCommandParameter();
            DriveSmartReadResult  result;
            uint bytesReturned;

            parameter.DriveNumber        = (byte)driveNumber;
            parameter.Registers.Features = SMART_READ_DATA;
            parameter.Registers.LBAMid   = SMART_LBA_MID;
            parameter.Registers.LBAHigh  = SMART_LBA_HI;
            parameter.Registers.Command  = SMART_CMD;

            bool valid = DeviceIoControl(handle, DriveCommand.ReceiveDriveData,
                                         ref parameter, Marshal.SizeOf(parameter), out result,
                                         Marshal.SizeOf(typeof(DriveSmartReadResult)), out bytesReturned,
                                         IntPtr.Zero);

            if (!valid)
            {
                return(null);
            }
            else
            {
                return(result.Attributes);
            }
        }
Example #3
0
        public bool ReadNameAndFirmwareRevision(IntPtr handle, int driveNumber,
                                                out string name, out string firmwareRevision)
        {
            DriveCommandParameter parameter = new DriveCommandParameter();
            DriveIdentifyResult   result;
            uint bytesReturned;

            parameter.DriveNumber       = (byte)driveNumber;
            parameter.Registers.Command = RegisterCommand.IdCmd;

            bool valid = NativeMethods.DeviceIoControl(handle,
                                                       DriveCommand.ReceiveDriveData, ref parameter, Marshal.SizeOf(parameter),
                                                       out result, Marshal.SizeOf(typeof(DriveIdentifyResult)),
                                                       out bytesReturned, IntPtr.Zero);

            if (!valid)
            {
                name             = null;
                firmwareRevision = null;
                return(false);
            }

            name             = GetString(result.Identify.ModelNumber);
            firmwareRevision = GetString(result.Identify.FirmwareRevision);
            return(true);
        }
Example #4
0
        public static string ReadName(IntPtr handle, int driveNumber)
        {
            DriveCommandParameter parameter = new DriveCommandParameter();
            DriveIdentifyResult   result;
            uint bytesReturned;

            parameter.DriveNumber       = (byte)driveNumber;
            parameter.Registers.Command = ID_CMD;

            bool valid = DeviceIoControl(handle, DriveCommand.ReceiveDriveData,
                                         ref parameter, Marshal.SizeOf(parameter), out result,
                                         Marshal.SizeOf(typeof(DriveIdentifyResult)), out bytesReturned,
                                         IntPtr.Zero);

            if (!valid)
            {
                return(null);
            }
            else
            {
                byte[] bytes = result.Identify.ModelNumber;
                char[] chars = new char[bytes.Length];
                for (int i = 0; i < bytes.Length; i += 2)
                {
                    chars[i]     = (char)bytes[i + 1];
                    chars[i + 1] = (char)bytes[i];
                }

                return(new string(chars).Trim());
            }
        }
Example #5
0
        public static bool EnableSmart(IntPtr handle, int driveNumber)
        {
            DriveCommandParameter parameter = new DriveCommandParameter();
            DriveCommandResult    result;
            uint bytesReturned;

            parameter.DriveNumber        = (byte)driveNumber;
            parameter.Registers.Features = SMART_ENABLE_OPERATIONS;
            parameter.Registers.LBAMid   = SMART_LBA_MID;
            parameter.Registers.LBAHigh  = SMART_LBA_HI;
            parameter.Registers.Command  = SMART_CMD;

            return(DeviceIoControl(handle, DriveCommand.SendDriveCommand,
                                   ref parameter, Marshal.SizeOf(parameter), out result,
                                   Marshal.SizeOf(typeof(DriveCommandResult)), out bytesReturned,
                                   IntPtr.Zero));
        }
Example #6
0
        public bool EnableSmart(IntPtr handle, int driveNumber)
        {
            DriveCommandParameter parameter = new DriveCommandParameter();
            DriveCommandResult    result;
            uint bytesReturned;

            parameter.DriveNumber        = (byte)driveNumber;
            parameter.Registers.Features = RegisterFeature.SmartEnableOperations;
            parameter.Registers.LBAMid   = SMART_LBA_MID;
            parameter.Registers.LBAHigh  = SMART_LBA_HI;
            parameter.Registers.Command  = RegisterCommand.SmartCmd;

            return(NativeMethods.DeviceIoControl(handle, DriveCommand.SendDriveCommand,
                                                 ref parameter, Marshal.SizeOf(typeof(DriveCommandParameter)), out result,
                                                 Marshal.SizeOf(typeof(DriveCommandResult)), out bytesReturned,
                                                 IntPtr.Zero));
        }
Example #7
0
        public DriveAttributeValue[] ReadSmartData(IntPtr handle, int driveNumber)
        {
            DriveCommandParameter    parameter = new DriveCommandParameter();
            DriveSmartReadDataResult result;
            uint bytesReturned;

            parameter.DriveNumber        = (byte)driveNumber;
            parameter.Registers.Features = RegisterFeature.SmartReadData;
            parameter.Registers.LBAMid   = SMART_LBA_MID;
            parameter.Registers.LBAHigh  = SMART_LBA_HI;
            parameter.Registers.Command  = RegisterCommand.SmartCmd;

            bool isValid = NativeMethods.DeviceIoControl(handle,
                                                         DriveCommand.ReceiveDriveData, ref parameter, Marshal.SizeOf(parameter),
                                                         out result, Marshal.SizeOf(typeof(DriveSmartReadDataResult)),
                                                         out bytesReturned, IntPtr.Zero);

            return((isValid) ? result.Attributes : new DriveAttributeValue[0]);
        }
        public bool EnableSmart(IntPtr handle, int driveNumber)
        {
            var parameter = new DriveCommandParameter
            {
                DriveNumber = (byte)driveNumber,
                Registers   =
                {
                    Features = RegisterFeature.SmartEnableOperations,
                    LBAMid   = SMART_LBA_MID,
                    LBAHigh  = SMART_LBA_HI,
                    Command  = RegisterCommand.SmartCmd
                }
            };


            return(SystemCall.DeviceIoControl(handle, DriveCommand.SendDriveCommand,
                                              ref parameter, Marshal.SizeOf(typeof(DriveCommandParameter)), out DriveCommandResult _,
                                              Marshal.SizeOf(typeof(DriveCommandResult)), out _,
                                              IntPtr.Zero));
        }
        public bool EnableSmart()
        {
            if (handle.IsClosed)
            {
                throw new ObjectDisposedException("WindowsATASmart");
            }

            DriveCommandParameter parameter = new DriveCommandParameter();
            DriveCommandResult    result;
            uint bytesReturned;

            parameter.DriveNumber        = (byte)driveNumber;
            parameter.Registers.Features = RegisterFeature.SmartEnableOperations;
            parameter.Registers.LBAMid   = SMART_LBA_MID;
            parameter.Registers.LBAHigh  = SMART_LBA_HI;
            parameter.Registers.Command  = RegisterCommand.SmartCmd;

            return(NativeMethods.DeviceIoControl(handle, DriveCommand.SendDriveCommand,
                                                 ref parameter, Marshal.SizeOf(parameter), out result,
                                                 Marshal.SizeOf(typeof(DriveCommandResult)), out bytesReturned,
                                                 IntPtr.Zero));
        }
        public DriveAttributeValue[] ReadSmartData(IntPtr handle, int driveNumber)
        {
            var parameter = new DriveCommandParameter
            {
                DriveNumber = (byte)driveNumber,
                Registers   =
                {
                    Features = RegisterFeature.SmartReadData,
                    LBAMid   = SMART_LBA_MID,
                    LBAHigh  = SMART_LBA_HI,
                    Command  = RegisterCommand.SmartCmd
                }
            };


            var isValid = SystemCall.DeviceIoControl(handle,
                                                     DriveCommand.ReceiveDriveData, ref parameter, Marshal.SizeOf(parameter),
                                                     out DriveSmartReadDataResult result, Marshal.SizeOf(typeof(DriveSmartReadDataResult)),
                                                     out _, IntPtr.Zero);

            return(isValid ? result.Attributes : new DriveAttributeValue[0]);
        }
Example #11
0
        public static List <DriveAttribute> ReadSmart(IntPtr handle,
                                                      int driveNumber)
        {
            DriveCommandParameter parameter = new DriveCommandParameter();
            DriveSmartReadResult  result;
            uint bytesReturned;

            parameter.DriveNumber        = (byte)driveNumber;
            parameter.Registers.Features = SMART_READ_DATA;
            parameter.Registers.LBAMid   = SMART_LBA_MID;
            parameter.Registers.LBAHigh  = SMART_LBA_HI;
            parameter.Registers.Command  = SMART_CMD;

            bool isValid = NativeMethods.DeviceIoControl(handle,
                                                         DriveCommand.ReceiveDriveData, ref parameter, Marshal.SizeOf(parameter),
                                                         out result, Marshal.SizeOf(typeof(DriveSmartReadResult)),
                                                         out bytesReturned, IntPtr.Zero);

            return((isValid)
        ? new List <DriveAttribute>(result.Attributes)
        : new List <DriveAttribute>());
        }
        public DriveThresholdValue[] ReadSmartThresholds()
        {
            if (handle.IsClosed)
            {
                throw new ObjectDisposedException("WindowsATASmart");
            }

            DriveCommandParameter          parameter = new DriveCommandParameter();
            DriveSmartReadThresholdsResult result;
            uint bytesReturned = 0;

            parameter.DriveNumber        = (byte)driveNumber;
            parameter.Registers.Features = RegisterFeature.SmartReadThresholds;
            parameter.Registers.LBAMid   = SMART_LBA_MID;
            parameter.Registers.LBAHigh  = SMART_LBA_HI;
            parameter.Registers.Command  = RegisterCommand.SmartCmd;

            bool isValid = NativeMethods.DeviceIoControl(handle,
                                                         DriveCommand.ReceiveDriveData, ref parameter, Marshal.SizeOf(parameter),
                                                         out result, Marshal.SizeOf(typeof(DriveSmartReadThresholdsResult)),
                                                         out bytesReturned, IntPtr.Zero);

            return((isValid) ? result.Thresholds : new DriveThresholdValue[0]);
        }
Example #13
0
 public static extern bool DeviceIoControl(IntPtr handle,
                                           DriveCommand command, ref DriveCommandParameter parameter,
                                           int parameterSize, out DriveIdentifyResult result, int resultSize,
                                           out uint bytesReturned, IntPtr overlapped);
 public static extern bool DeviceIoControl(SafeHandle handle,
                                           DriveCommand command, ref DriveCommandParameter parameter,
                                           int parameterSize, out DriveSmartReadThresholdsResult result,
                                           int resultSize, out uint bytesReturned, IntPtr overlapped);
Example #15
0
    public bool EnableSmart(IntPtr handle, int driveNumber) {
      DriveCommandParameter parameter = new DriveCommandParameter();
      DriveCommandResult result;
      uint bytesReturned;

      parameter.DriveNumber = (byte)driveNumber;
      parameter.Registers.Features = RegisterFeature.SmartEnableOperations;
      parameter.Registers.LBAMid = SMART_LBA_MID;
      parameter.Registers.LBAHigh = SMART_LBA_HI;
      parameter.Registers.Command = RegisterCommand.SmartCmd;

      return NativeMethods.DeviceIoControl(handle, DriveCommand.SendDriveCommand, 
        ref parameter, Marshal.SizeOf(typeof(DriveCommandParameter)), out result,
        Marshal.SizeOf(typeof(DriveCommandResult)), out bytesReturned, 
        IntPtr.Zero);
    }
Example #16
0
 public static extern bool DeviceIoControl(IntPtr handle,
   DriveCommand command, ref DriveCommandParameter parameter,
   int parameterSize, out DriveIdentifyResult result, int resultSize,
   out uint bytesReturned, IntPtr overlapped);
Example #17
0
    public bool ReadNameAndFirmwareRevision(IntPtr handle, int driveNumber, 
      out string name, out string firmwareRevision) 
    {
      DriveCommandParameter parameter = new DriveCommandParameter();
      DriveIdentifyResult result;
      uint bytesReturned;

      parameter.DriveNumber = (byte)driveNumber;
      parameter.Registers.Command = RegisterCommand.IdCmd;

      bool valid = NativeMethods.DeviceIoControl(handle, 
        DriveCommand.ReceiveDriveData, ref parameter, Marshal.SizeOf(parameter), 
        out result, Marshal.SizeOf(typeof(DriveIdentifyResult)), 
        out bytesReturned, IntPtr.Zero);

      if (!valid) {
        name = null;
        firmwareRevision = null;
        return false;
      }

      name = GetString(result.Identify.ModelNumber);
      firmwareRevision = GetString(result.Identify.FirmwareRevision);
      return true;
    }
Example #18
0
    public DriveThresholdValue[] ReadSmartThresholds(IntPtr handle,
      int driveNumber) 
    {
      DriveCommandParameter parameter = new DriveCommandParameter();
      DriveSmartReadThresholdsResult result;
      uint bytesReturned = 0;

      parameter.DriveNumber = (byte)driveNumber;
      parameter.Registers.Features = RegisterFeature.SmartReadThresholds;
      parameter.Registers.LBAMid = SMART_LBA_MID;
      parameter.Registers.LBAHigh = SMART_LBA_HI;
      parameter.Registers.Command = RegisterCommand.SmartCmd;

      bool isValid = NativeMethods.DeviceIoControl(handle,
        DriveCommand.ReceiveDriveData, ref parameter, Marshal.SizeOf(parameter),
        out result, Marshal.SizeOf(typeof(DriveSmartReadThresholdsResult)), 
        out bytesReturned, IntPtr.Zero); 

      return (isValid) ? result.Thresholds : new DriveThresholdValue[0];
    }