random: Fix behavior of kernel option "-rs".
[pintos-anon] / src / tests / filesys / extended / mk-tree.c
1 /* Library function for creating a tree of directories. */
2
3 #include <stdio.h>
4 #include <syscall.h>
5 #include "tests/filesys/extended/mk-tree.h"
6 #include "tests/lib.h"
7
8 static void do_mkdir (const char *format, ...) PRINTF_FORMAT (1, 2);
9 static void do_touch (const char *format, ...) PRINTF_FORMAT (1, 2);
10
11 void
12 make_tree (int at, int bt, int ct, int dt) 
13 {
14   char try[128];
15   int a, b, c, d;
16   int fd;
17
18   msg ("creating /0/0/0/0 through /%d/%d/%d/%d...",
19        at - 1, bt - 1, ct - 1, dt - 1);
20   quiet = true;
21   for (a = 0; a < at; a++) 
22     {
23       do_mkdir ("/%d", a);
24       for (b = 0; b < bt; b++) 
25         {
26           do_mkdir ("/%d/%d", a, b);
27           for (c = 0; c < ct; c++) 
28             {
29               do_mkdir ("/%d/%d/%d", a, b, c);
30               for (d = 0; d < dt; d++)
31                 do_touch ("/%d/%d/%d/%d", a, b, c, d);
32             }
33         }
34     }
35   quiet = false;
36
37   snprintf (try, sizeof try, "/%d/%d/%d/%d", 0, bt - 1, 0, dt - 1);
38   CHECK ((fd = open (try)) > 1, "open \"%s\"", try);
39   msg ("close \"%s\"", try);
40   close (fd);
41 }
42
43 static void
44 do_mkdir (const char *format, ...) 
45 {
46   char dir[128];
47   va_list args;
48
49   va_start (args, format);
50   vsnprintf (dir, sizeof dir, format, args);
51   va_end (args);
52
53   CHECK (mkdir (dir), "mkdir \"%s\"", dir);
54 }
55
56 static void
57 do_touch (const char *format, ...)
58 {
59   char file[128];
60   va_list args;
61
62   va_start (args, format);
63   vsnprintf (file, sizeof file, format, args);
64   va_end (args);
65
66   CHECK (create (file, 0), "create \"%s\"", file);
67 }