Skip to content

Commit 2487e22

Browse files
Remove global, make metadata length a member of FS
1 parent aa0b7ae commit 2487e22

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

cores/esp8266/spiffs/spiffs.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ typedef struct spiffs_t {
291291
void *user_data;
292292
// config magic
293293
u32_t config_magic;
294+
// active metadata length
295+
u32_t obj_meta_len;
294296
} spiffs;
295297

296298
/* spiffs file status struct */
@@ -300,7 +302,7 @@ typedef struct {
300302
spiffs_obj_type type;
301303
spiffs_page_ix pix;
302304
u8_t name[SPIFFS_OBJ_NAME_LEN];
303-
u8_t meta[4]; // Set to the largest supported metadata len
305+
u8_t meta[SPIFFS_MAX_META]; // Set to the largest supported metadata len
304306
} spiffs_stat;
305307

306308
struct spiffs_dirent {
@@ -309,7 +311,7 @@ struct spiffs_dirent {
309311
spiffs_obj_type type;
310312
u32_t size;
311313
spiffs_page_ix pix;
312-
u8_t meta[4]; // Set to the largest supported metadata len
314+
u8_t meta[SPIFFS_MAX_META]; // Set to the largest supported metadata len
313315
};
314316

315317
typedef struct {

cores/esp8266/spiffs/spiffs_config.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ typedef uint8_t u8_t;
2828

2929
// Enable supporting both timestamped and non-timestamped FS images by making
3030
// the meta-len a global variable here and by changing the logic of SPIFFS.begin.
31-
extern int __SPIFFS_obj_meta_len;
32-
#define SPIFFS_OBJ_META_LEN (__SPIFFS_obj_meta_len)
31+
#define SPIFFS_OBJ_META_LEN (fs->obj_meta_len)
3332
#define SPIFFS_MAX_META (4) // Maximum metadata size allowed at runtime
3433
// Because SPIFFS reads binary images of blocks, we need to be sure to actually ensure there is space to
3534
// keep the metadata (since 0 bytes are allocated in the struct itself). Use an anonymous union to ensure

cores/esp8266/spiffs_api.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
using namespace fs;
2727

28-
int __SPIFFS_obj_meta_len = 0;
29-
3028
namespace spiffs_impl {
3129

3230

@@ -54,7 +52,7 @@ FileImplPtr SPIFFSImpl::open(const char* path, OpenMode openMode, AccessMode acc
5452
fd, path, openMode, accessMode, _fs.err_code);
5553
return FileImplPtr();
5654
}
57-
if (!(mode & SPIFFS_O_RDONLY) && __SPIFFS_obj_meta_len==sizeof(4)) {
55+
if (!(mode & SPIFFS_O_RDONLY) && _fs.obj_meta_len) {
5856
time_t t = time(NULL);
5957
struct tm tmr;
6058
localtime_r(&t, &tmr);

cores/esp8266/spiffs_api.h

+7-8
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ extern "C" {
3939

4040
using namespace fs;
4141

42-
extern int __SPIFFS_obj_meta_len;
4342
namespace spiffs_impl {
4443

4544
int getSpiffsMode(OpenMode openMode, AccessMode accessMode);
@@ -273,8 +272,8 @@ class SPIFFSImpl : public FSImpl
273272
}
274273
}
275274
// Make sure we format with requested metadata len
276-
__SPIFFS_obj_meta_len = _cfg._enableTime ? 4 : 0;
277-
DEBUGV("SPIFFSImpl::_formatOldOrNew formatting with metadata==%d\r\n", __SPIFFS_obj_meta_len);
275+
_fs.obj_meta_len = _cfg._enableTime ? 4 : 0;
276+
DEBUGV("SPIFFSImpl::_formatOldOrNew formatting with metadata==%d\r\n", _fs.obj_meta_len);
278277
spiffs_config config = _setupSpiffsConfig(_cfg._enableTime);
279278

280279
// We need to try a mount on SPIFFS, even though it will probably fail, to make the opaque
@@ -326,18 +325,18 @@ class SPIFFSImpl : public FSImpl
326325
// First, can we mount w/o metadata (preserve backwards)
327326
int err;
328327
if ( !_is_metadata_fs(_start, _blockSize, _pageSize) ) {
329-
__SPIFFS_obj_meta_len = 0;
328+
_fs.obj_meta_len = 0;
330329
DEBUGV("SPIFFSImpl: trying fs @%x, size=%x, block=%x, page=%x, metadata=%d\r\n",
331-
_start, _size, _blockSize, _pageSize, __SPIFFS_obj_meta_len);
330+
_start, _size, _blockSize, _pageSize, _fs.obj_meta_len);
332331
err = SPIFFS_mount(&_fs, &config, _workBuf.get(),
333332
_fdsBuf.get(), fdsBufSize, _cacheBuf.get(), cacheBufSize,
334333
&SPIFFSImpl::_check_cb);
335334
} else {
336335
// Flag matched, it's a metadata FS
337-
__SPIFFS_obj_meta_len = 4;
336+
_fs.obj_meta_len = 4;
338337
config = _setupSpiffsConfig(true);
339338
DEBUGV("SPIFFSImpl: doesn't look like old metadata==0, so trying fs @%x, size=%x, block=%x, page=%x, metadata=%d\r\n",
340-
_start, _size, _blockSize, _pageSize, __SPIFFS_obj_meta_len);
339+
_start, _size, _blockSize, _pageSize, _fs.obj_meta_len);
341340
err = SPIFFS_mount(&_fs, &config, _workBuf.get(),
342341
_fdsBuf.get(), fdsBufSize, _cacheBuf.get(), cacheBufSize,
343342
&SPIFFSImpl::_check_cb);
@@ -573,7 +572,7 @@ class SPIFFSFileImpl : public FileImpl
573572
{
574573
CHECKFD();
575574
time_t t = 0;
576-
if (__SPIFFS_obj_meta_len) {
575+
if (_fs->getFs()->obj_meta_len) {
577576
_getStat() ;
578577
memcpy(&t, _stat.meta, sizeof(time_t));
579578
}

0 commit comments

Comments
 (0)