Getting the cluster size of a hard drive (through code)

限于喜欢 提交于 2020-06-27 07:04:18

问题


I need to find the cluster size of the users hard drive, through C or C++. The hard drive uses NTFS (though I'd appreciate knowing how it's done on other file systems as well).

I guess what I need is some combination of win32 API calls, but I don't know which.

For instance, typing "fsutil fsinfo ntfsinfo c:" in the windows console gives you "Bytes per cluster", which is what I need. (Though for obvious reasons, I don't want to run that command and parse it's output.)


回答1:


Use the GetDiskFreeSpace

BOOL WINAPI GetDiskFreeSpace(
  __in   LPCTSTR lpRootPathName,
  __out  LPDWORD lpSectorsPerCluster, // <--
  __out  LPDWORD lpBytesPerSector, // <--
  __out  LPDWORD lpNumberOfFreeClusters,
  __out  LPDWORD lpTotalNumberOfClusters
);


来源:https://stackoverflow.com/questions/1073646/getting-the-cluster-size-of-a-hard-drive-through-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!