惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
A
About on SuperTechFans
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
aimingoo的专栏
aimingoo的专栏
T
The Blog of Author Tim Ferriss
IT之家
IT之家
罗磊的独立博客
博客园_首页
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
量子位
Hugging Face - Blog
Hugging Face - Blog
G
Google Developers Blog
博客园 - 叶小钗
H
Help Net Security
N
Netflix TechBlog - Medium
B
Blog
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
Vercel News
Vercel News
博客园 - 三生石上(FineUI控件)

博客园 - bodong

Unreal Engine 5创建项目失败:文件“{ConfigFile}”处理失败。 如何找到当前计算机所有的UnrealEngine安装位置 Unreal Engine 5调试资源依赖来源的方法 GhostDoc Enterprise.v2024.2.24300 for Visual Studio 2022插件漏洞分析和离线解锁方法 ScyllaHide插件可能导致x64dbg的日志窗口无法捕获应用程序输出的日志字符串 C++使用宏来判断当前编译期支持的C++标准版本的方法 VisualStudio各版本_MSC_VER和_MSC_FULL_VER宏定义值列表 Rider如何针对一个项目禁用某一类错误检查(Inspections)的办法 UnrealEngine 5 C++标准版本 UnrealEngine Setup即使挂了代理也很慢的解决办法 CPPStringFormatting: 使用.NET格式化字符串风格格式化C++字符串的库 Windows平台下使用C++和Windows API计算文件MD5的方法 将C++代码文件路径、行号、函数名称等打包到#pragma message输出的方法 KnownDLLs列表 Avalonia实现Visual Studio风格标题栏的方法 解决IDA Pro Warning:mssdk64_win7: No such file or directory AHeadLib.Net C#版本的DLL劫持代码生成工具 安装Visual Studio 2022指定版本的方法 UnrealSharp: 一个可以让你在UnrealEngine5中采用C# 12和.NET 8.0开发的插件
Windows平台下使用C++检测硬盘分区是否属于SSD硬盘的方法
bodong · 2024-05-30 · via 博客园 - bodong
#include <iostream>
#include <windows.h>
#include <tchar.h>
#include <string>
#include <cassert>

typedef std::basic_string<TCHAR> StringT;

bool IsDriveSSD(const StringT& driveName)
{
    assert(driveName.size()>=2);

    HANDLE hDevice = CreateFile((_T("\\\\.\\") + driveName.substr(0, 2)).c_str(), 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);

    if (hDevice == INVALID_HANDLE_VALUE)
    {
        return false;
    }

    STORAGE_PROPERTY_QUERY query{};
    query.PropertyId = StorageDeviceSeekPenaltyProperty;
    query.QueryType = PropertyStandardQuery;
    DWORD count;
    DEVICE_SEEK_PENALTY_DESCRIPTOR result{};
    if (DeviceIoControl(hDevice, IOCTL_STORAGE_QUERY_PROPERTY,
        &query, sizeof(query), &result, sizeof(result), &count, nullptr))
    {
        CloseHandle(hDevice);
        return !result.IncursSeekPenalty;
    }

    CloseHandle(hDevice);

    return false;
}

int main()
{
    DWORD len = GetLogicalDriveStrings(0, NULL);
    if (len == 0)
    {
        return 0;
    }

    TCHAR* buffer = new TCHAR[len];
    
    GetLogicalDriveStrings(len, buffer);

    for (TCHAR* drive = buffer; *drive; drive += _tcslen(drive) + 1)
    {
        // ULARGE_INTEGER freeBytesAvailable;
        // ULARGE_INTEGER totalNumberOfBytes;
        // ULARGE_INTEGER totalNumberOfFreeBytes;

        // if (GetDiskFreeSpaceEx(drive, &freeBytesAvailable, &totalNumberOfBytes, &totalNumberOfFreeBytes))
        {
        #if UNICODE
        #define  _tcout std::wcout
        #else
        #define  _tcout std::cout
        #endif

            _tcout << drive << _T("  ") << (IsDriveSSD(drive)?_T("True") : _T("False")) << std::endl;
        }
    }

    delete[] buffer;

    return 0;
}

输出:

C:\  True
D:\  False
E:\  False
F:\  False
G:\  True
H:\  True
I:\  True