Skip to content
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

When FFat is mounted before SD, then filesystem reports wrong system sizes #3546

Closed
ullix opened this issue Dec 8, 2019 · 4 comments
Closed
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@ullix
Copy link

ullix commented Dec 8, 2019

I use an ESP32 in Arduino environment (more precise: UECIDE). I use both the internal Flash (about 1.4MB) with FFat and an external SD card (32GB) with SD.

When I first mount the Flash with FFat, and then the SD with SD, all calls to totalBytes and freeBytes, usedBytes, resp., show only the values valid for FFat.

When I reverse the order of mounting, so doing SD first, then all comes out correct.

(Note: FFat can't do usedBytes, SD can't do freeBytes.)

#include "FS.h"
#include "FFat.h"
#include "SD.h"

void setup(){
    Serial.begin(115200);
    uint64_t totalB;    // total Bytes
    uint64_t freeB;     // free Bytes
    uint64_t usedB;     // used Bytes = total Bytes - free Bytes    
    uint64_t cardSize;  // only for SD: size of card

    //************ First ******************************************
    Serial.println("\nMounting FFat Flash");
    if (!FFat.begin(false)) {     
        Serial.println("An Error has occurred while mounting FFAT");
        return;
    }
    // end first **************************************************

    //************ Second *****************************************
    Serial.println("\nMounting SD card");
    if(!SD.begin()){
        Serial.println("Card Mount Failed");
        return;
    }
    //end second***************************************************
    
    Serial.println();
    
    totalB = SD .totalBytes();
    usedB  = SD .usedBytes();
    freeB  = totalB - usedB;   // no freeBytes in SD
    cardSize = SD.cardSize() / (1024 * 1024);    
    Serial.printf("SD: total: %llu,  free: %llu,  used: %llu, card size: %llu \n", totalB, freeB, usedB, cardSize);  
    
    totalB = FFat.totalBytes();
    freeB  = FFat.freeBytes();
    usedB  = totalB - freeB;    // no usedBytes in FFat
    Serial.printf("FFat: total: %llu,  free: %llu,  used: %llu \n", totalB, freeB, usedB);

    totalB = SD .totalBytes();
    usedB  = SD .usedBytes();
    freeB  = totalB - usedB;   // no freeBytes in SD
    cardSize = SD.cardSize() / (1024 * 1024);
    Serial.printf("SD: total: %llu,  free: %llu,  used: %llu, card size: %llu \n", totalB, freeB, usedB, cardSize);  
    
    totalB = FFat.totalBytes();
    freeB  = FFat.freeBytes();
    usedB  = totalB - freeB;    // no usedBytes in FFat
    Serial.printf("FFat: total: %llu,  free: %llu,  used: %llu \n", totalB, freeB, usedB);
}

void loop(){}

When the code is run as shown, the outcome is:


Mounting FFat Flash

Mounting SD card

SD: total: 1454080,  free: 4096,  used: 1449984, card size: 30735
FFat: total: 1454080,  free: 4096,  used: 1449984
SD: total: 1454080,  free: 4096,  used: 1449984, card size: 30735
FFat: total: 1454080,  free: 4096,  used: 1449984

Irrespective of whether SD or FFat is selected, only the FFat data are shown.

When the sections in the code marked 'First' and 'Second' are switched, then the outcome is this:

Mounting SD card

Mounting FFat Flash

SD: total: 32211189760,  free: 31970983936,  used: 240205824, card size: 30735
FFat: total: 1454080,  free: 4096,  used: 1449984
SD: total: 32211189760,  free: 31970983936,  used: 240205824, card size: 30735
FFat: total: 1454080,  free: 4096,  used: 1449984

This is the correct result!

@lbernstone
Copy link
Contributor

lbernstone commented Dec 8, 2019

Let me run some tests before I merge, but this should fix it.
https://github.com/lbernstone/arduino-esp32/blob/SD_pdrv/libraries/SD/src/SD.cpp

@stale
Copy link

stale bot commented Feb 6, 2020

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Feb 6, 2020
@stale
Copy link

stale bot commented Feb 20, 2020

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Feb 20, 2020
@holgerlembke
Copy link
Contributor

Needs to be opened again. Version 2.0.11

ffat first:
FFat.totalbytes(): 1392640 FFat.usedbytes(): 49152
SD.totalbytes(): 1392640 SD.usedbytes(): 49152

sd first:
FFat.totalbytes(): 1392640 FFat.usedbytes(): 49152
SD.totalbytes(): 1015267328 SD.usedbytes(): 73269248

// esp32 wrover module
#include <FS.h>
#include <SD.h>
#include <FFat.h>

void setup() {
  Serial.begin(115200);
  delay(1000);

  SD.begin(5);
  FFat.begin();

  Serial.print("FFat.totalbytes(): ");
  Serial.print(FFat.totalBytes());
  Serial.print(" FFat.usedbytes(): ");
  Serial.println(FFat.usedBytes());

  Serial.print("SD.totalbytes(): ");
  Serial.print(SD.totalBytes());
  Serial.print(" SD.usedbytes(): ");
  Serial.println(SD.usedBytes());
}

void loop() {}

me-no-dev pushed a commit that referenced this issue Aug 29, 2023
…sizes (#8520)

* Fixes wrong usedbytes/totalbytes results.

drive id was implemented fixed, does not work with arbitrary initialization.

See #3546

* Fixing indention/tabs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

3 participants