Skip to content

Commit 8b67495

Browse files
authored
Merge pull request #640 from bdring/Devt
Devt
2 parents e348ddb + b7bcee6 commit 8b67495

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3782
-1279
lines changed

.github/ISSUE_TEMPLATE/config.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
blank_issues_enabled: false
22
contact_links:
33
- name: General Questions
4-
url: https://github.com/bdring/FluidNC/wiki/General-Questions
5-
about: Please read our documentation which answers many questions
4+
url: http://wiki.fluidnc.com/
5+
about: Please read our wiki which answers many questions
66
- name: Discord server
77
url: https://discord.com/invite/vGhne3QmFZ
88
about: Please ask and answer questions on our Discord server.

FluidNC/data/index.html.gz

89 Bytes
Binary file not shown.

FluidNC/esp32/littlefs.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "esp_partition.h"
2+
#include "esp_littlefs.h"
3+
#include "esp_log.h"
4+
#include "wdt.h"
5+
#include "Driver/localfs.h"
6+
#include "src/Logging.h"
7+
8+
// Remember the partition label of the littlefs filesystem -
9+
// typically littlefs or spiffs - so we can pass it to esp_littlefs_info
10+
const char* littlefs_label;
11+
12+
bool littlefs_format(const char* partition_label) {
13+
esp_log_level_set("esp_littlefs", ESP_LOG_NONE);
14+
esp_err_t err;
15+
disable_core0_WDT();
16+
err = esp_littlefs_format(partition_label);
17+
enable_core0_WDT();
18+
if (err) {
19+
log_debug("LittleFS format in " << partition_label << " partition failed: " << esp_err_to_name(err));
20+
return true;
21+
}
22+
return false;
23+
}
24+
25+
bool littlefs_mount(const char* label, bool format) {
26+
esp_log_level_set("esp_littlefs", ESP_LOG_NONE);
27+
esp_vfs_littlefs_conf_t conf = { .base_path = "/littlefs", .partition_label = label, .format_if_mount_failed = format };
28+
29+
esp_err_t err = esp_vfs_littlefs_register(&conf);
30+
31+
if (!err) {
32+
littlefs_label = label;
33+
}
34+
return err;
35+
}
36+
void littlefs_unmount() {
37+
esp_vfs_littlefs_unregister(littlefs_label);
38+
}

