SdFat for 1.0.4

I have posted a new version of SdFat for Arduino 1.0.4 as

The standard avr-libc version of malloc() has been replaced in 1.0.4 to fix a long standing bug.

The new Arduino version of malloc() is not compatible with standard avr-gcc/avr-libc versions of malloc().

The new Arduino malloc() will break several libraries that calculate free RAM and will not work with multi-threaded schedulers and RTOSs.

So except for malloc() (which I've never used) its good to go? And the malloc() thing is an Arduino thing and Not caused by SDFat?

The new malloc() breaks things that don't use malloc(). SdFat does not use malloc().

Functions that determine memory usage can cause problems. These functions may access a global variable, __malloc_heap_start, that causes a conflict with the new malloc().

The problem with SdFat was a small utility function, FreeRam(), that returns the amount of free stack space.

Hi! I used SdFat a long ago and by then it was very fast to open files by dir index.

Now we still have this function, but how to determine this index? The variable dirIndex_ is private and there isn't the function dirIndex()

I plan to store the indexes for a few files in a matrix and access them when some buttons are pushed



I though no one used open by index. It seemed to be an idea that never was used.

The private variable dirIndex_ is only the low bits of the required index.

The required index is the position of the directory entry in the directory file divided by 32.

Here is an example that determines the directory index of a file, opens the file by index, and prints the file contents.

 * Open a file by index.  Use an SD card with the file "TEST.TXT" 
 * in the root directory.
#include <SdFat.h>

// SD chip select pin
const uint8_t chipSelect = SS;

// file system object
SdFat sd;

SdFile file;
void setup() {
  while (!Serial) {} // wait for Leonardo
  // Initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();

  // You can use any directory file.  Root is used in this case.
  // The volume working directory, vwd, is root
  if (!, "TEST.TXT", O_READ)) {
    Serial.println("open by name failed");
  // Index of file is position of directory entry divided by 32.
  // After open, directory file is positioned just after entry so subtract one.
  uint16_t index = sd.vwd()->curPosition()/32 - 1;
  if (!, index, O_READ)) {
    Serial.println("open by index failed");
  int c;
  while ((c = >= 0) Serial.write((char)c);
void loop() {}

The program should print the text in “TEST.TXT” followed by “Done!” like this.

Test text.