Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine what filesystem a partition is of

How does operating system know what filesystem a partition is using? In other words, how are FAT16/32, NTFS, ext2/3 etc. distinguished from each other?

like image 399
billyswong Avatar asked Dec 22 '22 13:12

billyswong


1 Answers

If you're using Win32 APIs on Windows, then you can call GetVolumeInformation (http://msdn.microsoft.com/en-us/library/aa364993.aspx) to determine the type of file system present on a given mounted volume.

For example, if you're trying to detect the file system present on D:, then you can call:

WCHAR FSType[512];    

if (GetVolumeInformationW(L"D:\\", NULL, 0, NULL, NULL, NULL, FSType, ARRAYSIZE(FSType))) {
    wprintf(L"FS type = %s\n", FSType);    
}

This will only work, however, if the file system is "recognized" and "mountable" by the running operating system.

like image 147
reuben Avatar answered Jan 03 '23 11:01

reuben