|
@@ -21,35 +21,64 @@
|
21
|
21
|
*/
|
22
|
22
|
|
23
|
23
|
#include "lwip/apps/httpd.h"
|
|
24
|
+#include "lwip/apps/fs.h"
|
|
25
|
+#include "ff.h"
|
|
26
|
+
|
|
27
|
+#include <string.h>
|
24
|
28
|
|
25
|
29
|
#include "config.h"
|
26
|
30
|
#include "log.h"
|
|
31
|
+#include "debug_disk.h"
|
27
|
32
|
#include "http.h"
|
28
|
33
|
|
29
|
34
|
void http_init(void) {
|
30
|
35
|
httpd_init();
|
31
|
36
|
}
|
32
|
37
|
|
33
|
|
-#include "lwip/apps/fs.h"
|
34
|
|
-#include <string.h>
|
35
|
|
-
|
36
|
38
|
int fs_open_custom(struct fs_file *file, const char *name) {
|
37
|
|
- // TODO hook up to fat fs
|
38
|
|
- if (strcmp(name, "/src.tar.xz") == 0) {
|
39
|
|
- /*
|
|
39
|
+ debug("'%s'", name);
|
|
40
|
+
|
|
41
|
+ // TODO only do this when not mounted via USB
|
|
42
|
+ debug_disk_mount();
|
|
43
|
+
|
|
44
|
+ FIL f;
|
|
45
|
+ FRESULT r = f_open (&f, name, FA_READ);
|
|
46
|
+ if (r == FR_OK) {
|
|
47
|
+ FSIZE_t len = f_size(&f);
|
|
48
|
+ char *data = malloc(len);
|
|
49
|
+ if (!data) {
|
|
50
|
+ debug("error: not enough memory");
|
|
51
|
+ f_close(&f);
|
|
52
|
+ debug_disk_unmount();
|
|
53
|
+ return 0;
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ UINT read_count = 0;
|
|
57
|
+ r = f_read(&f, data, len, &read_count);
|
|
58
|
+ if ((r != FR_OK) || (read_count != len)) {
|
|
59
|
+ debug("invalid read: %d %d %ld", r, read_count, len);
|
|
60
|
+ }
|
|
61
|
+
|
40
|
62
|
memset(file, 0, sizeof(struct fs_file));
|
41
|
|
- file->data = (const char *)data_tar_xz;
|
42
|
|
- file->len = data_tar_xz_len;
|
|
63
|
+ file->data = data;
|
|
64
|
+ file->len = len;
|
43
|
65
|
file->index = file->len;
|
44
|
66
|
file->flags = FS_FILE_FLAGS_HEADER_PERSISTENT;
|
|
67
|
+
|
|
68
|
+ f_close(&f);
|
|
69
|
+ debug_disk_unmount();
|
45
|
70
|
return 1;
|
46
|
|
- */
|
47
|
|
- (void)file;
|
48
|
|
- return 0;
|
49
|
71
|
}
|
|
72
|
+
|
|
73
|
+ debug_disk_unmount();
|
50
|
74
|
return 0;
|
51
|
75
|
}
|
52
|
76
|
|
53
|
77
|
void fs_close_custom(struct fs_file *file) {
|
54
|
|
- (void)file;
|
|
78
|
+ debug("len=%d", file->len);
|
|
79
|
+
|
|
80
|
+ if (file && file->data) {
|
|
81
|
+ free((void *)file->data);
|
|
82
|
+ file->data = NULL;
|
|
83
|
+ }
|
55
|
84
|
}
|