Current Lua downloadable firmware will be posted here

User avatar
By dpwhittaker
#10506 You have to put it in the #ifdef spiffs section. Make sure it is below the extern spiffs fs (from memory, could be off a bit).

You also have to expose it to lua in the macros at the bottom of the file.
User avatar
By raz123
#10515
dpwhittaker wrote:I wrote an extension to file to report the total space and the free space, and got some interesting results.


Well done. Have you considered pushing this to the nodemcu github?
User avatar
By dpwhittaker
#10536 I'm still not sure it is accurate... I can't seem to get freespace to zero. When I get below 60k freespace, I'll write a 10k file, but the freespace will only drop by 3k. There doesn't seem to be a strong correlation between the totalspace - freespace and the sum of file sizes. All these symptoms tell me I am missing something in my calculation. Perhaps deleted pages need to be factored in somehow.

When I finish my current project (the lhttpd port), I'll switch back to this and put on my hardhat and go spelunking through the spiffs source.
User avatar
By pellepl
#11176 Hi,

small explanation, there are three things to remember:

* spiffs can only write to free pages
* pages in a block become free when a block is erased
* spiffs must always have two blocks of free sectors

When the filesystem contains only two blocks worth of free pages (the rest of pages are busy or deleted), spiffs will try to garbage collect. This means finding a block with mostly deleted pages (preferably only deleted pages), move all busy pages within this block and then erase the block, making all pages in the block free.

So, to calculate "free space" one should sum up [all free pages + all deleted pages - 2*(block of free pages)] - here you'd get number of pages that are available for writing.

The two spare free blocks are needed to ensure successful garbage collections (where spiffs needs free space to move busy pages) and file system check.

Perhaps I should simply add a SPIFFS_info(..) giving all info you need... ;)

Cheers / Peter