コード例 #1
0
ファイル: c_HDD_Smart.cs プロジェクト: AMV007/Common_CSharp
        bool IsSmartEnabled(IntPtr hDevice, byte ucDriveIndex, ref ST_DRIVE_INFO m_stDrivesInfo)
        {
            SENDCMDINPARAMS  stCIP = new SENDCMDINPARAMS();
            SENDCMDOUTPARAMS stCOP = new SENDCMDOUTPARAMS();
            uint             dwRet = 0;
            bool             bRet  = false;

            stCIP.cBufferSize                  = 0;
            stCIP.bDriveNumber                 = ucDriveIndex;
            stCIP.irDriveRegs.bFeaturesReg     = C_SMART_SUBREGISTER.ENABLE_SMART;
            stCIP.irDriveRegs.bSectorCountReg  = 1;
            stCIP.irDriveRegs.bSectorNumberReg = 1;
            stCIP.irDriveRegs.bCylLowReg       = SMART_CYL_LOW;
            stCIP.irDriveRegs.bCylHighReg      = SMART_CYL_HI;
            stCIP.irDriveRegs.bDriveHeadReg    = DRIVE_HEAD_REG;
            stCIP.irDriveRegs.bCommandReg      = SMART_CMD;
            object OutObj = stCOP;

            bRet = kernel32.DeviceIoControl(hDevice, SMART_SEND_DRIVE_COMMAND, stCIP, ref OutObj, ref dwRet);
            if (bRet)
            {
            }
            else
            {
                dwRet = (uint)Marshal.GetLastWin32Error();
                m_stDrivesInfo.m_csErrorString = "Error " + dwRet + " in reading SMART Enabled flag";
            }
            return(bRet);
        }
コード例 #2
0
 private static extern int DeviceIoControl(uint hDevice,
                                           uint dwIoControlCode,
                                           ref SENDCMDINPARAMS lpInBuffer,
                                           int nInBufferSize,
                                           ref SENDCMDOUTPARAMS lpOutBuffer,
                                           int nOutBufferSize,
                                           ref uint lpbytesReturned,
                                           int lpOverlapped);
コード例 #3
0
 internal static extern bool DeviceIoControl
 (
     SafeHandle hDevice,
     DFP dwIoControlCode,
     ref SENDCMDINPARAMS lpInBuffer,
     int nInBufferSize,
     out IDENTIFYCMDOUTPARAMS lpOutBuffer,
     int nOutBufferSize,
     out uint lpBytesReturned,
     IntPtr lpOverlapped);
コード例 #4
0
        public DriveInfo(int driveNumber)
        {
            int handle;

            this._driveType = DriveTypes.Unknown;
            SENDCMDINPARAMS  sci = new SENDCMDINPARAMS();
            SENDCMDOUTPARAMS sco = new SENDCMDOUTPARAMS();

            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                string file = @"\\.\PhysicalDrive" + driveNumber.ToString();
                handle = CreateFile(file, -1073741824, 3, 0, 3, 0, 0);
            }
            else
            {
                string _Vb_t_string_0 = @"\\.\Smartvsd";
                handle = CreateFile(_Vb_t_string_0, 0, 0, 0, 1, 0, 0);
            }
            if (handle != -1)
            {
                int returnSize;
                sci.DriveNumber            = (byte)driveNumber;
                sci.BufferSize             = Marshal.SizeOf(sco);
                sci.DriveRegs.DriveHead    = (byte)(160 | (driveNumber << 4));
                sci.DriveRegs.Command      = 0xec;
                sci.DriveRegs.SectorCount  = 1;
                sci.DriveRegs.SectorNumber = 1;
                returnSize = 0;
                if (DeviceIoControl(handle, 0x7c088, sci, Marshal.SizeOf(sci), sco, Marshal.SizeOf(sco), ref returnSize, 0) != 0)
                {
                    this._serialNumber    = SwapChars(sco.IDS.SerialNumber);
                    this._model           = SwapChars(sco.IDS.ModelNumber);
                    this._firmware        = SwapChars(sco.IDS.FirmwareRevision);
                    this._numberCylinders = sco.IDS.NumberCylinders;
                    this._numberHeads     = sco.IDS.NumberHeads;
                    this._sectorsPerTrack = sco.IDS.SectorsPerTrack;
                    this._bufferSize      = sco.IDS.BufferSize * 0x200;
                    if ((sco.IDS.GenConfig & 0x80) == 0x80)
                    {
                        this._driveType = DriveTypes.Removable;
                    }
                    else if ((sco.IDS.GenConfig & 0x40) == 0x40)
                    {
                        this._driveType = DriveTypes.Fixed;
                    }
                    else
                    {
                        this._driveType = DriveTypes.Unknown;
                    }
                }
                CloseHandle(handle);
            }
        }
