|
@@ -31,13 +31,47 @@
|
31
|
31
|
#include "debug_disk.h"
|
32
|
32
|
#include "http.h"
|
33
|
33
|
|
|
34
|
+static char *fs_log_write_buf = NULL;
|
|
35
|
+static size_t fs_log_write_count = 0;
|
|
36
|
+static size_t fs_log_write_len = 0;
|
|
37
|
+
|
34
|
38
|
void http_init(void) {
|
35
|
39
|
httpd_init();
|
36
|
40
|
}
|
37
|
41
|
|
|
42
|
+static void fs_log_write(const void *b, size_t l) {
|
|
43
|
+ if ((fs_log_write_count + l) > fs_log_write_len) {
|
|
44
|
+ l = fs_log_write_len - fs_log_write_count;
|
|
45
|
+ }
|
|
46
|
+ memcpy(fs_log_write_buf + fs_log_write_count, b, l);
|
|
47
|
+ fs_log_write_count += l;
|
|
48
|
+}
|
|
49
|
+
|
38
|
50
|
int fs_open_custom(struct fs_file *file, const char *name) {
|
39
|
51
|
debug("'%s'", name);
|
40
|
52
|
|
|
53
|
+ if (strcmp(name, "/log.json") == 0) {
|
|
54
|
+ size_t log_len = rb_len(log_get());
|
|
55
|
+ char *log = malloc(log_len);
|
|
56
|
+ if (!log) {
|
|
57
|
+ debug("error: not enough memory %d", log_len);
|
|
58
|
+ return 0;
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ fs_log_write_buf = log;
|
|
62
|
+ fs_log_write_count = 0;
|
|
63
|
+ fs_log_write_len = log_len;
|
|
64
|
+ rb_dump(log_get(), fs_log_write, 0);
|
|
65
|
+
|
|
66
|
+ memset(file, 0, sizeof(struct fs_file));
|
|
67
|
+ file->pextension = "/log.json";
|
|
68
|
+ file->data = log;
|
|
69
|
+ file->len = log_len;
|
|
70
|
+ file->index = file->len;
|
|
71
|
+ file->flags = FS_FILE_FLAGS_HEADER_PERSISTENT;
|
|
72
|
+ return 1;
|
|
73
|
+ }
|
|
74
|
+
|
41
|
75
|
// TODO only do this when not mounted via USB
|
42
|
76
|
debug_disk_mount();
|
43
|
77
|
|
|
@@ -47,7 +81,7 @@ int fs_open_custom(struct fs_file *file, const char *name) {
|
47
|
81
|
FSIZE_t len = f_size(&f);
|
48
|
82
|
char *data = malloc(len);
|
49
|
83
|
if (!data) {
|
50
|
|
- debug("error: not enough memory");
|
|
84
|
+ debug("error: not enough memory %ld", len);
|
51
|
85
|
f_close(&f);
|
52
|
86
|
debug_disk_unmount();
|
53
|
87
|
return 0;
|
|
@@ -60,6 +94,7 @@ int fs_open_custom(struct fs_file *file, const char *name) {
|
60
|
94
|
}
|
61
|
95
|
|
62
|
96
|
memset(file, 0, sizeof(struct fs_file));
|
|
97
|
+ file->pextension = NULL;
|
63
|
98
|
file->data = data;
|
64
|
99
|
file->len = len;
|
65
|
100
|
file->index = file->len;
|