21
21
#include " FileSystem.h"
22
22
#include " Arduino.h"
23
23
24
- boolean FSClass::mount (){
25
- if (_mounted) return true ;
24
+ bool FSClass::mount () {
25
+ if (_mounted)
26
+ return true ;
27
+
26
28
_mounted = spiffs_mount ();
27
29
return _mounted;
28
30
}
29
31
30
- void FSClass::unmount (){
31
- if (!_mounted) return ;
32
+ void FSClass::unmount () {
33
+ if (!_mounted)
34
+ return ;
35
+
32
36
spiffs_unmount ();
33
37
_mounted = false ;
34
38
}
35
39
36
- boolean FSClass::format (){
40
+ bool FSClass::format () {
37
41
return spiffs_format ();
38
42
}
39
43
40
- boolean FSClass::exists (const char *filename){
44
+ bool FSClass::exists (const char *filename) {
41
45
spiffs_stat stat = {0 };
42
- if (SPIFFS_stat (&_filesystemStorageHandle, filename, &stat) < 0 ) return false ;
46
+ if (SPIFFS_stat (&_filesystemStorageHandle, filename, &stat) < 0 )
47
+ return false ;
43
48
return stat.name [0 ] != ' \0 ' ;
44
49
}
45
50
46
- boolean FSClass::create (const char *filepath){
51
+ bool FSClass::create (const char *filepath){
47
52
return SPIFFS_creat (&_filesystemStorageHandle, filepath, 0 ) == 0 ;
48
53
}
49
54
50
- boolean FSClass::remove (const char *filepath){
55
+ bool FSClass::remove (const char *filepath){
51
56
return SPIFFS_remove (&_filesystemStorageHandle, filepath) == 0 ;
52
57
}
53
58
54
- boolean FSClass::rename (const char *filename, const char *newname){
59
+ bool FSClass::rename (const char *filename, const char *newname) {
55
60
return SPIFFS_rename (&_filesystemStorageHandle, filename, newname) == 0 ;
56
61
}
57
62
58
- FSFile FSClass::open (const char *filename, uint8_t mode){
63
+ FSFile FSClass::open (const char *filename, uint8_t mode) {
59
64
int repeats = 0 ;
60
65
bool notExist;
61
66
bool canRecreate = (mode & SPIFFS_CREAT) == SPIFFS_CREAT;
@@ -81,25 +86,25 @@ FSFile FSClass::open(const char *filename, uint8_t mode){
81
86
82
87
FSClass FS;
83
88
84
- FSFile::FSFile (){
89
+ FSFile::FSFile () {
85
90
_file = 0 ;
86
91
_stats = {0 };
87
92
}
88
93
89
- FSFile::FSFile (file_t f){
94
+ FSFile::FSFile (file_t f) {
90
95
_file = f;
91
96
if (SPIFFS_fstat (&_filesystemStorageHandle, _file, &_stats) != 0 ){
92
97
debugf (" mount errno %d\n " , SPIFFS_errno (&_filesystemStorageHandle));
93
98
}
94
99
}
95
100
96
- void FSFile::close (){
101
+ void FSFile::close () {
97
102
if (! _file) return ;
98
103
SPIFFS_close (&_filesystemStorageHandle, _file);
99
104
_file = 0 ;
100
105
}
101
106
102
- uint32_t FSFile::size (){
107
+ uint32_t FSFile::size () {
103
108
if (! _file) return 0 ;
104
109
uint32_t pos = SPIFFS_tell (&_filesystemStorageHandle, _file);
105
110
SPIFFS_lseek (&_filesystemStorageHandle, _file, 0 , SPIFFS_SEEK_END);
@@ -108,31 +113,31 @@ uint32_t FSFile::size(){
108
113
return size;
109
114
}
110
115
111
- uint32_t FSFile::seek (uint32_t pos){
116
+ uint32_t FSFile::seek (uint32_t pos) {
112
117
if (! _file) return 0 ;
113
118
return SPIFFS_lseek (&_filesystemStorageHandle, _file, pos, SPIFFS_SEEK_SET);
114
119
}
115
120
116
- uint32_t FSFile::position (){
121
+ uint32_t FSFile::position () {
117
122
if (! _file) return 0 ;
118
123
return SPIFFS_tell (&_filesystemStorageHandle, _file);
119
124
}
120
125
121
- boolean FSFile::eof (){
126
+ bool FSFile::eof () {
122
127
if (! _file) return 0 ;
123
128
return SPIFFS_eof (&_filesystemStorageHandle, _file);
124
129
}
125
130
126
- boolean FSFile::isDirectory (void ){
131
+ bool FSFile::isDirectory (void ) {
127
132
return false ;
128
133
}
129
134
130
- int FSFile::read (void *buf, uint16_t nbyte){
135
+ int FSFile::read (void *buf, uint16_t nbyte) {
131
136
if (! _file) return -1 ;
132
137
return SPIFFS_read (&_filesystemStorageHandle, _file, buf, nbyte);
133
138
}
134
139
135
- int FSFile::read (){
140
+ int FSFile::read () {
136
141
if (! _file) return -1 ;
137
142
int val;
138
143
if (SPIFFS_read (&_filesystemStorageHandle, _file, &val, 1 ) != 1 ) return -1 ;
0 commit comments