2 * Simple test for validating mtime on a file create and set via utime.
15 void usage(char *prog)
17 fprintf(stderr, "usage: %s <filename>\n", prog);
21 int main(int argc, char *argv[])
23 long before_mknod, after_mknod;
24 const char *prog = argv[0];
25 const char *filename = argv[1];
30 utb.actime = 0x47114711;
31 utb.modtime = 0x11471147;
37 /* Adjust the before time back one second, because the kernel's
38 * CURRENT_TIME (lockless clock reading, used to set inode times)
39 * may drift against the do_gettimeofday() time (TSC-corrected and
40 * locked clock reading, used to return timestamps to user space).
41 * This means that the mknod time could be a second older than the
42 * before time, even for a local filesystem such as ext3.
44 before_mknod = time(0) - 1;
45 rc = mknod(filename, 0700, S_IFREG);
46 after_mknod = time(0);
47 if (rc && errno != EEXIST) {
48 fprintf(stderr, "%s: mknod(%s) failed: rc %d: %s\n",
49 prog, filename, errno, strerror(errno));
52 rc = stat(filename, &st);
54 fprintf(stderr, "%s: stat(%s) failed: rc %d: %s\n",
55 prog, filename, errno, strerror(errno));
59 if (st.st_mtime < before_mknod || st.st_mtime > after_mknod) {
61 "%s: bad mknod times %lu <= %lu <= %lu false\n",
62 prog, before_mknod, st.st_mtime, after_mknod);
66 printf("%s: good mknod times %lu%s <= %lu <= %lu\n",
67 prog, before_mknod, before_mknod == st.st_mtime ? "*":"",
68 st.st_mtime, after_mknod);
73 rc = utime(filename, &utb);
75 fprintf(stderr, "%s: utime(%s) failed: rc %d: %s\n",
76 prog, filename, errno, strerror(errno));
80 rc = stat(filename, &st);
82 fprintf(stderr, "%s: second stat(%s) failed: rc %d: %s\n",
83 prog, filename, errno, strerror(errno));
87 if (st.st_mtime != utb.modtime ) {
88 fprintf(stderr, "%s: bad utime mtime %lu should be %lu\n",
89 prog, st.st_mtime, utb.modtime);
93 if (st.st_atime != utb.actime ) {
94 fprintf(stderr, "%s: bad utime mtime %lu should be %lu\n",
95 prog, st.st_atime, utb.actime);
99 printf("%s: good utime mtimes %lu, atime %lu\n",
100 prog, utb.modtime, utb.actime);