LittleFS free space

I just ask wether littlefs on waveshare_rp2040_pizero shall be configured or else, because when i do:

FSInfo *info;
LittleFS.info(*info);

The value at info->totalBytes is always default value=537140992
So, i am afraid i will end up writing ouside real area.

My board definition:

[env:pico_nodebug_16MB]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git 
board = waveshare_rp2040_pizero
framework = arduino
board_build.core = earlephilhower
board_build.filesystem_size = 5m
board_build.filesystem = littlefs
board_build.partitions = partitions.csv
build_flags = -O3

Thanks in advence, best regards.

LittleFS.info takes a reference to a FSInfo struct as parameter. See

Therefore the code must be

FSInfo info;
LittleFS.info(info);

A wonder why no crash happened.

2 Likes

If we want to be really pedantic we can also zero-init the struct first, use that as the FSInfo& (“reference”, aka just a variable name) and compute the free (approximate) space, or rather the size of the unused blocks as:

FSInfo info {};
LittleFS.info(info);
Serial.println("LittleFS free bytes: " + String(info.totalBytes - info.usedBytes));
1 Like