1 /* This tests the behavior of Minix when the current working dir (cwd) doesn't
2 * actually exist and we either:
4 * - make a new directory
5 * - make a special file (mknod)
7 * - create a symbolic link, or
9 * In each case, `a component of the path does not name an existing file', and
10 * the operation should fail with ENOENT. These tests should actually be
11 * distributed over the other tests that actually test the specific system
19 #include <sys/socket.h>
20 #include <sys/types.h>
25 #define MAX_ERROR 999 /* Effectively no limit. This is necessary as this
26 * test tries to undo errors and should therefore not
27 * preemptively exit, as that would leave the FS
28 * in a corrupted state. */
31 #define TEST_PATH "a/b/c"
32 #define INTEGR_MSG "You might want to check fs integrity\n"
40 char buf
[1], testroot
[PATH_MAX
+1], renamebuf
[PATH_MAX
+1];
43 if (socketpair(PF_UNIX
, SOCK_STREAM
, 0, s
) == -1) e(1);
44 if (system("mkdir -p " TEST_PATH
) == -1) e(2);
45 if (realpath(".", testroot
) == NULL
) e(3);
49 else if (r
== 0) { /* Child */
50 /* Change child's cwd to TEST_PATH */
51 if (chdir(TEST_PATH
) == -1) e(5);
53 /* Signal parent we're ready for the test */
55 if (write(s
[0], buf
, sizeof(buf
)) != sizeof(buf
)) e(6);
57 /* Wait for parent to remove my cwd */
58 if (read(s
[0], buf
, sizeof(buf
)) != sizeof(buf
)) e(7);
60 /* Try to create a file */
61 if ((fd
= open("testfile", O_RDWR
| O_CREAT
)) != -1) {
63 /* Uh oh. We created a file?! Try to remove it. */
65 if (unlink("testfile") != 0) {
66 /* This is not good. We created a file, but we can
67 * never access it; we have a spurious inode.
74 if (errno
!= ENOENT
) e(10);
76 /* Try to create a dir */
78 if (mkdir("testdir", 0777) == 0) {
80 /* Uh oh. This shouldn't have been possible. Try to undo. */
81 if (rmdir("testdir") != 0) {
88 if (errno
!= ENOENT
) e(13);
90 /* Try to create a special file */
92 if (mknod("testnode", 0777 | S_IFIFO
, 0) == 0) {
94 /* Impossible. Try to make it unhappen. */
95 if (unlink("testnode") != 0) {
102 if (errno
!= ENOENT
) e(16);
104 /* Try to rename a file */
106 /* First create a file in the test dir */
107 snprintf(renamebuf
, PATH_MAX
, "%s/oldname", testroot
);
108 if ((fd
= open(renamebuf
, O_RDWR
| O_CREAT
)) == -1) e(17);
109 if (close(fd
) != 0) e(18);
111 /* Now try to rename that file to an entry in the current, non-existing
114 if (rename(renamebuf
, "testrename") == 0) {
116 /* This shouldn't have been possible. Revert the name change.
118 if (rename("testrename", renamebuf
) != 0) {
126 /* Try to create a hard link to that file */
128 if (link(renamebuf
, "testhlink") == 0) {
130 /* Try to undo the hard link to prevent fs corruption. */
131 if (unlink("testhlink") != 0) {
138 if (errno
!= ENOENT
) e(23);
140 /* Try to create a symlink */
142 if (symlink(testroot
, "testslink") == 0) {
144 /* Try to remove the symlink to prevent fs corruption. */
145 if (unlink("testslink") != 0) {
152 if (errno
!= ENOENT
) e(26);
155 } else { /* Parent */
158 /* Wait for the child to enter the TEST_PATH dir */
159 if (read(s
[1], buf
, sizeof(buf
)) != sizeof(buf
)) e(27);
161 /* Delete TEST_PATH */
162 if (rmdir(TEST_PATH
) != 0) e(28);
164 /* Tell child we removed its cwd */
166 if (write(s
[1], buf
, sizeof(buf
)) != sizeof(buf
)) e(29);
169 errct
+= WEXITSTATUS(status
); /* Count errors */
173 int main(int argc
, char* argv
[])
178 return(-1); /* Unreachable */