ESP8266
|
Access FAT16 and FAT32 files on SD and SDHC cards. More...
Public Member Functions | |
SdFile (void) | |
void | clearUnbufferedRead (void) |
uint8_t | close (void) |
uint8_t | contiguousRange (uint32_t *bgnBlock, uint32_t *endBlock) |
uint8_t | createContiguous (SdFile *dirFile, const char *fileName, uint32_t size) |
uint32_t | curCluster (void) const |
uint32_t | curPosition (void) const |
uint32_t | dirBlock (void) const |
uint8_t | dirEntry (dir_t *dir) |
uint8_t | dirIndex (void) const |
uint32_t | fileSize (void) const |
uint32_t | firstCluster (void) const |
uint8_t | isDir (void) const |
uint8_t | isFile (void) const |
uint8_t | isOpen (void) const |
uint8_t | isSubDir (void) const |
uint8_t | isRoot (void) const |
void | ls (uint8_t flags=0, uint8_t indent=0) |
uint8_t | makeDir (SdFile *dir, const char *dirName) |
uint8_t | open (SdFile *dirFile, uint16_t index, uint8_t oflag) |
uint8_t | open (SdFile *dirFile, const char *fileName, uint8_t oflag) |
uint8_t | openRoot (SdVolume *vol) |
int16_t | read (void) |
int16_t | read (void *buf, uint16_t nbyte) |
int8_t | readDir (dir_t *dir) |
uint8_t | remove (void) |
void | rewind (void) |
uint8_t | rmDir (void) |
uint8_t | rmRfStar (void) |
uint8_t | seekCur (uint32_t pos) |
uint8_t | seekEnd (void) |
uint8_t | seekSet (uint32_t pos) |
void | setUnbufferedRead (void) |
uint8_t | timestamp (uint8_t flag, uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) |
uint8_t | sync (void) |
uint8_t | type (void) const |
uint8_t | truncate (uint32_t size) |
uint8_t | unbufferedRead (void) const |
SdVolume * | volume (void) const |
size_t | write (uint8_t b) |
size_t | write (const void *buf, uint16_t nbyte) |
size_t | write (const char *str) |
uint8_t | contiguousRange (uint32_t &bgnBlock, uint32_t &endBlock) |
uint8_t | createContiguous (SdFile &dirFile, const char *fileName, uint32_t size) |
uint8_t | dirEntry (dir_t &dir) |
uint8_t | makeDir (SdFile &dir, const char *dirName) |
uint8_t | open (SdFile &dirFile, const char *fileName, uint8_t oflag) |
uint8_t | open (SdFile &dirFile, const char *fileName) |
uint8_t | open (SdFile &dirFile, uint16_t index, uint8_t oflag) |
uint8_t | openRoot (SdVolume &vol) |
int8_t | readDir (dir_t &dir) |
Public Member Functions inherited from Print | |
Print () | |
int | getWriteError () |
void | clearWriteError () |
size_t | write (const char *str) |
virtual size_t | write (const uint8_t *buffer, size_t size) |
size_t | write (const char *buffer, size_t size) |
size_t | printf (const char *format,...) __attribute__((format(printf |
size_t size_t | print (const __FlashStringHelper *) |
size_t | print (const String &) |
size_t | print (const char[]) |
size_t | print (char) |
size_t | print (unsigned char, int=10) |
size_t | print (int, int=10) |
size_t | print (unsigned int, int=10) |
size_t | print (long, int=10) |
size_t | print (unsigned long, int=10) |
size_t | print (double, int=2) |
size_t | print (const Printable &) |
size_t | println (const __FlashStringHelper *) |
size_t | println (const String &s) |
size_t | println (const char[]) |
size_t | println (char) |
size_t | println (unsigned char, int=10) |
size_t | println (int, int=10) |
size_t | println (unsigned int, int=10) |
size_t | println (long, int=10) |
size_t | println (unsigned long, int=10) |
size_t | println (double, int=2) |
size_t | println (const Printable &) |
size_t | println (void) |
Static Public Member Functions | |
static void | dateTimeCallback (void(*dateTime)(uint16_t *date, uint16_t *time)) |
static void | dateTimeCallbackCancel (void) |
static void | dirName (const dir_t &dir, char *name) |
static void | printDirName (const dir_t &dir, uint8_t width) |
static void | printFatDate (uint16_t fatDate) |
static void | printFatTime (uint16_t fatTime) |
static void | printTwoDigits (uint8_t v) |
static uint8_t | remove (SdFile *dirFile, const char *fileName) |
static void | dateTimeCallback (void(*dateTime)(uint16_t &date, uint16_t &time)) |
static uint8_t | remove (SdFile &dirFile, const char *fileName) |
Private Member Functions | |
uint8_t | addCluster (void) |
uint8_t | addDirCluster (void) |
dir_t * | cacheDirEntry (uint8_t action) |
uint8_t | openCachedEntry (uint8_t cacheIndex, uint8_t oflags) |
dir_t * | readDirCache (void) |
Static Private Member Functions | |
static void | oldToNew (uint16_t *date, uint16_t *time) |
static uint8_t | make83Name (const char *str, uint8_t *name) |
Private Attributes | |
uint8_t | flags_ |
uint8_t | type_ |
uint32_t | curCluster_ |
uint32_t | curPosition_ |
uint32_t | dirBlock_ |
uint8_t | dirIndex_ |
uint32_t | fileSize_ |
uint32_t | firstCluster_ |
SdVolume * | vol_ |
Static Private Attributes | |
static void(* | oldDateTime_ )(uint16_t &date, uint16_t &time) = NULL |
static uint8_t const | F_OFLAG = (O_ACCMODE | O_APPEND | O_SYNC) |
static uint8_t const | F_UNUSED = 0X30 |
static uint8_t const | F_FILE_UNBUFFERED_READ = 0X40 |
static uint8_t const | F_FILE_DIR_DIRTY = 0X80 |
static void(* | dateTime_ )(uint16_t *date, uint16_t *time) = NULL |
Additional Inherited Members | |
Protected Member Functions inherited from Print | |
void | setWriteError (int err=1) |
Access FAT16 and FAT32 files on SD and SDHC cards.
SdFile::SdFile | ( | void | ) |
Create an instance of SdFile.
|
private |
|
private |
|
private |
void SdFile::clearUnbufferedRead | ( | void | ) |
uint8_t SdFile::close | ( | void | ) |
Close a file and force cached data and directory information to be written to the storage device.
uint8_t 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. |
uint8_t SdFile::contiguousRange | ( | uint32_t & | bgnBlock, |
uint32_t & | endBlock | ||
) |
uint8_t SdFile::createContiguous | ( | SdFile * | dirFile, |
const char * | fileName, | ||
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] | fileName | A valid DOS 8.3 file name. |
[in] | size | The desired file size. |
uint8_t SdFile::createContiguous | ( | SdFile & | dirFile, |
const char * | fileName, | ||
uint32_t | size | ||
) |
uint32_t SdFile::curCluster | ( | void | ) | const |
uint32_t SdFile::curPosition | ( | void | ) | const |
|
static |
Set the date/time callback function
[in] | dateTime | The user's call back function. The callback function is of the form: |
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 |
|
static |
Cancel the date/time callback function.
uint32_t SdFile::dirBlock | ( | void | ) | const |
uint8_t SdFile::dirEntry | ( | dir_t * | dir | ) |
Return a files directory entry
[out] | dir | Location for return of the files directory entry. |
uint8_t SdFile::dirEntry | ( | dir_t & | dir | ) |
uint8_t SdFile::dirIndex | ( | void | ) | const |
|
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. |
uint32_t SdFile::fileSize | ( | void | ) | const |
uint32_t SdFile::firstCluster | ( | void | ) | const |
uint8_t SdFile::isDir | ( | void | ) | const |
uint8_t SdFile::isFile | ( | void | ) | const |
uint8_t SdFile::isOpen | ( | void | ) | const |
uint8_t SdFile::isRoot | ( | void | ) | const |
uint8_t SdFile::isSubDir | ( | void | ) | const |
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. |
|
staticprivate |
uint8_t SdFile::makeDir | ( | SdFile * | dir, |
const char * | dirName | ||
) |
Make a new directory.
[in] | dir | An open SdFat instance for the directory that will containing the new directory. |
[in] | dirName | A valid 8.3 DOS name for the new directory. |
uint8_t SdFile::makeDir | ( | SdFile & | dir, |
const char * | dirName | ||
) |
|
staticprivate |
uint8_t SdFile::open | ( | SdFile * | dirFile, |
uint16_t | index, | ||
uint8_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 fileName for definition of flags and return values.
uint8_t SdFile::open | ( | SdFile * | dirFile, |
const char * | fileName, | ||
uint8_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] | fileName | 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.
uint8_t SdFile::open | ( | SdFile & | dirFile, |
const char * | fileName, | ||
uint8_t | oflag | ||
) |
uint8_t SdFile::open | ( | SdFile & | dirFile, |
const char * | fileName | ||
) |
uint8_t SdFile::open | ( | SdFile & | dirFile, |
uint16_t | index, | ||
uint8_t | oflag | ||
) |
|
private |
uint8_t SdFile::openRoot | ( | SdVolume * | vol | ) |
Open a volume's root directory.
[in] | vol | The FAT volume containing the root directory to be opened. |
uint8_t SdFile::openRoot | ( | SdVolume & | vol | ) |
|
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. |
|
static |
Print a directory date field to Serial.
Format is yyyy-mm-dd.
[in] | fatDate | The date field from a directory entry. |
|
static |
Print a directory time field to Serial.
Format is hh:mm:ss.
[in] | fatTime | The time field from a directory entry. |
|
static |
Print a value as two digits to Serial.
[in] | v | Value to be printed, 0 <= v <= 99 |
int16_t SdFile::read | ( | void | ) |
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. |
int8_t SdFile::readDir | ( | dir_t & | dir | ) |
|
private |
|
static |
Remove a file.
The directory entry and all data for the file are deleted.
[in] | dirFile | The directory that contains the file. |
[in] | fileName | The name of the file to be removed. |
uint8_t SdFile::remove | ( | void | ) |
Remove a file.
The directory entry and all data for the file are deleted.
|
static |
void SdFile::rewind | ( | void | ) |
Set the file's current position to zero.
uint8_t SdFile::rmDir | ( | void | ) |
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.
uint8_t SdFile::rmRfStar | ( | void | ) |
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.
uint8_t SdFile::seekCur | ( | uint32_t | pos | ) |
Set the files position to current position + pos. See seekSet().
uint8_t SdFile::seekEnd | ( | void | ) |
Set the files current position to end of file. Useful to position a file for append. See seekSet().
uint8_t 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::setUnbufferedRead | ( | void | ) |
Use unbuffered reads to access this file. Used with Wave Shield ISR. Used with Sd2Card::partialBlockRead() in WaveRP.
Not recommended for normal applications.
uint8_t SdFile::sync | ( | void | ) |
uint8_t 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 |
uint8_t 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 | ( | void | ) | const |
uint8_t SdFile::unbufferedRead | ( | void | ) | const |
|
virtual |
size_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. |
size_t SdFile::write | ( | const char * | str | ) |
Write a string to a file. Used by the Arduino Print class.
Use SdFile::writeError to check for errors.
|
private |
|
private |
|
staticprivate |
|
private |
|
private |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
private |
|
private |
|
private |
|
staticprivate |
|
private |
|
private |