SDFS.info64 doesn't return the correct SD card capacity
- Dominant language
- C++
- Stars
- 16.7k
- Forks
- 13.1k
- PR merge metrics
- No merged PRs in 30d
Description
### Basic Infos
- [X] This issue complies with the [issue POLICY doc](https://github.com/esp8266/Arduino/blob/master/POLICY.md).
- [X] I have read the documentation at [readthedocs](https://arduino-esp8266.readthedocs.io/en/latest) and the issue is not addressed there.
- [X] I have searched the issue tracker for a similar issue.
- [X] 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:
```cpp
info.totalBytes =_fs.vol()->clusterCount() * info.blockSize;
info.usedBytes = (_fs.vol()->clusterCount() - _fs.vol()->freeClusterCount()) * info.blockSize;
```
to this:
```cpp
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](https://stackoverflow.com/help/mcve) Sketch
```cpp
#include
#include
#include
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
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.