lr123
lr123

Reputation: 1650

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

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.)

Upvotes: 11

Views: 7927

Answers (1)

Nick Dandoulakis
Nick Dandoulakis

Reputation: 43140

Use the GetDiskFreeSpace

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

Upvotes: 17

Related Questions