SdFat, initial file size insufficient, any method to autoextend beyond the end?

Hello all,

I can create a file of any size, the absolute size of the file is not the issue, what I would like to know, if I create a 2MB file but then end up writing beyond the end of the current file, file position wraps back to the start of the current file, I want to know is there a mode whereby the file size gets extended?

I am using the O_RDRW attribute to open the file, and I require random access within the file, so would I be right in thinking O_APPEND is not the answer?

Thanks.

Regards,

Graham

You didn't provide code so I can only guess what is happening.

If you open an existing file with O_RDWR, the file position will be at the beginning of the file.

The Arduino SD.h wrapper for SdFat has a hidden seek to EOF if you open a file for write.

 if (mode & (O_APPEND | O_WRITE)) 
    file.seekSet(file.fileSize());

If you want to open a file for write at end-of-file like SD.h use these flags and your writes will extend the file.

 file.open(fname, O_RDWR | O_CREAT | O_AT_END);

SdFat also provides these symbols.

//------------------------------------------------------------------------------
/** Arduino SD.h style flag for open for read. */
#define FILE_READ O_READ
/** Arduino SD.h style flag for open at EOF for read/write with create. */
#define FILE_WRITE (O_RDWR | O_CREAT | O_AT_END)