FreeBSD 5+ with UFS2 provides real inode creation time in st_birthtime field of struct stat. If the filesystem doesn't support it, st_birthtime is set to -1.
Following sample patch adds support for st_birthtime to source/lib/time.c.
It should be made conditional on the presence of the field, unfortunately I'm not familiar with autotools. Any help on that will be appreciated.
Created attachment 1723 [details]
Great news ! I've been hoping a UNIX would provide this sometime. We need a configure.in test for the st_birthtime field of the stat struct though.
Solaris' ZFS also support creation times. A major task which still will have to be done for FreeBSD is *setting* the btime. There are two methods of setting creation time, if this is actually correct:
To provide a sensible birth time for applications that are unaware of the birth time attribute, we changed the semantics of the "utimes" system call so that if the birth time was newer than the value of the modification time that it was setting, it sets the birth time to the same time as the modification time. An application that is aware of the birth time attribute can set both the birth time and the modification time by doing two calls to "utimes". First it calls "utimes" with a modification time equal to the saved birth time, then it calls "utimes" a second time with a modification time equal to the (presumably newer) saved modification time. For filesystems that do not store birth times, the second call will overwrite the first call resulting in the same values for access and modification times as they would have previously gotten. For filesystems that support birth time, it will be properly set. And most happily for the application writers, they will not have to conditionally compile the name of "utimes" for BSD and non-BSD systems. They just write their applications to call the standard interface twice knowing that the right thing will happen on all systems and filesystems. For those applications that value speed of execution over portability can use the new version of the "utimes" system call that allows all time values to be set with one call.
Created attachment 2027 [details]
send birthtime (with configure checks)
Add configure checks.
I've looked at adding ability to set birthtime but unfortunately there is still no "new" version of utimes syscall and with current utimes it would only be possible to set birthtime older than current.
Also there is no quick & easy way to implement it in samba ;(
What I gathered so far is that I would have to modify smbd/reply.c:reply_setattrE() and change file_utime()/SMB_VFS_UTIME (with modules) to use something more flexible than struct utimbuf that has only 2 fields: actime and modtime. Is that correct/all ?
I have equivalent patches for Darwin. I'll look at merging these and those.
I Don't know if James merged his patches but the birthtime support (not setting however) is there now.