This is from SdFile.cpp:
* O_READ - Open for reading.
* O_RDONLY - Same as O_READ.
* O_WRITE - Open for writing.
* O_WRONLY - Same as O_WRITE.
* O_RDWR - Open for reading and writing.
* O_APPEND - If set, the file offset shall be set to the end of the
* file prior to each write.
* O_CREAT - If the file exists, this flag has no effect except as noted
* under O_EXCL below. Otherwise, the file shall be created
* O_EXCL - If O_CREAT and O_EXCL are set, open() shall fail if the file exists.
* O_SYNC - Call sync() after each write. This flag should not be used with
* write(uint8_t), write_P(PGM_P), writeln_P(PGM_P), or the Arduino Print class.
* These functions do character at a time writes so sync() will be called
* after each byte.
* O_TRUNC - If the file exists and is a regular file, and the file is
* successfully opened and is not read only, its length shall be truncated to 0.
Each of the values can be OR'd together to open the file exactly the way that you want. The way to open the file is the 2nd argument to the open() method. To open a file for writing, creating it if doesn't exist, and deleting any data in the file if it does, use O_WRITE | O_CREAT | O_TRUNC.