blob: 2b8559234e49e0fff4303a55386caba5e5f5e5c1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#include <stdint.h>
#include "drive.h"
#include "util.h"
#include "log.h"
static char nbuf2[11];
static char path_builder[200] = "";
static uint8_t path_builder_len = 0;
static char indent_builder[20] = " ";
static uint8_t indent_builder_len = 2;
void tree(struct drive *d) {
struct directory_content_info infos[100];
uint8_t n_infos = d->enumerate_dir(d, path_builder, infos, 100);
if (!n_infos) {
logsz(indent_builder);
logsz("(empty)\n");
return;
}
for (uint8_t i = 0; i < n_infos; ++i) {
logsz(indent_builder);
logsz(infos[i].name);
if (infos[i].is_dir) {
logsz(":\n");
indent_builder[indent_builder_len] = ' ';
indent_builder[indent_builder_len + 1] = ' ';
indent_builder[indent_builder_len + 2] = '\0';
indent_builder_len += 2;
uint8_t name_length = 0;
while (infos[i].name[name_length])
++name_length;
memcpy(path_builder + path_builder_len, infos[i].name, name_length + 1);
path_builder_len += name_length;
tree(d);
path_builder_len -= name_length;
path_builder[path_builder_len] = '\0';
indent_builder_len -= 2;
indent_builder[indent_builder_len] = '\0';
}
else {
u32_dec(infos[i].size, nbuf2);
logsz(" (");
logsz(nbuf2);
logsz(" bytes)\n");
}
}
}
|