コード例 #5
0
    //***************************************************************************
    // DoIdentify
    // Function: Send an IDENTIFY command to the drive
    // DriveNum = 0-3
    // IDCmd = IDE_ID_FUNCTION or IDE_ATAPI_ID
    //***************************************************************************
    private static string IdentifyDrive(int hDrive, byte IDCmd)
    {
        SENDCMDINPARAMS SCIP = null;

        byte[] bArrOut           = new byte[OUTPUT_DATA_SIZE];
        byte[] bSerial           = new byte[20];
        int    lpcbBytesReturned = 0;

        //   Set up data structures for IDENTIFY command.

        // Compute the drive number.
        // The command can either be IDE identify or ATAPI identify.
        SCIP.irDriveRegs.bCommandReg = (byte)IDCmd;

        if (DeviceIoControl(hDrive, DFP_RECEIVE_DRIVE_DATA, ref SCIP, Marshal.SizeOf(SCIP) - 4, bArrOut, OUTPUT_DATA_SIZE, ref lpcbBytesReturned, 0L) != 0)
        {
            System.Buffer.BlockCopy(bArrOut, 36, bSerial, 0, 20);
            bSerial = SwapBytes(bSerial);
            return(Encoding.ASCII.GetString(bSerial));
        }
        return(null);
    }
コード例 #6
0
    //****************************************************************************
    // CheckSMARTEnable - Check if SMART enable
    // FUNCTION: Send a SMART_ENABLE_SMART_OPERATIONS command to the drive
    // bDriveNum = 0-3

    //***************************************************************************
    private static bool CheckSMARTEnable(int hDrive, IDE_DRIVE_NUMBER DriveNum)
    {
        //Set up data structures for Enable SMART Command.
        SENDCMDINPARAMS  SCIP = null;
        SENDCMDOUTPARAMS SCOP = null;
        int lpcbBytesReturned = 0;

        {
            SCIP.cBufferSize = 0;
            {
                SCIP.irDriveRegs.bFeaturesReg = SMART_ENABLE_SMART_OPERATIONS;
                SCIP.irDriveRegs.bCylLowReg   = SMART_CYL_LOW;
                SCIP.irDriveRegs.bCylHighReg  = SMART_CYL_HI;
                //Compute the drive number.
                SCIP.irDriveRegs.bDriveHeadReg = 0xa0;
                // Or (DriveNum And 1) * 16
                SCIP.irDriveRegs.bCommandReg = IDE_EXECUTE_SMART_FUNCTION;
            }
            SCIP.bDriveNumber = DriveNum;
        }
        return(Convert.ToBoolean(DeviceIoControl(hDrive, DFP_SEND_DRIVE_COMMAND, ref SCIP, Marshal.SizeOf(SCIP) - 4, ref SCOP, Marshal.SizeOf(SCOP) - 4, ref lpcbBytesReturned, 0L)));
    }
