示例#1
0
 // \\.\ScsiY: is different from \\.\PhysicalDriveX
 private static NVMeInfo GetDeviceInfo()
 {
     while (nextDrive < MAX_DRIVES)
     {
         using (WindowsNVMeSmart smart = new WindowsNVMeSmart(nextDrive)) {
             nextDrive++;
             if (!smart.IsValid)
             {
                 continue;
             }
             NVMeInfo info = smart.GetInfo();
             if (info != null)
             {
                 return(info);
             }
         }
     }
     return(null);
 }
        // \\.\ScsiY: is different from \\.\PhysicalDriveX
        // We need to find the NvmeInfo that matches the drive we search.
        private static NVMeInfo GetDeviceInfo(StorageInfo infoToMatch, int previousDrive)
        {
            for (int nextDrive = previousDrive + 1; nextDrive <= MAX_DRIVES; nextDrive++)
            {
                using (WindowsNVMeSmart smart = new WindowsNVMeSmart(nextDrive)) {
                    if (!smart.IsValid)
                    {
                        continue;
                    }
                    NVMeInfo info = smart.GetInfo(infoToMatch, nextDrive, false);
                    if (info != null)
                    {
                        return(info);
                    }
                }
            }

            // This is a bit tricky. If this fails for one drive, it will fail for all, because we start with 0 each time.
            // if we failed to obtain any useful information for any drive letter, we force creation - this will later try to use the alternate approach
            // when reading NVMe data. As we know it's an NVME drive
            for (int nextDrive = previousDrive + 1; nextDrive <= MAX_DRIVES; nextDrive++)
            {
                using (WindowsNVMeSmart smart = new WindowsNVMeSmart(nextDrive)) {
                    if (!smart.IsValid)
                    {
                        continue;
                    }
                    NVMeInfo info = smart.GetInfo(infoToMatch, nextDrive, true);
                    if (info != null)
                    {
                        return(info);
                    }
                }
            }

            return(null);
        }