NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: setting file creation time of a date



    Date:        Thu, 30 Apr 2020 12:21:18 +0200
    From:        Riccardo Mottola <riccardo.mottola%libero.it@localhost>
    Message-ID:  <6a5beb80-729f-ddcf-6b12-70eb13d7e4e5%libero.it@localhost>

  | But can I set the creation time? I'd like to be able to preserve it when 
  | dealing with files.

As Johhny Billquist said, the standard technique is to set the modtime
to the value you want the birthtime to be, and then set the modtime to
the value you want it to be (call utimes() (or one of its variants) twice).

But I wouldn't bother, the birthtime field is useless.

For example, whether it should be preserved when dealing with files
depends entirely upon what you're doing - if you're making a backup of
x.c in a file called old-x.c ("cp x.c old-x.c") then it probably makes
sense, but if you're using x.c as a template for new code, to get the
boilerplate parts correct ("cp x.c  newfile.c") then you almost certainly
don't.

There's no way that either the cp cpmmand (or anything similar to it) or
the system can tell the difference between those two cases, so the only
way for the birthtime field to be updated properly, is if you explicitly
tell the system when it should be set.  Now imagine how likely it is that
you're going to remember to do that properly every time...   Further, since
you have to do it, you may as well put it inside the file somewhere,
where you can see it more easily, if the system can't automatically update
and keep track of it, it doesn't belong in the inode.

I have previously asked people to tell me what they believe the semantics of
the birthtime are, and how that is useful for something - no-one has ever
succeeded in providing semantics that can be made to work, and which are
simultaneously useful.   It's easy to specify how the field can be set
but for those cases it there are no uses beyond human curiosity ("What was
the birthtime set to?") - there are uses to which a good file creation time
could be put, but no known reliable way to make the field actually work
reliably for those uses.

kre



Home | Main Index | Thread Index | Old Index