コード例 #7
0
ファイル: c_HDD_Smart.cs プロジェクト: AMV007/Common_CSharp
        bool CollectDriveInfo(IntPtr hDevice, byte ucDriveIndex, ref ST_DRIVE_INFO m_stDrivesInfo)
        {
            bool            bRet  = false;
            SENDCMDINPARAMS stCIP = new SENDCMDINPARAMS();
            uint            dwRet = 0;

            const int OUT_BUFFER_SIZE = IDENTIFY_BUFFER_SIZE + 16;

            char[] szOutput = new char[OUT_BUFFER_SIZE];

            stCIP.cBufferSize                  = IDENTIFY_BUFFER_SIZE;
            stCIP.bDriveNumber                 = ucDriveIndex;
            stCIP.irDriveRegs.bFeaturesReg     = 0;
            stCIP.irDriveRegs.bSectorCountReg  = 1;
            stCIP.irDriveRegs.bSectorNumberReg = 1;
            stCIP.irDriveRegs.bCylLowReg       = 0;
            stCIP.irDriveRegs.bCylHighReg      = 0;
            stCIP.irDriveRegs.bDriveHeadReg    = DRIVE_HEAD_REG;
            stCIP.irDriveRegs.bCommandReg      = ID_CMD;

            object TempO = szOutput;

            bRet     = kernel32.DeviceIoControl(hDevice, SMART_RCV_DRIVE_DATA, stCIP, ref TempO, ref dwRet);
            szOutput = (char[])TempO;
            if (bRet)
            {
                m_stDrivesInfo.m_stInfo = (ST_IDSECTOR)ArrayToStructure(szOutput, m_stDrivesInfo.m_stInfo.GetType(), 16);
                ConvertString(ref m_stDrivesInfo.m_stInfo.sModelNumber);
                ConvertString(ref m_stDrivesInfo.m_stInfo.sSerialNumber);
                ConvertString(ref m_stDrivesInfo.m_stInfo.sFirmwareRev);
            }
            else
            {
                dwRet = (uint)Marshal.GetLastWin32Error();
            }
            return(bRet);
        }
