PKUOS - Pintos
Pintos source browser for PKU Operating System course
dir-rm-tree.c
Go to the documentation of this file.
1/** Creates directories /0/0/0 through /3/2/2 and files in the
2 leaf directories, then removes them. */
3
4#include <stdarg.h>
5#include <stdio.h>
6#include <syscall.h>
8#include "tests/lib.h"
9#include "tests/main.h"
10
11static void remove_tree (int at, int bt, int ct, int dt);
12
13void
14test_main (void)
15{
16 make_tree (4, 3, 3, 4);
17 remove_tree (4, 3, 3, 4);
18}
19
20static void do_remove (const char *format, ...) PRINTF_FORMAT (1, 2);
21
22static void
23remove_tree (int at, int bt, int ct, int dt)
24{
25 char try[128];
26 int a, b, c, d;
27
28 msg ("removing /0/0/0/0 through /%d/%d/%d/%d...",
29 at - 1, bt - 1, ct - 1, dt - 1);
30 quiet = true;
31 for (a = 0; a < at; a++)
32 {
33 for (b = 0; b < bt; b++)
34 {
35 for (c = 0; c < ct; c++)
36 {
37 for (d = 0; d < dt; d++)
38 do_remove ("/%d/%d/%d/%d", a, b, c, d);
39 do_remove ("/%d/%d/%d", a, b, c);
40 }
41 do_remove ("/%d/%d", a, b);
42 }
43 do_remove ("/%d", a);
44 }
45 quiet = false;
46
47 snprintf (try, sizeof (try), "/%d/%d/%d/%d", at - 1, 0, ct - 1, 0);
48 CHECK (open (try) == -1, "open \"%s\" (must return -1)", try);
49}
50
51static void
52do_remove (const char *format, ...)
53{
54 char name[128];
55 va_list args;
56
57 va_start (args, format);
58 vsnprintf (name, sizeof name, format, args);
59 va_end (args);
60
61 CHECK (remove (name), "remove \"%s\"", name);
62}
#define PRINTF_FORMAT(FMT, FIRST)
Definition: debug.h:10
static void do_remove(const char *format,...) PRINTF_FORMAT(1
Definition: dir-rm-tree.c:52
void test_main(void)
tests/main.h
Definition: dir-rm-tree.c:14
static void remove_tree(int at, int bt, int ct, int dt)
Creates directories /0/0/0 through /3/2/2 and files in the leaf directories, then removes them.
Definition: dir-rm-tree.c:23
char * name[]
Definition: insult.c:47
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
int open(const char *file)
Definition: syscall.c:103
bool remove(const char *file)
Definition: syscall.c:97
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 static void void make_tree(int at, int bt, int ct, int dt)
tests/filesys/extended/mk-tree.h
Definition: mk-tree.c:12
#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