Access FAT16 and FAT32 files on SD and SDHC cards. More...
#include <SdFile.h>
Public Member Functions | |
bool | close () |
bool | contiguousRange (uint32_t *bgnBlock, uint32_t *endBlock) |
bool | createContiguous (SdFile *dirFile, const char *path, uint32_t size) |
uint32_t | curCluster () const |
uint32_t | curPosition () const |
bool | dirEntry (dir_t *dir) |
bool | exists (const char *name) |
uint32_t | fileSize () const |
uint32_t | firstCluster () const |
bool | getFilename (char *name) |
void | getpos (fpos_t *pos) |
bool | isDir () const |
bool | isFile () const |
bool | isOpen () const |
bool | isRoot () const |
bool | isSubDir () const |
void | ls (uint8_t flags=0, uint8_t indent=0) |
bool | mkdir (SdFile *dir, const char *path, bool pFlag=true) |
bool | open (SdFile *dirFile, uint16_t index, uint16_t oflag) |
bool | open (SdFile *dirFile, const char *path, uint16_t oflag) |
bool | open (const char *path, uint16_t oflag) |
bool | openRoot (SdVolume *vol) |
void | print (unsigned long, int=DEC) |
void | print (unsigned char, int=BYTE) |
void | print (const String &) |
void | print (const char[]) |
void | print (char, int=BYTE) |
void | print (int, int=DEC) |
void | print (unsigned int, int=DEC) |
void | print (long, int=DEC) |
void | print (double, int=2) |
void | println (unsigned long, int=DEC) |
void | println (double, int=2) |
void | println (void) |
void | println (int, int=DEC) |
void | println (long, int=DEC) |
void | println (unsigned int, int=DEC) |
void | println (unsigned char, int=BYTE) |
void | println (const String &s) |
void | println (const char[]) |
void | println (char, int=BYTE) |
bool | printName () |
int16_t | read () |
int16_t | read (void *buf, uint16_t nbyte) |
int8_t | readDir (dir_t *dir) |
bool | remove () |
void | rewind () |
bool | rmdir () |
bool | rmRfStar () |
SdFile () | |
bool | seekCur (int32_t offset) |
bool | seekEnd (int32_t offset=0) |
bool | seekSet (uint32_t pos) |
void | setpos (fpos_t *pos) |
bool | sync () |
bool | timestamp (uint8_t flag, uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) |
bool | truncate (uint32_t size) |
uint8_t | type () const |
SdVolume * | volume () const |
virtual void | write (const uint8_t *buffer, size_t size) |
void | write (uint8_t b) |
void | write (const char *str) |
int16_t | write (const void *buf, uint16_t nbyte) |
void | write_P (PGM_P str) |
void | writeln_P (PGM_P str) |
Static Public Member Functions | |
static void | dateTimeCallback (void(*dateTime)(uint16_t *date, uint16_t *time)) |
static void | dateTimeCallbackCancel () |
static void | dirName (const dir_t &dir, char *name) |
static void | printDirName (const dir_t &dir, uint8_t width, bool printSlash=true) |
static void | printFatDate (uint16_t fatDate) |
static void | printFatTime (uint16_t fatTime) |
static void | printTwoDigits (uint8_t v) |
static bool | remove (SdFile *dirFile, const char *path) |
Public Attributes | |
bool | writeError |
Friends | |
class | SdFat |
Access FAT16 and FAT32 files on SD and SDHC cards.
SdFile::SdFile | ( | ) | [inline] |
Create an instance of SdFile.
bool SdFile::close | ( | ) |
Close a file and force cached data and directory information to be written to the storage device.
bool SdFile::contiguousRange | ( | uint32_t * | bgnBlock, |
uint32_t * | endBlock | ||
) |
Check for contiguous file and return its raw block range.
[out] | bgnBlock | the first block address for the file. |
[out] | endBlock | the last block address for the file. |
bool SdFile::createContiguous | ( | SdFile * | dirFile, |
const char * | path, | ||
uint32_t | size | ||
) |
Create and open a new contiguous file of a specified size.
[in] | dirFile | The directory where the file will be created. |
[in] | path | A path with a valid DOS 8.3 file name. |
[in] | size | The desired file size. |
uint32_t SdFile::curCluster | ( | ) | const [inline] |
uint32_t SdFile::curPosition | ( | ) | const [inline] |
static void SdFile::dateTimeCallback | ( | void(*)(uint16_t *date, uint16_t *time) | dateTime ) | [inline, static] |
Set the date/time callback function
[in] | dateTime | The user's call back function. The callback function is of the form: |
void dateTime(uint16_t* date, uint16_t* time) { uint16_t year; uint8_t month, day, hour, minute, second; // User gets date and time from GPS or real-time clock here // return date using FAT_DATE macro to format fields *date = FAT_DATE(year, month, day); // return time using FAT_TIME macro to format fields *time = FAT_TIME(hour, minute, second); }
Sets the function that is called when a file is created or when a file's directory entry is modified by sync(). All timestamps, access, creation, and modify, are set when a file is created. sync() maintains the last access date and last modify date/time.
See the timestamp() function.
static void SdFile::dateTimeCallbackCancel | ( | ) | [inline, static] |
Cancel the date/time callback function.
bool SdFile::dirEntry | ( | dir_t * | dir ) |
Return a file's directory entry
[out] | dir | Location for return of the file's directory entry. |
void SdFile::dirName | ( | const dir_t & | dir, |
char * | name | ||
) | [static] |
Format the name field of dir into the 13 byte array name in standard 8.3 short name format.
[in] | dir | The directory structure containing the name. |
[out] | name | A 13 byte char array for the formatted name. |
bool SdFile::exists | ( | const char * | name ) |
Test for the existence of a file in a directory
[in] | name | Name of the file to be tested for. |
uint32_t SdFile::fileSize | ( | ) | const [inline] |
uint32_t SdFile::firstCluster | ( | ) | const [inline] |
bool SdFile::getFilename | ( | char * | name ) |
Get a file's name
[out] | name | An array of 13 characters for the file's name. |
void SdFile::getpos | ( | fpos_t * | pos ) |
get position for streams
[out] | pos | struct to receive position |
bool SdFile::isDir | ( | ) | const [inline] |
bool SdFile::isFile | ( | ) | const [inline] |
bool SdFile::isOpen | ( | ) | const [inline] |
bool SdFile::isRoot | ( | ) | const [inline] |
bool SdFile::isSubDir | ( | ) | const [inline] |
void SdFile::ls | ( | uint8_t | flags = 0 , |
uint8_t | indent = 0 |
||
) |
List directory contents to Serial.
[in] | flags | The inclusive OR of |
LS_DATE - Print file modification date
LS_SIZE - Print file size.
LS_R - Recursive list of subdirectories.
[in] | indent | Amount of space before file name. Used for recursive list to indicate subdirectory level. |
bool SdFile::mkdir | ( | SdFile * | parent, |
const char * | path, | ||
bool | pFlag = true |
||
) |
Make a new directory.
[in] | parent | An open SdFat instance for the directory that will contain the new directory. |
[in] | path | A path with a valid 8.3 DOS name for the new directory. |
[in] | pFlag | Create missing parent directorys if true. |
bool SdFile::open | ( | SdFile * | dirFile, |
uint16_t | index, | ||
uint16_t | oflag | ||
) |
Open a file by index.
[in] | dirFile | An open SdFat instance for the directory. |
[in] | index | The index of the directory entry for the file to be opened. The value for index is (directory file position)/32. |
[in] | oflag | Values for oflag are constructed by a bitwise-inclusive OR of flags O_READ, O_WRITE, O_TRUNC, and O_SYNC. |
See open() by path for definition of flags.
bool SdFile::open | ( | SdFile * | dirFile, |
const char * | path, | ||
uint16_t | oflag | ||
) |
Open a file or directory by name.
[in] | dirFile | An open SdFat instance for the directory containing the file to be opened. |
[in] | path | A path with a valid 8.3 DOS name for a file to be opened. |
[in] | oflag | Values for oflag are constructed by a bitwise-inclusive OR of flags from the following list |
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.
WARNING: A given file must not be opened by more than one SdFile object of file coruption may occur.
bool SdFile::open | ( | const char * | path, |
uint16_t | oflag | ||
) |
Open a file in the current working directory.
[in] | path | A path with a valid 8.3 DOS name for a file to be opened. |
[in] | oflag | Values for oflag are constructed by a bitwise-inclusive OR of open flags. see SdFile::open(SdFile*, const char*, uint8_t). |
bool SdFile::openRoot | ( | SdVolume * | vol ) |
Open a volume's root directory.
[in] | vol | The FAT volume containing the root directory to be opened. |
void Print::print | ( | unsigned int | n, |
int | base = DEC |
||
) | [inherited] |
Write an unsigned number to the associated device in ASCII.
[in] | n | the number to be printed |
[in] | base | format to be used |
void Print::print | ( | const char | str[] ) | [inherited] |
Write a string to the associated device.
[in] | str | the string to be printed |
void Print::print | ( | const String & | s ) | [inherited] |
Write a string to the associated device.
[in] | s | the string to be printed |
void Print::print | ( | char | c, |
int | base = BYTE |
||
) | [inherited] |
Write an signed byte to the associated device in ASCII.
[in] | c | the byte to be printed |
[in] | base | format to be used |
void Print::print | ( | unsigned char | b, |
int | base = BYTE |
||
) | [inherited] |
Write an unsigned byte to the associated device in ASCII.
[in] | b | the byte to be printed |
[in] | base | format to be used |
void Print::print | ( | int | n, |
int | base = DEC |
||
) | [inherited] |
Write an signed number to the associated device in ASCII.
[in] | n | the number to be printed |
[in] | base | format to be used |
void Print::print | ( | long | n, |
int | base = DEC |
||
) | [inherited] |
Write an signed number to the associated device in ASCII.
[in] | n | the number to be printed |
[in] | base | format to be used |
void Print::print | ( | unsigned long | n, |
int | base = DEC |
||
) | [inherited] |
Write an unsigned number to the associated device in ASCII.
[in] | n | the number to be printed |
[in] | base | format to be used |
void Print::print | ( | double | n, |
int | digits = 2 |
||
) | [inherited] |
Write the decimal representation of an float or double to the associated device in ASCII.
[in] | n | the number to be printed |
[in] | digits | the digits in ftraction to be printed |
void SdFile::printDirName | ( | const dir_t & | dir, |
uint8_t | width, | ||
bool | printSlash = true |
||
) | [static] |
Print the name field of a directory entry in 8.3 format to Serial.
[in] | dir | The directory structure containing the name. |
[in] | width | Blank fill name if length is less than width. |
[in] | printSlash | Print '/' after directory names if true. |
void SdFile::printFatDate | ( | uint16_t | fatDate ) | [static] |
Print a directory date field to Serial.
Format is yyyy-mm-dd.
[in] | fatDate | The date field from a directory entry. |
void SdFile::printFatTime | ( | uint16_t | fatTime ) | [static] |
Print a directory time field to Serial.
Format is hh:mm:ss.
[in] | fatTime | The time field from a directory entry. |
void Print::println | ( | const char | c[] ) | [inherited] |
Write a string to the associated device followed by CR LF.
[in] | c | the string to be printed |
void Print::println | ( | char | c, |
int | base = BYTE |
||
) | [inherited] |
Write an signed byte to the associated device in ASCII followed by CR LF.
[in] | c | the byte to be printed |
[in] | base | format to be used |
void Print::println | ( | unsigned char | b, |
int | base = BYTE |
||
) | [inherited] |
Write an unsigned byte to the associated device in ASCII followed by CR LF.
[in] | b | the byte to be printed |
[in] | base | format to be used |
void Print::println | ( | unsigned int | n, |
int | base = DEC |
||
) | [inherited] |
Write an unsigned number to the associated device in ASCII followed by CR LF.
[in] | n | the number to be printed |
[in] | base | format to be used |
void Print::println | ( | unsigned long | n, |
int | base = DEC |
||
) | [inherited] |
Write an unsigned number to the associated device in ASCII followed by CR LF.
[in] | n | the number to be printed |
[in] | base | format to be used |
void Print::println | ( | double | n, |
int | digits = 2 |
||
) | [inherited] |
Write the decimal representation of an float or double to the associated device in ASCII followed by CR LF.
[in] | n | the number to be printed |
[in] | digits | the digits in ftraction to be printed |
void Print::println | ( | void | ) | [inherited] |
Print CR LF
void Print::println | ( | int | n, |
int | base = DEC |
||
) | [inherited] |
Write an signed number to the associated device in ASCII followed by CR LF.
[in] | n | the number to be printed |
[in] | base | format to be used |
void Print::println | ( | const String & | s ) | [inherited] |
Write a string to the associated device followed by CR LF.
[in] | s | the string to be printed |
void Print::println | ( | long | n, |
int | base = DEC |
||
) | [inherited] |
Write an signed number to the associated device in ASCII followed by CR LF.
[in] | n | the number to be printed |
[in] | base | format to be used |
bool SdFile::printName | ( | ) |
Print a file's name to Serial
void SdFile::printTwoDigits | ( | uint8_t | v ) | [static] |
Print a value as two digits to Serial.
[in] | v | Value to be printed, 0 <= v <= 99 |
int16_t SdFile::read | ( | ) |
Read the next byte from a file.
int16_t SdFile::read | ( | void * | buf, |
uint16_t | nbyte | ||
) |
Read data from a file starting at the current position.
[out] | buf | Pointer to the location that will receive the data. |
[in] | nbyte | Maximum number of bytes to read. |
int8_t SdFile::readDir | ( | dir_t * | dir ) |
Read the next directory entry from a directory file.
[out] | dir | The dir_t struct that will receive the data. |
bool SdFile::remove | ( | ) |
Remove a file.
The directory entry and all data for the file are deleted.
bool SdFile::remove | ( | SdFile * | dirFile, |
const char * | path | ||
) | [static] |
Remove a file.
The directory entry and all data for the file are deleted.
[in] | dirFile | The directory that contains the file. |
[in] | path | Path for the file to be removed. |
void SdFile::rewind | ( | ) | [inline] |
Set the file's current position to zero.
bool SdFile::rmdir | ( | ) |
Remove a directory file.
The directory file will be removed only if it is empty and is not the root directory. rmdir() follows DOS and Windows and ignores the read-only attribute for the directory.
bool SdFile::rmRfStar | ( | ) |
Recursively delete a directory and all contained files.
This is like the Unix/Linux 'rm -rf *' if called with the root directory hence the name.
Warning - This will remove all contents of the directory including subdirectories. The directory will then be removed if it is not root. The read-only attribute for files will be ignored.
bool SdFile::seekCur | ( | int32_t | offset ) | [inline] |
Set the files position to current position + pos. See seekSet().
[in] | offset | The new position in bytes from the current position. |
bool SdFile::seekEnd | ( | int32_t | offset = 0 ) |
[inline] |
Set the files position to end-of-file + offset. See seekSet().
[in] | offset | The new position in bytes from end-of-file. |
bool SdFile::seekSet | ( | uint32_t | pos ) |
Sets a file's position.
[in] | pos | The new position in bytes from the beginning of the file. |
void SdFile::setpos | ( | fpos_t * | pos ) |
set position for streams
[out] | pos | struct with value for new position |
bool SdFile::sync | ( | ) |
bool SdFile::timestamp | ( | uint8_t | flags, |
uint16_t | year, | ||
uint8_t | month, | ||
uint8_t | day, | ||
uint8_t | hour, | ||
uint8_t | minute, | ||
uint8_t | second | ||
) |
Set a file's timestamps in its directory entry.
[in] | flags | Values for flags are constructed by a bitwise-inclusive OR of flags from the following list |
T_ACCESS - Set the file's last access date.
T_CREATE - Set the file's creation date and time.
T_WRITE - Set the file's last write/modification date and time.
[in] | year | Valid range 1980 - 2107 inclusive. |
[in] | month | Valid range 1 - 12 inclusive. |
[in] | day | Valid range 1 - 31 inclusive. |
[in] | hour | Valid range 0 - 23 inclusive. |
[in] | minute | Valid range 0 - 59 inclusive. |
[in] | second | Valid range 0 - 59 inclusive |
bool SdFile::truncate | ( | uint32_t | length ) |
Truncate a file to a specified length. The current file position will be maintained if it is less than or equal to length otherwise it will be set to end of file.
[in] | length | The desired length for the file. |
uint8_t SdFile::type | ( | ) | const [inline] |
int16_t SdFile::write | ( | const void * | buf, |
uint16_t | nbyte | ||
) |
Write data to an open file.
[in] | buf | Pointer to the location of the data to be written. |
[in] | nbyte | Number of bytes to write. |
void SdFile::write | ( | uint8_t | b ) | [virtual] |
Write a byte to a file. Required by the Arduino Print class.
[in] | b | the byte to be written. Use SdFile::writeError to check for errors. |
Implements Print.
void Print::write | ( | const uint8_t * | buffer, |
size_t | size | ||
) | [virtual, inherited] |
default implementation: may be overridden
[in] | buffer | pointer to data |
[in] | size | count of bytes to be written |
void SdFile::write | ( | const char * | str ) | [virtual] |
Write a string to a file. Used by the Arduino Print class.
[in] | str | Pointer to the string. Use SdFile::writeError to check for errors. |
Reimplemented from Print.
void SdFile::write_P | ( | PGM_P | str ) |
Write a PROGMEM string to a file.
[in] | str | Pointer to the PROGMEM string. Use SdFile::writeError to check for errors. |
void SdFile::writeln_P | ( | PGM_P | str ) |
Write a PROGMEM string followed by CR/LF to a file.
[in] | str | Pointer to the PROGMEM string. Use SdFile::writeError to check for errors. |
bool SdFile::writeError |