views:

185

answers:

2

Hello world!

I'm writing a file transfer application, and I need to copy files from NTFS to FAT drives. Reading from http://support.microsoft.com/kb/127830, I understand that a time such as #11/29/2004 7:31:06 PM, 250ms# should get translated to #11/29/2004 7:31:08 PM, 0ms# when copying to a FAT hard drive. However, what actually happens is that the file time gets truncated to #11/29/2004 7:31:06 PM, 0ms#.

Am I missing something here? When does the time get truncated, and when does it get rounded?

Thanks a lot! CFP

Edit: Add a code sample:

IO.File.GetLastWriteTimeUtc(Source)

My NTFS->FAT function is:

Function NTFSToFATTime(ByVal NTFSTime As Date) As Date
    Return (New Date(NTFSTime.Year, NTFSTime.Month, NTFSTime.Day, NTFSTime.Hour, NTFSTime.Minute, NTFSTime.Second).AddSeconds(If(NTFSTime.Millisecond = 0, NTFSTime.Second Mod 2, 2 - (NTFSTime.Second Mod 2))))
End Function
+2  A: 

Technical backgrounder: Basically FAT uses 2 bytes to store the time (hours/minutes/seconds) of the file create in the directory entry. It uses the low 4 bits of this field for the seconds, for which values of 0-29 are valid, and are multiplied by 2 to get the final value. Thus by necessity, seconds will be an even number.

Weird, but my guess is that the docs are either wrong or don't refer to the API you're using. Your timestamp is just getting truncated. Not sure which API you're using to create the FAT file (might be useful to see the docs for it).

quixoto
Ummm...Ben, that link is already in the OP's question!... :D
tommieb75
Ha! Fair enough. Editing to neuter my answer of its brilliant insight.
quixoto
Hmmm, the strange thing is that on other cases it does work by rounding the values. I'm using VB.Net... Any further insight ?Thanks!
CFP
I'm not a VB guy, but why are you writing the code to do the truncation/rounding yourself at all? Why not just take the timestamp from NTFS, shove it into FAT, and let the filesystem driver sort it out?
quixoto
Well the point is to write a backup program. So I need to compare file times between different drives...
CFP
A: 

In fact, the problem was related to a hard drive interface handling the file times in the wrong way (a d-link storage bay), ie. truncating rather than rounding.

There's therefore no true way to escape this problem, but to allow for a little sloppiness in time checking.

Thanks a lot, CFP.

CFP