1 /* Create a very deep "vine" of directories: /dir0/dir1/dir2/...
2 and an ordinary file in each of them, until we fill up the
5 Then delete most of them, for two reasons. First, "tar"
6 limits file names to 100 characters (which could be extended
7 to 256 without much trouble). Second, a full disk has no room
8 for the tar archive. */
13 #include "tests/lib.h"
14 #include "tests/main.h"
21 msg ("creating many levels of files and directories...");
23 CHECK (mkdir ("start"), "mkdir \"start\"");
24 CHECK (chdir ("start"), "chdir \"start\"");
27 char name[3][READDIR_MAX_LEN + 1];
28 char file_name[16], dir_name[16];
33 snprintf (file_name, sizeof file_name, "file%d", i);
34 if (!create (file_name, 0))
36 CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
37 snprintf (contents, sizeof contents, "contents %d\n", i);
38 if (write (fd, contents, strlen (contents)) != (int) strlen (contents))
40 CHECK (remove (file_name), "remove \"%s\"", file_name);
46 /* Create directory. */
47 snprintf (dir_name, sizeof dir_name, "dir%d", i);
48 if (!mkdir (dir_name))
50 CHECK (remove (file_name), "remove \"%s\"", file_name);
54 /* Check for file and directory. */
55 CHECK ((fd = open (".")) > 1, "open \".\"");
56 CHECK (readdir (fd, name[0]), "readdir \".\"");
57 CHECK (readdir (fd, name[1]), "readdir \".\"");
58 CHECK (!readdir (fd, name[2]), "readdir \".\" (should fail)");
59 CHECK ((!strcmp (name[0], dir_name) && !strcmp (name[1], file_name))
60 || (!strcmp (name[1], dir_name) && !strcmp (name[0], file_name)),
61 "names should be \"%s\" and \"%s\", "
62 "actually \"%s\" and \"%s\"",
63 file_name, dir_name, name[0], name[1]);
66 /* Descend into directory. */
67 CHECK (chdir (dir_name), "chdir \"%s\"", dir_name);
69 CHECK (i > 200, "created files and directories only to level %d", i);
72 msg ("removing all but top 10 levels of files and directories...");
76 char file_name[16], dir_name[16];
78 snprintf (file_name, sizeof file_name, "file%d", i);
79 snprintf (dir_name, sizeof dir_name, "dir%d", i);
80 CHECK (chdir (".."), "chdir \"..\"");
81 CHECK (remove (dir_name), "remove \"%s\"", dir_name);
82 CHECK (remove (file_name), "remove \"%s\"", file_name);