Determining Which File System Is in Use

To determine under which file system your application is currently running, the application calls the GetVolumeInformation function. This function returns information about the current volume, such as the maximum length of filenames. Once you call this function, you can use the value returned in the lpMaximumComponentLength parameter as the maximum file length in your application and dynamically allocate a buffer for your filenames and paths. This is preferable to using static buffers for filenames and paths. If you must use static buffers, however, reserve at least 256 characters for filenames and 260 characters for paths.

Here is the syntax for the GetVolumeInformation function:

BOOL GetVolumeInformation (
LPCTSTR lpRootPathName,
LPTSTR lpVolumeNameBuffer,
DWORD nVolumeNameSize,
LPDWORD lpVolumeSerialNumber,
LPDWORD lpMaximumComponentLength,
LPDWORD lpFileSystemFlags,
LPTSTR lpFileSystemNameBuffer,
DWORD nFileSystemNameSize)

lpRootPathName points to a string containing the root directory of the volume to be queried. If this parameter is NULL, the root of the current directory is used.

lpVolumeNameBuffer points to a buffer that is filled in with the name of the volume. This parameter can be NULL if the volume name is not needed.

nVolumeNameSize is the length, in characters, of the volume name buffer. This parameter is ignored if the volume name buffer is not supplied.

lpVolumeSerialNumber points to a variable that is filled in with the volume serial number. This parameter can be NULL if the volume serial number is not needed.

lpMaximumComponentLength points to a variable that is filled in with the maximum length, in characters, of a filename component (the part of the filename between the backslashes) supported by the specified file system.

lpFileSystemFlags points to a variable that is filled in with flags associated with the specified file system. This variable can contain any combination of flags, such as FS_CASE_SENSITIVE, which specifies that the file system supports case-sensitive filename lookup. For a description of all the flags, see the Win32 SDK documentation.

lpFileSystemNameBuffer points to a buffer that is filled in with the name of the file system (such as FAT, HPFS, or NTFS). This parameter can be NULL if the system name is not needed.

nFileSystemNameSize is the length, in characters, of the file system name buffer. This parameter is ignored if the name buffer is not supplied.