Determine file system [GetVolumeInformation() not helpful]

Ed Broughton 31 Reputation points
2020-10-10T19:53:26.02+00:00

Is there a means of determining the file system of a drive, from a native C++ application? Or, otherwise learning what I want to know*?

GetVolumeInformation() does not tell me what I need to know*.

*WHAT I WANT TO KNOW ABOUT A FILESYSTEM

I want to know the "granularity" with which a filesystem stores a file modification timestamp. Unfortunately, GetVolumeInformation() does not provide this information.

The Windows API provides a FILETIME, which is a count of 10 nanosecond intervals.

NTFS stores the full FILETIME. If the modification time is set to a particular FILETIME, and subsequently "read", the returned FILETIME will match the previously set time, exactly.

However, this is not true on FAT32. Some of the "lower bits" will have been lost (and will be returned as zeroes). The time will have been "rounded".

I THINK A GETVOLUMEINFORMATIONEX() IS NEEDED

Ideally, what I want to know would be learned independently of determining the file system.

That is the intent of GetVolumeInformation().

Some advantages of GetVolumeInformation() are:

  • Support for a future filesystem that an application “never heard of”
  • Handles the possibility that some characteristic cannot be determined just from knowing the file system

CURRENT POSSIBLE APPROACHES TO DETERMING MODIFICATION TIMESTAMP GRANULARITY

APPROACH 1

Create a temporary file on the relevant drive. Set its modification timestamp FILETIME to all 1 bits. Read the FILETIME value. Determine how many "low bits" are zeroes. Delete the temporary file.

Disadvantages:

  • Won't work without file creation and deletion permissions.
  • Slightly inefficient
  • "Hackish"

Advantages:

  • Works with any file system, even an unknown one

APPROACH TWO

Based on the values returned by GetVolumeInformation(), attempt to determine the file system.

From the file system, "look up" the file modification timestamp granularity.

Advantages:

  • Does not require writing to the relevant drive

Disadvantages:

  • May not be reliable.
  • Does not support unknown file systems
  • "Hackish"

UNNECESSARY COMMENTS

  • Windows is able to report the file system of a specified drive.
    Clearly, there is some means of determining it.
  • At the moment, I don't have any non NTFS drives upon which to perform a test.
    However, I don't expect the forum to address that issue.
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,611 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 85,126 Reputation points
    2020-10-11T06:16:58.327+00:00

    You can see the details about Time stamps for each File System in the doc
    File System Behavior Overview.pdf

    Part : "6 Time stamps"


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.