1 /* Tries to remove the current directory, which may succeed or
2 fail. The requirements in each case are different; refer to
3 the assignment for details. */
7 #include "tests/main.h"
10 wrap_open (const char *name)
12 static int fds[8], fd_cnt;
15 CHECK ((fd = open (name)) > 1, "open \"%s\"", name);
16 for (i = 0; i < fd_cnt; i++)
18 fail ("fd returned is not unique");
27 char name[READDIR_MAX_LEN + 1];
29 root_fd = wrap_open ("/");
30 CHECK (mkdir ("a"), "mkdir \"a\"");
32 a_fd0 = wrap_open ("/a");
33 CHECK (!readdir (a_fd0, name), "verify \"/a\" is empty");
34 CHECK (inumber (root_fd) != inumber (a_fd0),
35 "\"/\" and \"/a\" must have different inumbers");
37 CHECK (chdir ("a"), "chdir \"a\"");
39 msg ("try to remove \"/a\"");
42 msg ("remove successful");
44 CHECK (open ("/a") == -1, "open \"/a\" (must fail)");
45 CHECK (open (".") == -1, "open \".\" (must fail)");
46 CHECK (open ("..") == -1, "open \"..\" (must fail)");
47 CHECK (!create ("x", 512), "create \"x\" (must fail)");
51 int a_fd1, a_fd2, a_fd3;
53 msg ("remove failed");
55 CHECK (!remove ("../a"), "try to remove \"../a\" (must fail)");
56 CHECK (!remove (".././a"), "try to remove \".././a\" (must fail)");
57 CHECK (!remove ("/./a"), "try to remove \"/./a\" (must fail)");
59 a_fd1 = wrap_open ("/a");
60 a_fd2 = wrap_open (".");
61 CHECK (inumber (a_fd1) == inumber (a_fd2),
62 "\"/a\" and \".\" must have same inumber");
63 CHECK (inumber (root_fd) != inumber (a_fd1),
64 "\"/\" and \"/a\" must have different inumbers");
66 CHECK (chdir ("/a"), "chdir \"/a\"");
67 a_fd3 = wrap_open (".");
68 CHECK (inumber (a_fd3) == inumber (a_fd1),
69 "\".\" must have same inumber as before");
71 CHECK (chdir ("/"), "chdir \"/\"");
72 CHECK (!remove ("a"), "try to remove \"a\" (must fail: still open)");
74 CHECK (!readdir (a_fd0, name), "verify \"/a\" is empty");