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

SDFS.info64 doesn't return the correct SD card capacity #8934

Open
4 tasks done
BrokeStudio opened this issue May 28, 2023 · 1 comment
Open
4 tasks done

SDFS.info64 doesn't return the correct SD card capacity #8934

BrokeStudio opened this issue May 28, 2023 · 1 comment

Comments

@BrokeStudio
Copy link

BrokeStudio commented May 28, 2023

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have searched the issue tracker for a similar issue.
  • I have filled out all fields below.

Platform

  • Hardware: ESP-12
  • Core Version: 3.1.2
  • Development Env: Platformio
  • Operating System: Windows

Settings in IDE

  • Module: Generic ESP8266 Module
  • Flash Mode: qio
  • Flash Size: 4MB
  • lwip Variant: not relevant
  • Reset Method: nodemcu
  • Flash Frequency: 40Mhz
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 921600

Problem Description

Using SDFS.info64() with a 32GB SD card doesn't return the SD card capacity.

I modified SDFS.h file, function bool info64(fs::FSInfo64& info) from this:

info.totalBytes =_fs.vol()->clusterCount() * info.blockSize;
info.usedBytes = (_fs.vol()->clusterCount() - _fs.vol()->freeClusterCount()) * info.blockSize;

to this:

info.totalBytes = (uint64_t)_fs.vol()->clusterCount() * (uint64_t)info.blockSize;
info.usedBytes = (uint64_t)(_fs.vol()->clusterCount() - _fs.vol()->freeClusterCount()) * (uint64_t)info.blockSize;

and it fixed the issue.
However, I'm not sure if it's the best fix.

MCVE Sketch

#include <Arduino.h>
#include <LittleFS.h>
#include <SD.h>

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

  if (!SDFS.begin())
  {
    Serial.println("Initialization failed!");
  }
  else
  {
    Serial.println("Initialization successful!");
    FSInfo64 sd_info;
    SDFS.info64(sd_info);
    Serial.print("Total space: ");
    Serial.printf("%02llX", (sd_info.totalBytes >> 56) & 0xff);
    Serial.printf("%02llX", (sd_info.totalBytes >> 48) & 0xff);
    Serial.printf("%02llX", (sd_info.totalBytes >> 40) & 0xff);
    Serial.printf("%02llX", (sd_info.totalBytes >> 32) & 0xff);
    Serial.printf("%02llX", (sd_info.totalBytes >> 24) & 0xff);
    Serial.printf("%02llX", (sd_info.totalBytes >> 16) & 0xff);
    Serial.printf("%02llX", (sd_info.totalBytes >> 8) & 0xff);
    Serial.printf("%02llX", sd_info.totalBytes & 0xff);
    Serial.println();
  }
}

void loop()
{
}

Debug Messages

Code above outputs this:

Initialization successful!
Total space: 000000006D880000

Once function info64 in file SDFS.h, it outputs this (which is the correct value):

Initialization successful!
Total space: 000000076D880000
@BrokeStudio
Copy link
Author

Seems to be related to issue #8445.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant