Skip to content

Preferences freeEntries() returns same number regardless of partition size. #11400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
ankgt opened this issue May 25, 2025 · 2 comments
Closed
1 task done
Labels
Status: Awaiting triage Issue is waiting for triage

Comments

@ankgt
Copy link

ankgt commented May 25, 2025

Board

ESP32 Dev Module

Device Description

I am using the official ESP32 Dev Module with a 4MB flash.

Hardware Configuration

None

Version

v2.0.17

IDE Name

VSCode

Operating System

macOS

Flash frequency

40Mhz

PSRAM enabled

yes

Upload speed

115200

Description

I have been using the prefs library with a custom partition table for a while now using a nvs partition named 'nvs' with size 0x5000.

I needed a larger parition, so have created a new partition table where i have a second nvs partition named 'nvs2' with a size 0x40000.

I have attached both tables for your reference.

partitions_custom_old.csv
partitions_custom.csv

Earlier I used to initialize the prefs using:

bool flagSuccess = prefs.begin("w2", false);

I now initialize as follows:

bool flagSuccess = prefs.begin("w2", false, "nvs2");

The issue is that after initializing if I call the prefs.freeEntries() function, in BOTH cases it returns the same number of free entries: about 630.

I tested both by first doing a full clean in platformio and then erasing the flash of the device.

The number 630 is what is reported on the first boot up (after erasing the flash and loading the firmware) using the following code:

size_t entriesAvailable = prefs.freeEntries(); Serial.print("SETTINGS_DEBUG: Entries available: "); Serial.println(entriesAvailable);

I am not able to figure out why the much larger 'nvs2' is still leading to the same amount of free entries.

Sketch

void SettingsSetup(void) {
    // Initialize the preferences.
    bool flagSuccess = prefs.begin("w2", false, "nvs2");
    if (!flagSuccess) {
        Serial.println(F("SETTINGS_ERROR: Unable to load prefs partition!!!"));
    }

    // Get free entries.
    if (true) {
        size_t entriesAvailable = prefs.freeEntries();
        Serial.print("SETTINGS_DEBUG: Entries available: ");
        Serial.println(entriesAvailable);
    }
}

Debug Message

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13232
load:0x40080400,len:3028
entry 0x400805e4
SETTINGS_DEBUG: Entries available: 630

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@ankgt ankgt added the Status: Awaiting triage Issue is waiting for triage label May 25, 2025
@ankgt ankgt changed the title prefs.freeEntires returns same number regardless of partition size. Preferences freeEntires returns same number regardless of partition size. May 25, 2025
@ankgt ankgt changed the title Preferences freeEntires returns same number regardless of partition size. Preferences freeEntries() returns same number regardless of partition size. May 25, 2025
@lbernstone
Copy link
Contributor

freeEntries has to do with available handles, not free space. Last time I looked at this, there was no way to check the amount of free space other than attempting the write and catching the error.

@me-no-dev
Copy link
Member

Closing as answered and also because 2.x versions are no longer supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting triage Issue is waiting for triage
Projects
None yet
Development

No branches or pull requests

3 participants