When did I create you?

Posted: February 17, 2009 in Uncategorized

I thought I would add some file aging capabilities to a logger class as an lower bound guarantee. I thought it would be nice to use the creation time of a file to keep track, bad idea, this is why.

It had to be platform agnostic so I set about trying to implement it in Windows first. I wrote all the code and ran the unit test. To my amazement sometimes the unit test failed some times it worked. Actually most of the time it failed. I started debugging it and found to my surprise that the creation date of the file somehow carried forward when a fast delete/create of a file at the same location with the same name was done. I swiftly turned to the MSDN doc and read it more closely for CreateFile and what would you know, it is a documented feature. A small line among a few hundred, not very precise either.

“If you rename or delete a file and then restore it shortly afterward, the system searches the cache for file information to restore. Cached information includes its short/long name pair and creation time.”

How odd? Who came up with that idea. Well that someone even came up with a name is called File System Tunneling


Once again the reason is backward compatibility, to MS-DOS!

“The idea is to mimic the behavior MS-DOS programs expect when they use the safe save method. They copy the modified data to a temporary file, delete the original and rename the temporary to the original. This should seem to be the original file when complete. Windows performs tunneling on both FAT and NTFS file systems to ensure long/short file names are retained when 16-bit applications perform this safe save operation”

All you people complaining that Vista breaks things, you should instead rejoice and be happy that we are finally getting rid of more and more legacy idiocies such as this (although this is still in Vista and Windows 7).

Either way, I ended up setting the creation time upon creation of a file. Finally done I thought.

Well things get even worse in unix. Unix file systems generally don’t track creation times. You could fake it through the i-node time stamp (through fsdb) however if a new i-node is created for whatever reason the time stamp will be updated. Not very reliable. FreeBSD apparently tracks it as birth time, all in all, as so very often in the unix land, it is a mess and no real set standard.

I played around in a few different distros to try to figure out a solution, but found none. So.. if anyone happen to read this and know what to do feel free to share.

For now I will have to resort to the very tacky thing of reading the date from the first log row in the file and cache that… Not really a performance problem as this is part of a syslog service that is running all the time, so generally it will only be needed upon restart.

  1. Mattias says:

    Another idea is too store meta data, such as creation time, separately, in a separate file. Not very pretty either… But on the other hand that means you don\’t have to rely on/trust the contents of the file. Which as you say is a bad thing, as this functionality has nothing to do with the contents of the file anyway.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s