PKUOS - Pintos
Pintos source browser for PKU Operating System course
mk-tree.c
Go to the documentation of this file.
1/** Library function for creating a tree of directories. */
2
3#include <stdio.h>
4#include <syscall.h>
6#include "tests/lib.h"
7
8static void do_mkdir (const char *format, ...) PRINTF_FORMAT (1, 2);
9static void do_touch (const char *format, ...) PRINTF_FORMAT (1, 2);
10
11void
12make_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
43static void
44do_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
56static void
57do_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}
#define PRINTF_FORMAT(FMT, FIRST)
Definition: debug.h:10
int vsnprintf(char *buffer, size_t buf_size, const char *format, va_list args)
Like vprintf(), except that output is stored into BUFFER, which must have space for BUF_SIZE characte...
Definition: stdio.c:26
int snprintf(char *buffer, size_t buf_size, const char *format,...)
Like printf(), except that output is stored into BUFFER, which must have space for BUF_SIZE character...
Definition: stdio.c:62
bool create(const char *file, unsigned initial_size)
Definition: syscall.c:91
void close(int fd)
Definition: syscall.c:139
int open(const char *file)
Definition: syscall.c:103
bool mkdir(const char *dir)
Definition: syscall.c:163
void msg(const char *format,...)
Definition: lib.c:28
bool quiet
Definition: lib.c:9
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
static void do_mkdir(const char *format,...) PRINTF_FORMAT(1
Library function for creating a tree of directories.
Definition: mk-tree.c:44
static void static void void make_tree(int at, int bt, int ct, int dt)
tests/filesys/extended/mk-tree.h
Definition: mk-tree.c:12
static void static void do_touch(const char *format,...) PRINTF_FORMAT(1
Definition: mk-tree.c:57
#define va_end(LIST)
Definition: stdarg.h:10
#define va_start(LIST, ARG)
Definition: stdarg.h:9
__builtin_va_list va_list
GCC has <stdarg.h> functionality as built-ins, so all we need is to use it.
Definition: stdarg.h:7
A directory.
Definition: directory.c:11
An open file.
Definition: file.c:8