4
4
5
5
void fail (const char * msg) {
6
6
Serial.println (msg);
7
- while (true ) {
7
+ while (true ) {
8
8
yield ();
9
9
}
10
10
}
@@ -15,6 +15,21 @@ void setup() {
15
15
WiFi.mode (WIFI_OFF);
16
16
Serial.println (" \n\n FS test\n " );
17
17
18
+ {
19
+ if (!SPIFFS.format ()) {
20
+ fail (" format failed" );
21
+ }
22
+ Dir root = SPIFFS.openDir (" /" );
23
+ int count = 0 ;
24
+ while (root.next ()) {
25
+ ++count;
26
+ }
27
+ if (count > 0 ) {
28
+ fail (" some files left after format" );
29
+ }
30
+ }
31
+
32
+
18
33
if (!SPIFFS.begin ()) {
19
34
fail (" SPIFFS init failed" );
20
35
}
@@ -63,15 +78,15 @@ void setup() {
63
78
{
64
79
Dir root = SPIFFS.openDir (" /" );
65
80
while (root.next ()) {
66
- String fileName = root.fileName ();
67
- File f = root.openFile (" r" );
68
- Serial.printf (" %s: %d\r\n " , fileName.c_str (), f.size ());
81
+ String fileName = root.fileName ();
82
+ File f = root.openFile (" r" );
83
+ Serial.printf (" %s: %d\r\n " , fileName.c_str (), f.size ());
69
84
}
70
85
}
71
86
72
87
{
73
88
Dir root = SPIFFS.openDir (" /" );
74
- while (root.next ()) {
89
+ while (root.next ()) {
75
90
String fileName = root.fileName ();
76
91
Serial.print (" deleting " );
77
92
Serial.println (fileName);
@@ -96,6 +111,20 @@ void setup() {
96
111
}
97
112
}
98
113
114
+ {
115
+ if (!SPIFFS.format ()) {
116
+ fail (" format failed" );
117
+ }
118
+ Dir root = SPIFFS.openDir (" /" );
119
+ int count = 0 ;
120
+ while (root.next ()) {
121
+ ++count;
122
+ }
123
+ if (count > 0 ) {
124
+ fail (" some files left after format" );
125
+ }
126
+ }
127
+
99
128
Serial.println (" success" );
100
129
}
101
130
0 commit comments