18 int main(int argc
, char *argv
[]);
20 void get_times(char *name
, time_t *a
, time_t *c
, time_t *m
);
30 m
= (argc
== 2 ? atoi(argv
[1]) : 0xFFFF);
33 for (i
= 0; i
< 4; i
++) {
34 if (m
& 0001) test16a();
38 return(-1); /* impossible */
43 /* Test atime, ctime, and mtime. */
45 int fd
, fd1
, fd2
, fd3
, fd4
;
46 time_t a
, c
, m
, pa
, pc
, pm
, xa
, xc
, xm
, ya
, yc
, ym
, za
, zc
, zm
, ta
, tc
, tm
;
52 if (passes
> 0) return; /* takes too long to repeat this test */
54 if ( (fd
= creat("T16.a", 0666)) < 0) e(1);
55 if (write(fd
, buf
, 1024) != 1024) e(2);
56 if (close(fd
) < 0) e(3);
57 sleep(1); /* wait 1 sec before continuing */
58 if ( (fd
= open("T16.a", O_RDONLY
)) < 0) e(4);
59 if (read(fd
, buf
, 3) != 3) e(5);
60 if (close(fd
) != 0) e(6);
61 if (stat("T16.a", &s
) != 0) e(7);
66 /* Almost certainly means we are running a V1 file system. */
67 printf(" (atime = 0. Probably V1 file system. V2 tests skipped.) ");
71 /* Many system calls affect atime, ctime, and mtime. Test them. They
72 * fall into several groups. The members of each group can be tested
73 * together. Start with creat(), mkdir(), and mkfifo, all of which
74 * set all 3 times on the created object, and ctime and mtime of the dir.
76 if ( (fd
= creat("T16.b", 0666)) < 0) e(8);
77 if (close(fd
) != 0) e(9);
78 get_times("T16.b", &a
, &c
, &m
);
79 get_times(".", &pa
, &pc
, &pm
);
84 if (unlink("T16.b") < 0) e(14);
86 /* Test the times for mkfifo. */
87 if ( (fd
= mkfifo("T16.c", 0666)) != 0) e(15);
88 if (access("T16.c", R_OK
| W_OK
) != 0) e(16);
89 get_times("T16.c", &a
, &c
, &m
);
90 get_times(".", &pa
, &pc
, &pm
);
95 if (unlink("T16.c") < 0) e(21);
97 /* Test the times for mkdir. */
98 if (mkdir("T16.d", 0666) < 0) e(22);
99 get_times("T16.d", &a
, &c
, &m
);
100 get_times(".", &pa
, &pc
, &pm
);
106 if (rmdir("T16.d") < 0) e(27);
107 get_times(".", &xa
, &xc
, &xm
);
112 /* Test open(file, O_TRUNC). */
113 if ( (fd
= open("T16.e", O_WRONLY
|O_CREAT
, 0666)) < 0) e(31);
114 if (write(fd
, buf
, 1024) != 1024) e(32);
115 if (close(fd
) != 0) e(33);
116 get_times("T16.e", &a
, &c
, &m
);
117 get_times(".", &pa
, &pc
, &pm
);
119 if ( (fd
= open("T16.e", O_WRONLY
|O_TRUNC
)) < 0) e(34);
120 get_times("T16.e", &xa
, &xc
, &xm
);
121 get_times(".", &ya
, &yc
, &ym
);
128 if (close(fd
) != 0) e(41);
129 /* Try once more, now without changing the file size. */
131 if ( (fd
= open("T16.e", O_WRONLY
|O_TRUNC
)) < 0) e(89);
132 get_times("T16.e", &a
, &c
, &m
);
136 if (close(fd
) != 0) e(93);
138 /* Test the times for link/unlink. */
139 get_times("T16.e", &a
, &c
, &m
);
140 get_times(".", &ya
, &yc
, &ym
);
142 if (link("T16.e", "T16.f") != 0) e(42); /* second link */
143 get_times("T16.e", &xa
, &xc
, &xm
);
144 get_times(".", &pa
, &pc
, &pm
);
147 #ifndef V1_FILESYSTEM
156 if (unlink("T16.f") != 0) e(46);
157 get_times("T16.e", &a
, &c
, &m
);
158 get_times(".", &ya
, &yc
, &ym
);
161 #ifndef V1_FILESYSTEM
168 if (unlink("T16.e") != 0) e(58);
170 /* Test rename, read, write, chmod, utime. */
171 get_times(".", &pa
, &pc
, &pm
);
172 if ( (fd
= open("T16.g", O_RDWR
|O_CREAT
)) < 0) e(59);
173 if ( (fd1
= open("T16.h", O_WRONLY
|O_CREAT
, 0666)) < 0) e(60);
174 if ( (fd2
= open("T16.i", O_WRONLY
|O_CREAT
, 0666)) < 0) e(61);
175 if ( (fd3
= open("T16.j", O_WRONLY
|O_CREAT
, 0666)) < 0) e(62);
176 if ( (fd4
= open("T16.k", O_RDWR
|O_CREAT
, 0666)) < 0) e(63);
177 if (write(fd
, buf
, 1024) != 1024) e(64);
178 get_times("T16.g", &a
, &c
, &m
);
179 get_times("T16.h", &pa
, &pc
, &pm
);
180 get_times("T16.i", &xa
, &xc
, &xm
);
181 get_times("T16.j", &ya
, &yc
, &ym
);
182 get_times("T16.k", &za
, &zc
, &zm
);
183 get_times(".", &wa
, &wc
, &wm
);
185 lseek(fd
, 0L, SEEK_SET
);
186 if (read(fd
, buf
, 35) != 35) e(65);
187 get_times("T16.g", &ta
, &tc
, &tm
);
188 if (a
== ta
|| c
!= tc
|| m
!= tm
) e(66);
189 if (write(fd1
, buf
, 35) != 35) e(67);
190 get_times("T16.h", &ta
, &tc
, &tm
);
191 if (pa
!= ta
|| pc
== tc
|| pm
== tm
) e(69);
192 if (rename("T16.i", "T16.i1") != 0) e(70);
193 get_times("T16.i1", &ta
, &tc
, &tm
);
194 if (xa
!= ta
|| xc
!= tc
|| xm
!= tm
) e(71);
195 get_times(".", &a
, &c
, &m
);
196 if (a
!= wa
|| c
== wc
|| m
== wm
|| wc
!= wm
) e(72);
197 if (chmod("T16.j", 0777) != 0) e(73);
198 get_times("T16.j", &ta
, &tc
, &tm
);
199 if (ya
!= ta
|| yc
== tc
|| ym
!= tm
) e(74);
200 if (utime("T16.k", (void *) 0) != 0) e(75);
201 get_times("T16.k", &ta
, &tc
, &tm
);
202 if (za
== ta
|| zc
== tc
) e(76);
203 if (close(fd
) != 0) e(77);
204 if (close(fd1
) != 0) e(78);
205 if (close(fd2
) != 0) e(79);
206 if (close(fd3
) != 0) e(80);
207 if (close(fd4
) != 0) e(81);
208 if (unlink("T16.g") != 0) e(82);
209 if (unlink("T16.h") != 0) e(83);
210 if (unlink("T16.i1") != 0) e(84);
211 if (unlink("T16.j") != 0) e(85);
212 if (unlink("T16.k") != 0) e(86);
214 /* Test the times for truncate. */
215 if (system("echo 1 > T16.l") != 0) e(87);
217 get_times("T16.l", &a
, &c
, &m
);
219 truncate("T16.l", s
.st_size
);
220 get_times("T16.l", &ta
, &tc
, &tm
);
221 if (a
!= ta
|| c
!= tc
|| m
!= tm
) e(88);
224 void get_times(name
, a
, c
, m
)
230 if (stat(name
, &s
) != 0) e(500);