Пример #1
0
        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);
        }
Пример #2
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));
        }
Пример #3
0
        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]);
        }