Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 647
larspars Avatar asked Jul 02 '09 10:07

larspars


People also ask

How do I know the cluster size of my hard drive?

To calculate the cluster size, simply take the size of the partition and divide it among the number of available clusters. For example, the maximum size of a FAT16 partition is 2 GB.

What is hard drive cluster size?

Cluster size represents the smallest amount of disk space that can be used to hold a file. When file sizes do not come out to an even multiple of the cluster size, additional space must be used to hold the file (up to the next multiple of the cluster size).


1 Answers

Use the GetDiskFreeSpace

BOOL WINAPI GetDiskFreeSpace(
  __in   LPCTSTR lpRootPathName,
  __out  LPDWORD lpSectorsPerCluster, // <--
  __out  LPDWORD lpBytesPerSector, // <--
  __out  LPDWORD lpNumberOfFreeClusters,
  __out  LPDWORD lpTotalNumberOfClusters
);
like image 164
Nick Dandoulakis Avatar answered Oct 20 '22 16:10

Nick Dandoulakis