FluidNC/esp32/localfs.cpp

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#include "Driver/localfs.h"
2+
#include "Driver/spiffs.h" // spiffs_format
3+
#include "Driver/littlefs.h" // littlefs_format
4+
#include <cstddef> // NULL
5+
#include <cstring>
6+
#include "src/Logging.h"
7+
#include "esp_partition.h"
8+
9+
const char* localfsName = NULL;
10+
11+
static bool has_partition(const char* label) {
12+
auto part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, label);
13+
return part != NULL;
14+
}
15+
16+
bool localfs_mount() {
17+
if (has_partition(spiffsName)) {
18+
if (!spiffs_mount(spiffsName, false)) {
19+
localfsName = spiffsName;
20+
return false;
21+
}
22+
// Migration - littlefs in spiffs partition
23+
if (!littlefs_mount(spiffsName, false)) {
24+
localfsName = littlefsName;
25+
return false;
26+
}
27+
// Try to create a SPIFFS filesystem
28+
if (!spiffs_mount(spiffsName, true)) {
29+
localfsName = spiffsName;
30+
return false;
31+
}
32+
log_error("Cannot mount or create a local filesystem in the spiffs partition");
33+
return true;
34+
}
35+
if (has_partition(littlefsName)) {
36+
// Mount LittleFS, create if necessary
37+
if (!littlefs_mount(littlefsName, true)) {
38+
localfsName = littlefsName;
39+
return false;
40+
}
41+
log_error("Cannot mount or create a local filesystem in the littlefs partition");
42+
return true;
43+
}
44+
log_error("The partition map has neither a spiffs partition nor a littlefs partition");
45+
return true;
46+
}
47+
void localfs_unmount() {
48+
if (localfsName == spiffsName) {
49+
spiffs_unmount();
50+
return;
51+
}
52+
if (localfsName == littlefsName) {
53+
littlefs_unmount();
54+
return;
55+
}
56+
localfsName = NULL;
57+
}
58+
bool localfs_format(const char* fsname) {
59+
if (!strcasecmp(fsname, "format") || !strcasecmp(fsname, "localfs")) {
60+
fsname = defaultLocalfsName;
61+
}
62+
if (!strcasecmp(fsname, spiffsName)) {
63+
localfs_unmount();
64+
if (!spiffs_format(spiffsName)) {
65+
if (!spiffs_mount(spiffsName)) {
66+
localfsName = spiffsName;
67+
return false;
68+
}
69+
}
70+
}
71+
if (!strcasecmp(fsname, littlefsName)) {
72+
localfs_unmount();
73+
if (!littlefs_format(littlefsName)) {
74+
if (!littlefs_mount(littlefsName)) {
75+
localfsName = littlefsName;
76+
return false;
77+
}
78+
}
79+
log_debug("Trying LittleFS in spiffs partition");
80+
if (!littlefs_format(spiffsName)) {
81+
if (!littlefs_mount(spiffsName)) {
82+
localfsName = littlefsName;
83+
return false;
84+
}
85+
}
86+
localfs_mount();
87+
return true;
88+
}
89+
localfsName = "";
90+
return true;
91+
}
92+
93+
uint64_t localfs_size() {
94+
std::error_code ec;
95+
96+
auto space = std::filesystem::space(localfsName, ec);
97+
if (ec) {
98+
return 0;
99+
}
100+
return space.capacity;
101+
}
102+
103+
static void insertFsName(char* s, const char* prefix) {
104+
size_t slen = strlen(s);
105+
size_t plen = strlen(prefix);
106+
memmove(s + 1 + plen, s, slen + 1);
107+
memmove(s + 1, prefix, plen);
108+
*s = '/';
109+
}
110+
111+
static bool replacedFsName(char* s, const char* replaced, const char* with) {
112+
if (*s != '/') {
113+
return false;
114+
}
115+
116+
char* head = s + 1;
117+
const char* tail = strchrnul(head, '/'); // tail string after prefix
118+
size_t plen = tail - head; // Prefix length
119+
size_t rlen = strlen(replaced); // replaced length
120+
121+
if (plen != rlen) {
122+
return false;
123+
}
124+
125+
if (strncasecmp(head, replaced, rlen) == 0) {
126+
// replaced matches the prefix of s
127+
128+
size_t tlen = strlen(tail);
129+
size_t wlen = strlen(with);
130+
131+
if (wlen != rlen) {
132+
// Move tail to new location
133+
memmove(head + wlen, tail, tlen + 1);
134+
}
135+
136+
// Insert with at the beginning
137+
memmove(head, with, wlen);
138+
return true;
139+
}
140+
return false;
141+
}
142+
143+
const char* canonicalPath(const char* filename, const char* defaultFs) {
144+
static char path[128];
145+
strncpy(path, filename, 128);
146+
147+
// log_debug("filename is " << filename << " deffs " << defaultFs);
148+
149+
// Map file system names to canonical form. The input name is case-independent,
150+
// while the canonical name is lower case.
151+
if (!(replacedFsName(path, "localfs", localfsName) || replacedFsName(path, spiffsName, localfsName) ||
152+
replacedFsName(path, littlefsName, localfsName) ||
153+
// The following looks like a no-op but it is not because of case independence
154+
replacedFsName(path, sdName, sdName))) {
155+
if (*filename != '/') {
156+
insertFsName(path, "");
157+
}
158+
// path now begins with /
159+
if (!strcmp(defaultFs, "")) {
160+
// If the default filesystem is empty, insert
161+
// the local file system prefix
162+
insertFsName(path, localfsName);
163+
} else {
164+
// If the default filesystem is not empty, insert
165+
// the defaultFs name as the mountpoint name
166+
insertFsName(path, defaultFs);
167+
}
168+
}
169+
// log_debug("path is " << path);
170+
return path;
171+
}

0 commit comments

Comments
 (0)