Author: eaglet
Reprinted please indicate the source
My system needs to compare the file time and size to determine whether the two files are the same, but during the running process, it is often found that the file time is inexplicably modified for 1-2 seconds. I have not studied this problem carefully and thought it was a bug of Microsoft. I have not found this problem clearly until recently. The system often downloads the same files from the server. I carefully studied this issue today and found that it is not a problem with Microsoft operating systems, but a problem with file system design.
Go straight to the topic
The FAT32 file system uses the FAT table (File Allocation Table) to store the file index information. To minimize the space occupied by each file in the FAT table, the FAT32 file system limits the file size to less than 4 GB, the file time precision to 2 seconds, and is aligned with an even number. The NTFS file system uses the MFT table (master file table) to store file metadata. This master file table is equivalent to a small database and can store more metadata. Therefore, whether the NTFS file system is the file size or the file time precision is much higher than that of FAT32. NTFS, the file precision is 100ns.
Because the file precision of the two file systems is different, if we copy the file from the NTFS file system to the FAT32 file, due to different time precision, the file time will be forcibly aligned with an even number.
NTFS time: 7 hours 31 min 0 sec 000 ms.
FAT time: 7 hours 31 min 0 sec 000 ms.
NTFS time: 7 hours 31 min 0 sec 001 ms.
FAT32 time: 7 hours 31 min 2 sec 000 ms.
NTFS time: 7 hours 31 min 1 sec 000 ms.
FAT32 time: 7 hours 31 min 2 sec 000 ms.
NTFS time: 7 hours 31 min 1 sec 999 ms.
FAT32 time: 7 hours 31 min 2 sec 000 ms.
From the above example, we can see that NTFS to FAT32, the file time will be 2 seconds at most.
If we need to determine whether the file is the same through the file time in the program, we must take into account the time error of the two file systems, otherwise the system will be wrong. In addition, it is better to use MD5 to determine whether the files are the same, but for large files, the MD5 computing time will be relatively long.
Refer:
Http://support.microsoft.com/kb/127830