Unix btime specification (creation date) available?

runki647

New Member


Messages: 1

Hello,

is there a specification for Unix or in general for btime (creation date) for files and directories?

Could it be that btime must always be lower (before) mtime (modification date)? It would be very good if there is a specification page to read it. Thanks.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 11,563
Messages: 37,878

Code:
            The btime timestamp was not historically present on UNIX
              systems and is not currently supported by most Linux
              filesystems.
From Linux' inode(7)

As far as I know POSIX only defines ctime, mtime and atime. If you're looking for their definition, it's in stat(2):
Code:
     st_atim          Time when file data was last accessed.  Changed
                      implicitly by syscalls such as read(2) and readv(2), and
                      explicitly by utimes(2).

     st_mtim          Time when file data was last modified.  Changed
                      implicitly by syscalls such as truncate(2), write(2),
                      and writev(2), and explicitly by utimes(2).  Also, any
                      syscall which modifies directory content changes the
                      st_mtim for the affected directory.  For instance,
                      creat(2), mkdir(2), rename(2), link(2), and unlink(2).

     st_ctim          Time when file status was last changed (inode data
                      modification).  Changed implicitly by any syscall that
                      affects file metadata, including st_mtim, such as
                      chflags(2), chmod(2), chown(2), truncate(2), utimes(2),
                      and write(2).  Also, any syscall which modifies
                      directory content changes the st_ctim for the affected
                      directory.  For instance, creat(2), mkdir(2), rename(2),
                      link(2), and unlink(2).
"Birth time" does seem to be defined:
Code:
st_birthtim      Time when the inode was created.
But I'm not sure if the UFS or ZFS filesystem actually uses it.

is there a specification for Unix or in general for btime (creation date) for files and directories?
I'm going to say, no, there isn't. It's not even consistent with different filesystems. Sometimes it exists, most of the time it doesn't.
 

ralphbsz

Son of Beastie

Reaction score: 2,181
Messages: 3,133

The birth time (a.k.a. btime) is a relatively recent addition to Unix; it came from Windows, and was initially implemented in Unix file systems to help with serving file systems to windows clients. Please don't call it "creation date", since that's confusing: that term is usually used for the Unix ctime. I don't know whether Posix (and successors) have written a specification for it yet; last time I worked on Posix-compliance of file system interfaces, it wasn't standardized yet.

On FreeBSD, the two big file systems (UFS and ZFS) support it, as do most relevant system calls (stat, utimes, and derivatives).

Is it always lower than mtime? I think in most cases that's true. Here's why: When you create a file, they are the same. When you write to a file, mtime increases, and btime stays the same. If you use the utimes() call to set mtime backwards and it is earlier than btime, then btime goes down with it. Other operations (reading, changing file attributes) don't change either btime or mtime. So I think btime <= mtime is an invariant. But I'm not 100% sure that is guaranteed, and there may be sequences (in particular with the system clock changing non-monotonically) that may be able to violate it.
 
Top