00001
00002
00003 #include <stdio.h>
00004 #include <syscall.h>
00005 #include "tests/filesys/extended/mk-tree.h"
00006 #include "tests/lib.h"
00007
00008 static void do_mkdir (const char *format, ...) PRINTF_FORMAT (1, 2);
00009 static void do_touch (const char *format, ...) PRINTF_FORMAT (1, 2);
00010
00011 void
00012 make_tree (int at, int bt, int ct, int dt)
00013 {
00014 char try[128];
00015 int a, b, c, d;
00016 int fd;
00017
00018 msg ("creating /0/0/0/0 through /%d/%d/%d/%d...",
00019 at - 1, bt - 1, ct - 1, dt - 1);
00020 quiet = true;
00021 for (a = 0; a < at; a++)
00022 {
00023 do_mkdir ("/%d", a);
00024 for (b = 0; b < bt; b++)
00025 {
00026 do_mkdir ("/%d/%d", a, b);
00027 for (c = 0; c < ct; c++)
00028 {
00029 do_mkdir ("/%d/%d/%d", a, b, c);
00030 for (d = 0; d < dt; d++)
00031 do_touch ("/%d/%d/%d/%d", a, b, c, d);
00032 }
00033 }
00034 }
00035 quiet = false;
00036
00037 snprintf (try, sizeof try, "/%d/%d/%d/%d", 0, bt - 1, 0, dt - 1);
00038 CHECK ((fd = open (try)) > 1, "open \"%s\"", try);
00039 msg ("close \"%s\"", try);
00040 close (fd);
00041 }
00042
00043 static void
00044 do_mkdir (const char *format, ...)
00045 {
00046 char dir[128];
00047 va_list args;
00048
00049 va_start (args, format);
00050 vsnprintf (dir, sizeof dir, format, args);
00051 va_end (args);
00052
00053 CHECK (mkdir (dir), "mkdir \"%s\"", dir);
00054 }
00055
00056 static void
00057 do_touch (const char *format, ...)
00058 {
00059 char file[128];
00060 va_list args;
00061
00062 va_start (args, format);
00063 vsnprintf (file, sizeof file, format, args);
00064 va_end (args);
00065
00066 CHECK (create (file, 0), "create \"%s\"", file);
00067 }