1 /* Check if filesystem timestamps are consistent with the system time.
2 Copyright (C) 2016-2023 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3, or (at your option) any later
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12 Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include <stat-time.h>
28 #define TEMPLATE "ckmtime.XXXXXX"
29 #define BILLION 1000000000
31 /* Some filesystems can slightly offset the timestamps of newly created files.
32 To compensate for it, tar testsuite waits at least 1 second before creating
33 next level of incremental backups.
35 However, NFS mounts can offset the timestamps by bigger amounts.
37 This program returns with success (0) if a newly created file is assigned
38 mtime matching the system time to the nearest second.
41 main (int argc
, char **argv
)
44 char name
[sizeof(TEMPLATE
)];
46 struct timespec ts
, td
;
51 strcpy (name
, TEMPLATE
);
56 assert (fstat (fd
, &st
) == 0);
59 td
= timespec_sub (get_stat_mtime (&st
), ts
);
60 diff
= td
.tv_sec
* BILLION
+ td
.tv_nsec
;
63 if (diff
/ BILLION
>= 1)
65 fprintf (stderr
, "file timestamp unreliable\n");