11

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

larspars
  • 1,640
  • 1
  • 15
  • 30
  • Keep in mind that this doesn't tell you a whole lot. Small files can be stored in the directory node itself. – MSalters Jul 02 '09 at 15:25
  • FWIW, a file system's cluster size is sometimes also referred to as its "allocation unit" size, e.g.: http://msdn.microsoft.com/en-us/library/aa383356(VS.85).aspx. – reuben Jul 05 '09 at 08:17

1 Answers1

17

Use the GetDiskFreeSpace

BOOL WINAPI GetDiskFreeSpace(
  __in   LPCTSTR lpRootPathName,
  __out  LPDWORD lpSectorsPerCluster, // <--
  __out  LPDWORD lpBytesPerSector, // <--
  __out  LPDWORD lpNumberOfFreeClusters,
  __out  LPDWORD lpTotalNumberOfClusters
);
Nick Dandoulakis
  • 42,588
  • 16
  • 104
  • 136