コード例 #8
0
        private PhysicalDisk method_4(string string_1)
        {
            PhysicalDisk disk = new PhysicalDisk {
                Extents      = new VOLUMEDISKEXTENTS(),
                Adapter      = new STORAGE_ADAPTER_DESCRIPTOR(),
                DeviceID     = new STORAGE_DEVICE_ID_DESCRIPTOR(),
                Device       = new STORAGE_DEVICE_DESCRIPTOR(),
                Version      = new GETVERSIONOUTPARAMS(),
                Params       = new SENDCMDOUTPARAMS(),
                SerialNumber = string.Empty,
                Firmware     = string.Empty,
                Model        = string.Empty
            };

            char[]         trimChars = new char[] { '\\' };
            SafeFileHandle handle    = Class1.CreateFileW(Class3.smethod_10(0) + Path.GetPathRoot(string_1).TrimEnd(trimChars), 0xc0000000, 3, IntPtr.Zero, 3, 0x80, IntPtr.Zero);

            try
            {
                uint    num     = 0;
                int     cb      = Marshal.SizeOf(disk.Extents);
                IntPtr  ptr     = Marshal.AllocHGlobal(cb);
                Struct0 struct2 = new Struct0();
                uint    num3    = this.method_0(0x56, 0, 0, 0);
                if (Class1.DeviceIoControl_1(handle, num3, IntPtr.Zero, 0, ptr, cb, ref num, 0))
                {
                    disk.Extents = (VOLUMEDISKEXTENTS)Marshal.PtrToStructure(ptr, typeof(VOLUMEDISKEXTENTS));
                    disk.Number  = Convert.ToByte(disk.Extents.diskNumber);
                }
                cb             = Marshal.SizeOf(disk.Adapter);
                ptr            = Marshal.AllocHGlobal(cb);
                struct2.uint_0 = 1;
                struct2.uint_1 = 0;
                if (Class1.DeviceIoControl(handle, 0x2d1400, struct2, Marshal.SizeOf(struct2), ptr, cb, ref num, 0))
                {
                    disk.Adapter = (STORAGE_ADAPTER_DESCRIPTOR)Marshal.PtrToStructure(ptr, typeof(STORAGE_ADAPTER_DESCRIPTOR));
                }
                cb             = Marshal.SizeOf(disk.DeviceID);
                ptr            = Marshal.AllocHGlobal(cb);
                struct2.uint_0 = 2;
                struct2.uint_1 = 0;
                if (Class1.DeviceIoControl(handle, 0x2d1400, struct2, Marshal.SizeOf(struct2), ptr, cb, ref num, 0))
                {
                    disk.DeviceID = (STORAGE_DEVICE_ID_DESCRIPTOR)Marshal.PtrToStructure(ptr, typeof(STORAGE_DEVICE_ID_DESCRIPTOR));
                }
                cb             = Marshal.SizeOf(disk.Device);
                ptr            = Marshal.AllocHGlobal(cb);
                struct2.uint_0 = 0;
                struct2.uint_1 = 0;
                if (Class1.DeviceIoControl(handle, 0x2d1400, struct2, Marshal.SizeOf(struct2), ptr, cb, ref num, 0))
                {
                    disk.Device = (STORAGE_DEVICE_DESCRIPTOR)Marshal.PtrToStructure(ptr, typeof(STORAGE_DEVICE_DESCRIPTOR));
                    string str2 = Encoding.ASCII.GetString(disk.Device.RawDeviceProperties);
                    int    num4 = Marshal.SizeOf(disk.Device) - disk.Device.RawDeviceProperties.Length;
                    if (disk.Device.ProductIdOffset > 0)
                    {
                        char[] chArray2 = new char[2];
                        chArray2[1] = ' ';
                        disk.Model  = str2.Substring(disk.Device.ProductIdOffset - num4, 20).Trim(chArray2);
                    }
                    if (disk.Device.ProductRevisionOffset > 0)
                    {
                        char[] chArray3 = new char[2];
                        chArray3[1]   = ' ';
                        disk.Firmware = str2.Substring(disk.Device.ProductRevisionOffset - num4, 8).Trim(chArray3);
                    }
                    if (disk.Device.SerialNumberOffset > 0)
                    {
                        char[] chArray4 = new char[2];
                        chArray4[1]       = ' ';
                        disk.SerialNumber = str2.Substring(disk.Device.SerialNumberOffset - num4, 40).Trim(chArray4);
                    }
                    if ((disk.SerialNumber != null) && (disk.SerialNumber.Length == 40))
                    {
                        disk.SerialNumber = this.method_3(disk.SerialNumber);
                    }
                    disk.RemovableMedia = Convert.ToBoolean(disk.Device.RemovableMedia);
                }
                cb  = Marshal.SizeOf(disk.Version);
                ptr = Marshal.AllocHGlobal(cb);
                if (Class1.DeviceIoControl_1(handle, 0x74080, IntPtr.Zero, 0, ptr, cb, ref num, 0))
                {
                    disk.Version = (GETVERSIONOUTPARAMS)Marshal.PtrToStructure(ptr, typeof(GETVERSIONOUTPARAMS));
                    if ((disk.Version.fCapabilities & 4L) > 0L)
                    {
                        SENDCMDINPARAMS sendcmdinparams = new SENDCMDINPARAMS();
                        sendcmdinparams.DriveRegs.Command = 0xec;
                        sendcmdinparams.DriveNumber       = disk.Number;
                        sendcmdinparams.BufferSize        = 0x200;
                        if (Class1.DeviceIoControl(handle, 0x7c088, sendcmdinparams, Marshal.SizeOf(sendcmdinparams), ptr, cb, ref num, 0))
                        {
                            disk.Params       = (SENDCMDOUTPARAMS)Marshal.PtrToStructure(ptr, typeof(SENDCMDOUTPARAMS));
                            disk.Model        = this.method_2(disk.Params.IDS.ModelNumber).Trim();
                            disk.Firmware     = this.method_2(disk.Params.IDS.FirmwareRevision).Trim();
                            disk.SerialNumber = this.method_2(disk.Params.IDS.SerialNumber).Trim();
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                if (handle != null)
                {
                    handle.Dispose();
                }
            }
            return(disk);
        }
コード例 #9
0
 private static int DeviceIoControl(int hDevice, int ByValdwIoControlCode, ref SENDCMDINPARAMS lpInBuffer, int nInBufferSize, byte[] lpOutBuffer, int nOutBufferSize, ref int lpBytesReturned, int lpOverlapped)
 {
     //
 }
コード例 #10
0
ファイル: c_HDD_Smart.cs プロジェクト: AMV007/Common_CSharp
        bool ReadSMARTAttributes(IntPtr hDevice, byte ucDriveIndex, ref ST_DRIVE_INFO m_stDrivesInfo)
        {
            SENDCMDINPARAMS stCIP = new SENDCMDINPARAMS();
            uint            dwRet = 0;
            bool            bRet  = false;

            char[] szAttributes = new char[Marshal.SizeOf(typeof(ST_ATAOUTPARAM)) + READ_ATTRIBUTE_BUFFER_SIZE - 1];
            m_stDrivesInfo.m_stSmartInfo = new ST_SMART_INFO[256];

            stCIP.cBufferSize                  = READ_ATTRIBUTE_BUFFER_SIZE;
            stCIP.bDriveNumber                 = ucDriveIndex;
            stCIP.irDriveRegs.bFeaturesReg     = C_SMART_SUBREGISTER.READ_ATTRIBUTES;
            stCIP.irDriveRegs.bSectorCountReg  = 1;
            stCIP.irDriveRegs.bSectorNumberReg = 1;
            stCIP.irDriveRegs.bCylLowReg       = SMART_CYL_LOW;
            stCIP.irDriveRegs.bCylHighReg      = SMART_CYL_HI;
            stCIP.irDriveRegs.bDriveHeadReg    = DRIVE_HEAD_REG;
            stCIP.irDriveRegs.bCommandReg      = SMART_CMD;

            object TempO = szAttributes;

            bRet         = kernel32.DeviceIoControl(hDevice, SMART_RCV_DRIVE_DATA, stCIP, ref TempO, ref dwRet);
            szAttributes = (char[])TempO;
            if (bRet)
            {
                m_stDrivesInfo.m_ucSmartValues = 0;
                m_stDrivesInfo.m_ucDriveIndex  = ucDriveIndex;

                int pT1 = Marshal.SizeOf(typeof(ST_DRIVERSTAT)) + 4; // buffer
                int pT3, pT2;
                for (int ucT1 = 0; ucT1 < 30; ++ucT1)
                {
                    pT3 = pT1 + 2 + ucT1 * 12;
                    pT2 = pT3 + C_SMART_ATTRIB_INDEX.RAW;

                    for (int i = 2; i < 7; i++)
                    {
                        szAttributes[pT3 + C_SMART_ATTRIB_INDEX.RAW + i] = (char)0;
                    }

                    if (szAttributes[pT3 + C_SMART_ATTRIB_INDEX.INDEX] != 0)
                    {
                        m_stDrivesInfo.m_stSmartInfo[m_stDrivesInfo.m_ucSmartValues] = new ST_SMART_INFO();
                        m_stDrivesInfo.m_stSmartInfo[m_stDrivesInfo.m_ucSmartValues].m_ucAttribIndex = (byte)szAttributes[pT3 + C_SMART_ATTRIB_INDEX.INDEX];
                        m_stDrivesInfo.m_stSmartInfo[m_stDrivesInfo.m_ucSmartValues].m_ucValue       = (byte)szAttributes[pT3 + C_SMART_ATTRIB_INDEX.VALUE];
                        m_stDrivesInfo.m_stSmartInfo[m_stDrivesInfo.m_ucSmartValues].m_ucWorst       = (byte)szAttributes[pT3 + C_SMART_ATTRIB_INDEX.WORST];
                        m_stDrivesInfo.m_stSmartInfo[m_stDrivesInfo.m_ucSmartValues].m_dwAttribValue = ReadUint(szAttributes, pT2);
                        m_stDrivesInfo.m_stSmartInfo[m_stDrivesInfo.m_ucSmartValues].m_dwThreshold   = uint.MaxValue;
                        m_stDrivesInfo.m_stSmartInfo[m_stDrivesInfo.m_ucSmartValues].Details         = GetAttrDesc(m_stDrivesInfo.m_stSmartInfo[m_stDrivesInfo.m_ucSmartValues].m_ucAttribIndex);
                        m_stDrivesInfo.m_ucSmartValues++;
                    }
                }
            }
            else
            {
                dwRet = (uint)Marshal.GetLastWin32Error();
            }

            stCIP.irDriveRegs.bFeaturesReg = C_SMART_SUBREGISTER.READ_THRESHOLDS;
            stCIP.cBufferSize = READ_THRESHOLD_BUFFER_SIZE; // Is same as attrib size
            TempO             = szAttributes;
            bRet         = kernel32.DeviceIoControl(hDevice, SMART_RCV_DRIVE_DATA, stCIP, ref TempO, ref dwRet);
            szAttributes = (char[])TempO;
            if (bRet)
            {
                int pT1 = Marshal.SizeOf(typeof(ST_DRIVERSTAT)) + 4; // buffer
                int pT3, pT2;
                for (int ucT1 = 0; ucT1 < 30; ++ucT1)
                {
                    pT2 = pT1 + 2 + ucT1 * 12 + 5;
                    pT3 = pT1 + 2 + ucT1 * 12;

                    for (int i = 2; i < 7; i++)
                    {
                        szAttributes[pT3 + C_SMART_ATTRIB_INDEX.RAW + i] = (char)0;
                    }

                    if (szAttributes[pT3] != 0)
                    {
                        for (int i = 0; i < m_stDrivesInfo.m_ucSmartValues; i++)
                        {
                            if (m_stDrivesInfo.m_stSmartInfo[i].m_ucAttribIndex == szAttributes[pT3])
                            {
                                m_stDrivesInfo.m_stSmartInfo[i].m_dwThreshold = szAttributes[pT2];
                                break;
                            }
                        }
                    }
                }
            }
            return(bRet);
        }
コード例 #11
0
        public static string Read(byte drive)
        {
            OperatingSystem os = Environment.OSVersion;

            if (os.Platform != PlatformID.Win32NT)
            {
                throw new NotSupportedException("仅支持WindowsNT/2000/XP");
            }
            //我没有NT4,请哪位大大测试一下NT4下能不能用
            //if (os.Version.Major < 5) throw new NotSupportedException("仅支持WindowsNT/2000/XP");

            string driveName = "\\\\.\\PhysicalDrive" + drive.ToString();
            uint   device    = CreateFile(driveName,
                                          GENERIC_READ | GENERIC_WRITE,
                                          FILE_SHARE_READ | FILE_SHARE_WRITE,
                                          0, OPEN_EXISTING, 0, 0);

            if (device == INVALID_HANDLE_VALUE)
            {
                return("");
            }
            GETVERSIONOUTPARAMS verPara = new GETVERSIONOUTPARAMS();
            uint bytRv = 0;

            if (0 != DeviceIoControl(device, DFP_GET_VERSION,
                                     0, 0, ref verPara, Marshal.SizeOf(verPara),
                                     ref bytRv, 0))
            {
                if (verPara.bIDEDeviceMap > 0)
                {
                    byte             bIDCmd = (byte)(((verPara.bIDEDeviceMap >> drive & 0x10) != 0) ? IDE_ATAPI_IDENTIFY : IDE_ATA_IDENTIFY);
                    SENDCMDINPARAMS  scip   = new SENDCMDINPARAMS();
                    SENDCMDOUTPARAMS scop   = new SENDCMDOUTPARAMS();

                    scip.cBufferSize = IDENTIFY_BUFFER_SIZE;
                    scip.irDriveRegs.bFeaturesReg    = 0;
                    scip.irDriveRegs.bSectorCountReg = 1;
                    scip.irDriveRegs.bCylLowReg      = 0;
                    scip.irDriveRegs.bCylHighReg     = 0;
                    scip.irDriveRegs.bDriveHeadReg   = (byte)(0xA0 | ((drive & 1) << 4));
                    scip.irDriveRegs.bCommandReg     = bIDCmd;
                    scip.bDriveNumber = drive;

                    if (0 != DeviceIoControl(device, DFP_RECEIVE_DRIVE_DATA,
                                             ref scip, Marshal.SizeOf(scip), ref scop,
                                             Marshal.SizeOf(scop), ref bytRv, 0))
                    {
                        StringBuilder s = new StringBuilder();
                        for (int i = 20; i < 40; i += 2)
                        {
                            s.Append((char)(scop.bBuffer[i + 1]));
                            s.Append((char)scop.bBuffer[i]);
                        }
                        CloseHandle(device);
                        return(s.ToString().Trim());
                    }
                }
            }
            CloseHandle(device);
            return("");
        }
コード例 #12
0
        public static bool ReadPhysicalDriveInNtUsingSmart()
        {
            bool done = false;

            for (int drive = 0; drive < 16; drive++)
            {
                //  Try to get a handle to PhysicalDrive IOCTL, report failure
                //  and exit if can't.
                string driveName = String.Concat("\\\\.\\PhysicalDrive", drive);

                //  Windows NT, Windows 2000, Windows Server 2003, Vista
                var hPhysicalDriveIoctl = OpenDisk(drive);

                //FileManagementNativeMethods.CreateFile(driveName,
                //                                                             FileAccess.ReadWrite,
                //                                                             FileShare.Delete | FileShare.ReadWrite,
                //                                                             IntPtr.Zero,
                //                                                             FileMode.Open,
                //                                                             FileOptions.None,
                //                                                             IntPtr.Zero);
                if (!hPhysicalDriveIoctl.IsInvalid)
                {
                    // Reservar memoria para la estructura.
                    var  getVersionParamsStructurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GETVERSIONINPARAMS)));
                    uint cbBytesReturned = 0;
                    var  fgfg            = DeviceManagement.NativeMethods.DeviceIoControl(hPhysicalDriveIoctl,
                                                                                          DiskIoControlCode.SMART_GET_VERSION,
                                                                                          IntPtr.Zero,
                                                                                          0,
                                                                                          getVersionParamsStructurePointer,
                                                                                          (uint)Marshal.SizeOf(typeof(GETVERSIONINPARAMS)),
                                                                                          ref cbBytesReturned,
                                                                                          IntPtr.Zero);

                    if (fgfg)
                    {
                        // Asignar valor a la estructura.
                        var getVersionParamsStructureValue = (GETVERSIONINPARAMS)Marshal.PtrToStructure(getVersionParamsStructurePointer, typeof(GETVERSIONINPARAMS));
                        var deviceLocation = getVersionParamsStructureValue.DeviceLocation;


                        const byte  ID_CMD = 0xEC; // Returns ID sector for ATA
                        const Int32 IDENTIFY_BUFFER_SIZE = 512;
                        uint        iBytesReturned       = 0;
                        var         sci = new SENDCMDINPARAMS
                        {
                            irDriveRegs  = { bCommandReg = ID_CMD },
                            bDriveNumber = (byte)0,
                            cBufferSize  = IDENTIFY_BUFFER_SIZE
                        };

                        var hhhhhh     = (uint)Marshal.SizeOf(typeof(IDENTIFY_DEVICE_DATA));
                        var sciPointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SENDCMDINPARAMS)));
                        var scoPointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SENDCMDOUTPARAMS)));
                        Marshal.StructureToPtr(sci, sciPointer, true);

                        var hhhh = DeviceManagement.NativeMethods.DeviceIoControl(
                            hPhysicalDriveIoctl,
                            DiskIoControlCode.SMART_RCV_DRIVE_DATA,
                            sciPointer,
                            (uint)Marshal.SizeOf(typeof(SENDCMDINPARAMS)),
                            scoPointer,
                            (uint)Marshal.SizeOf(typeof(SENDCMDOUTPARAMS)),
                            ref iBytesReturned,
                            IntPtr.Zero);
                        var scoPointerValue = (SENDCMDOUTPARAMS)Marshal.PtrToStructure(scoPointer, typeof(SENDCMDOUTPARAMS));

                        var bdb = Marshal.SizeOf(typeof(IDENTIFY_DEVICE_DATA));

                        var IdentifyDeviceDataPointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IDENTIFY_DEVICE_DATA)));
                        Marshal.Copy(scoPointerValue.bBuffer, 0, IdentifyDeviceDataPointer, 512);
                        var identifyDeviceDataValue = (IDENTIFY_DEVICE_DATA)Marshal.PtrToStructure(IdentifyDeviceDataPointer, typeof(IDENTIFY_DEVICE_DATA));

                        var fff = identifyDeviceDataValue.GetSupportedFeature(IDENTIFY_DEVICE_DATA.StateFeature.Bit48Lba);

                        //var modelNumber = identifyDeviceDataValue.ModelNumber;

                        //byte[] mnArray = new byte[identifyDeviceDataValue.ModelNumber.Length];
                        //Array.Copy(.ModelNumber, 0, mnArray, 0, identifyDeviceDataValue.ModelNumber.Length - 1);
                        //mnArray.SwapBytes();
                        //var modelNumber = new StringBuilder();
                        //modelNumber.Append(Encoding.ASCII.GetString(mnArray, 0, mnArray.Length));

                        //byte[] snArray1 = new byte[identifyDeviceDataValue.ModelNumber.Length];
                        //Array.Copy(identifyDeviceDataValue.ModelNumber, 0, snArray1, 0, identifyDeviceDataValue.ModelNumber.Length - 1);
                        //snArray1.SwapBytes();
                        //var snResult1 = new StringBuilder();
                        //snResult1.Append(Encoding.ASCII.GetString(snArray1, 0, snArray1.Length));

                        //byte[] snArray = new byte[identifyDeviceDataValue.FirmwareRevision.Length];
                        //Array.Copy(identifyDeviceDataValue.FirmwareRevision, 0, snArray, 0, identifyDeviceDataValue.FirmwareRevision.Length - 1);
                        //snArray.SwapBytes();
                        //var snResult = new StringBuilder();
                        //snResult.Append(Encoding.ASCII.GetString(snArray, 0, snArray.Length));

                        int aaa = 0;
                        aaa++;
                    }
                }
            }

            return(done);
        }