S h o r t S t o r i e s

// Tales from software development

Comparing file timestamps on NTFS and FAT32

leave a comment »

I’ve just bumped into a problem with file timestamps that I’ve encountered before and decided to research it a little more thoroughly this time around.

I was working on a utility that runs as a service and keeps a set of files in sync across several disks. The files’ Last Write timestamps are used to determine if a file has been updated and needs to be copied to keep the other copies of the file in sync.

Everything worked fine in my development environment but when the utility was deployed to the customer’s server we immediately noticed that the files were always being copied from one particular disk to another whenever it ran. The source disk was an NTFS formatted 500GB disk and the target disk was a 32GB SSD formatted as FAT32. This immediately set alarm bells ringing in my mind as FAT32 file timestamps don’t hold date/time information to the same resolution as NTFS.

NTFS stores all timestamps to 100 nanosecond resolution. By comparison, FAT32 stores the time portion of a timestamp to a 2 second resolution. There is an additional field that holds additional time information at 10ms resolution for the Create Date/Time only.

I updated the utility to allow a discrepancy of up to 2000 ms (i.e. 2 seconds) when comparing timestamps if the source and target disks are formatted with different filesystems. I also added some debugging code to identify the maximum discrepancy that was found when no files had been changed to confirm that the 2000 ms value was sufficient.

The largest discrepancy found when running against 14,000 files totalling 2.5GB was 1994 ms. So, the 2000 ms value looks to be sufficient.

Advertisements

Written by Sea Monkey

March 22, 2010 at 8:00 pm

Posted in Development

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: