Reputation: 67221
Can anybvody tell me why unix does not store the file creation time? Is it such a big burden to it as it stores modification time,change time and access time but not creation time? Is there any specific reason for it?
or is it through using some language(any programming language) and some system calls can we get the file creation time some how?
Upvotes: 3
Views: 5750
Reputation: 30813
The main reason Unix do not store creation time is this information is controversial as there is no standard definition of what a file creation date should be set to.
Some people would like this creation time to represent the time when the data was created (eg: a jpeg photo was shot) and thus to be preserved when a file is copied or restored from backup. On the other hand, some other people prefer this creation time to be the time when the file system object (eg: inode) is created.
The former, when done, usually appears inside the file (eg: EXIF).
The latter is what recent file systems provide:
Note there is no agreement to name the field used to store this creation time.
Upvotes: 3
Reputation: 538
stat will return modification change st_ctime once a file is modified or it's owner changes it's provenance changes so all bets are off on the contents dos/nt is unreliable in this regards as you can trash a file completely, rewriting it in it's entirety within a command shell and the creation time will not change
The metadata associated with a file in unix does not guarantee an original creation time but preserves the creation time for the latest version. If you need to version your files then the version should be made explicit externally or internally
The field st_ctime is changed by writing or by setting inode information (i.e., owner, group, link count, mode, etc.).
struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device ID (if special file) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for file system I/O */
blkcnt_t st_blocks; /* number of 512B blocks allocated */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last status change */
};
Upvotes: 1
Reputation: 52565
As WhiteboardDev notes, many modern filesystems do store the file creation time, but it's not standard so the method of accessing the details vary.
As for the specific reason for it, it's basically historical. It really was a burden to store too many pieces of meta-data in the seventies when many of these APIs were first defined. (It's worth noting that current filesystems do not always update the "last access time" because that is burden...)
Upvotes: 1
Reputation: 819
I believe that information like that is the responsibility of the inode to store and, therefore, a limitation of the file system itself. A quick googling and it turns out that the ext4 file system has added storage for that file attribute in its inode.
Upvotes: 5