Skip to content

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

Open
@BrokeStudio

Description

@BrokeStudio

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions