Prusa3d Marlin fork
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
SdBaseFile Class Reference

Base class for SdFile with Print and C++ streams.

#include <SdBaseFile.h>

Inheritance diagram for SdBaseFile:
Inheritance graph
[legend]
Collaboration diagram for SdBaseFile:
Collaboration graph
[legend]

Public Member Functions

 SdBaseFile ()
 
 SdBaseFile (const char *path, uint8_t oflag)
 
void getpos (filepos_t *pos)
 
void setpos (filepos_t *pos)
 
bool close ()
 
bool contiguousRange (uint32_t *bgnBlock, uint32_t *endBlock)
 
bool createContiguous (SdBaseFile *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)
 
int16_t fgets (char *str, int16_t num, char *delim=0)
 
uint32_t fileSize () const
 
uint32_t firstCluster () const
 
bool getFilename (char *name)
 
bool isDir () const
 
bool isFile () const
 
bool isOpen () const
 
bool isSubDir () const
 
bool isRoot () const
 
void ls (uint8_t flags=0, uint8_t indent=0)
 
bool mkdir (SdBaseFile *dir, const char *path, bool pFlag=true)
 
bool makeDir (SdBaseFile *dir, const char *path)
 
bool open (SdBaseFile *dirFile, uint16_t index, uint8_t oflag)
 
bool open (SdBaseFile *dirFile, const char *path, uint8_t oflag)
 
bool open (const char *path, uint8_t oflag=O_READ)
 
bool openNext (SdBaseFile *dirFile, uint8_t oflag)
 
bool openRoot (SdVolume *vol)
 
int peek ()
 
bool printName ()
 
int8_t readDir (dir_t *dir, char *longFilename)
 
bool remove ()
 
void rewind ()
 
bool rename (SdBaseFile *dirFile, const char *newPath)
 
bool rmdir ()
 
bool rmDir ()
 
bool rmRfStar ()
 
bool seekCur (int32_t offset)
 
bool seekEnd (int32_t offset=0)
 
bool seekSet (uint32_t pos)
 
bool sync ()
 
bool timestamp (SdBaseFile *file)
 
bool timestamp (uint8_t flag, uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
 
uint8_t type () const
 
bool truncate (uint32_t size)
 
SdVolumevolume () const
 
int16_t write (const void *buf, uint16_t nbyte)
 
bool contiguousRange (uint32_t &bgnBlock, uint32_t &endBlock)
 
bool createContiguous (SdBaseFile &dirFile, const char *path, uint32_t size)
 
bool dirEntry (dir_t &dir)
 
bool mkdir (SdBaseFile &dir, const char *path)
 
bool open (SdBaseFile &dirFile, const char *path, uint8_t oflag)
 
bool open (SdBaseFile &dirFile, const char *path)
 
bool open (SdBaseFile &dirFile, uint16_t index, uint8_t oflag)
 
bool openRoot (SdVolume &vol)
 
int8_t readDir (dir_t &dir, char *longFilename)
 

Static Public Member Functions

static SdBaseFilecwd ()
 
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 printFatDate (uint16_t fatDate)
 
static void printFatTime (uint16_t fatTime)
 
static bool remove (SdBaseFile *dirFile, const char *path)
 
static void dateTimeCallback (void(*dateTime)(uint16_t &date, uint16_t &time))
 
static bool remove (SdBaseFile &dirFile, const char *path)
 

Public Attributes

bool writeError
 

Protected Member Functions

int16_t read ()
 
int16_t read (void *buf, uint16_t nbyte)
 
bool openParent (SdBaseFile *dir)
 
bool addCluster ()
 
bool addDirCluster ()
 
dir_tcacheDirEntry (uint8_t action)
 
int8_t lsPrintNext (uint8_t flags, uint8_t indent)
 
bool mkdir (SdBaseFile *parent, const uint8_t dname[11])
 
bool open (SdBaseFile *dirFile, const uint8_t dname[11], uint8_t oflag)
 
bool openCachedEntry (uint8_t cacheIndex, uint8_t oflags)
 
dir_treadDirCache ()
 

Static Protected Member Functions

static bool make83Name (const char *str, uint8_t *name, const char **ptr)
 
static void printDirName (const dir_t &dir, uint8_t width, bool printSlash)
 

Protected Attributes

uint8_t flags_
 
uint8_t fstate_
 
uint8_t type_
 
uint32_t curCluster_
 
uint32_t curPosition_
 
uint32_t dirBlock_
 
uint8_t dirIndex_
 
uint32_t fileSize_
 
uint32_t firstCluster_
 
SdVolumevol_
 

Static Protected Attributes

static SdBaseFilecwd_ = 0
 
static void(* dateTime_ )(uint16_t *date, uint16_t *time)
 
static uint8_t const F_OFLAG = (O_ACCMODE | O_APPEND | O_SYNC)
 
static uint8_t const F_FILE_DIR_DIRTY = 0X80
 

Friends

class SdFat
 

Constructor & Destructor Documentation

◆ SdBaseFile() [1/2]

SdBaseFile::SdBaseFile ( )
inline

Create an instance.

◆ SdBaseFile() [2/2]

SdBaseFile::SdBaseFile ( const char *  path,
uint8_t  oflag 
)

Create a file object and open it in the current working directory.

Parameters
[in]pathA path with a valid 8.3 DOS name for a file to be opened.
[in]oflagValues for oflag are constructed by a bitwise-inclusive OR of open flags. see SdBaseFile::open(SdBaseFile*, const char*, uint8_t).

Member Function Documentation

◆ close()

bool SdBaseFile::close ( )

Close a file and force cached data and directory information to be written to the storage device.

Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include no file is open or an I/O error.

◆ contiguousRange() [1/2]

bool SdBaseFile::contiguousRange ( uint32_t &  bgnBlock,
uint32_t &  endBlock 
)
inline
Deprecated:
Use: bool contiguousRange(uint32_t* bgnBlock, uint32_t* endBlock);
Parameters
[out]bgnBlockthe first block address for the file.
[out]endBlockthe last block address for the file.
Returns
true for success or false for failure.

◆ contiguousRange() [2/2]

bool SdBaseFile::contiguousRange ( uint32_t *  bgnBlock,
uint32_t *  endBlock 
)

Check for contiguous file and return its raw block range.

Parameters
[out]bgnBlockthe first block address for the file.
[out]endBlockthe last block address for the file.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include file is not contiguous, file has zero length or an I/O error occurred.

◆ createContiguous() [1/2]

bool SdBaseFile::createContiguous ( SdBaseFile dirFile,
const char *  path,
uint32_t  size 
)
inline
Deprecated:
Use: bool createContiguous(SdBaseFile* dirFile, const char* path, uint32_t size)
Parameters
[in]dirFileThe directory where the file will be created.
[in]pathA path with a valid DOS 8.3 file name.
[in]sizeThe desired file size.
Returns
true for success or false for failure.

◆ createContiguous() [2/2]

bool SdBaseFile::createContiguous ( SdBaseFile dirFile,
const char *  path,
uint32_t  size 
)

Create and open a new contiguous file of a specified size.

Note
This function only supports short DOS 8.3 names. See open() for more information.
Parameters
[in]dirFileThe directory where the file will be created.
[in]pathA path with a valid DOS 8.3 file name.
[in]sizeThe desired file size.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include path contains an invalid DOS 8.3 file name, the FAT volume has not been initialized, a file is already open, the file already exists, the root directory is full or an I/O error.

◆ curCluster()

uint32_t SdBaseFile::curCluster ( ) const
inline
Returns
The current cluster number for a file or directory.

◆ curPosition()

uint32_t SdBaseFile::curPosition ( ) const
inline
Returns
The current position for a file or directory.

◆ cwd()

static SdBaseFile* SdBaseFile::cwd ( )
inlinestatic
Returns
Current working directory

◆ dateTimeCallback() [1/2]

static void SdBaseFile::dateTimeCallback ( void(*)(uint16_t &date, uint16_t &time)  dateTime)
inlinestatic
Deprecated:
Use: static void dateTimeCallback( void (dateTime)(uint16_t date, uint16_t* time));
Parameters
[in]dateTimeThe user's call back function.

◆ dateTimeCallback() [2/2]

static void SdBaseFile::dateTimeCallback ( void(*)(uint16_t *date, uint16_t *time)  dateTime)
inlinestatic

Set the date/time callback function

Parameters
[in]dateTimeThe 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);
}
static uint16_t FAT_TIME(uint8_t hour, uint8_t minute, uint8_t second)
Definition: SdBaseFile.h:144
static uint16_t FAT_DATE(uint16_t year, uint8_t month, uint8_t day)
Definition: SdBaseFile.h:110

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.

◆ dateTimeCallbackCancel()

static void SdBaseFile::dateTimeCallbackCancel ( )
inlinestatic

Cancel the date/time callback function.

◆ dirEntry() [1/2]

bool SdBaseFile::dirEntry ( dir_t dir)
inline
Deprecated:
Use: bool dirEntry(dir_t* dir);
Parameters
[out]dirLocation for return of the file's directory entry.
Returns
true for success or false for failure.

◆ dirEntry() [2/2]

bool SdBaseFile::dirEntry ( dir_t dir)

Return a file's directory entry.

Parameters
[out]dirLocation for return of the file's directory entry.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ dirName()

void SdBaseFile::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.

Parameters
[in]dirThe directory structure containing the name.
[out]nameA 13 byte char array for the formatted name.

◆ exists()

bool SdBaseFile::exists ( const char *  name)

Test for the existence of a file in a directory

Parameters
[in]nameName of the file to be tested for.

The calling instance must be an open directory file.

dirFile.exists("TOFIND.TXT") searches for "TOFIND.TXT" in the directory dirFile.

Returns
true if the file exists else false.

◆ fgets()

int16_t SdBaseFile::fgets ( char *  str,
int16_t  num,
char *  delim = 0 
)

Get a string from a file.

fgets() reads bytes from a file into the array pointed to by str, until num - 1 bytes are read, or a delimiter is read and transferred to str, or end-of-file is encountered. The string is then terminated with a null byte.

fgets() deletes CR, '\r', from the string. This insures only a '\n' terminates the string for Windows text files which use CRLF for newline.

Parameters
[out]strPointer to the array where the string is stored.
[in]numMaximum number of characters to be read (including the final null byte). Usually the length of the array str is used.
[in]delimOptional set of delimiters. The default is "\n".
Returns
For success fgets() returns the length of the string in str. If no data is read, fgets() returns zero for EOF or -1 if an error occurred.

◆ fileSize()

uint32_t SdBaseFile::fileSize ( ) const
inline
Returns
The total number of bytes in a file or directory.

◆ firstCluster()

uint32_t SdBaseFile::firstCluster ( ) const
inline
Returns
The first cluster number for a file or directory.

◆ getFilename()

bool SdBaseFile::getFilename ( char *  name)

Get a file's name

Parameters
[out]nameAn array of 13 characters for the file's name.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ getpos()

void SdBaseFile::getpos ( filepos_t pos)

get position for streams

Parameters
[out]posstruct to receive position

◆ isDir()

bool SdBaseFile::isDir ( ) const
inline
Returns
True if this is a directory else false.

◆ isFile()

bool SdBaseFile::isFile ( ) const
inline
Returns
True if this is a normal file else false.

◆ isOpen()

bool SdBaseFile::isOpen ( ) const
inline
Returns
True if this is an open file/directory else false.

◆ isRoot()

bool SdBaseFile::isRoot ( ) const
inline
Returns
True if this is the root directory.

◆ isSubDir()

bool SdBaseFile::isSubDir ( ) const
inline
Returns
True if this is a subdirectory else false.

◆ ls()

void SdBaseFile::ls ( uint8_t  flags = 0,
uint8_t  indent = 0 
)

List directory contents.

Parameters
[in]prPrint stream for list.
[in]flagsThe inclusive OR of

LS_DATE - Print file modification date

LS_SIZE - Print file size.

LS_R - Recursive list of subdirectories.

Parameters
[in]indentAmount of space before file name. Used for recursive list to indicate subdirectory level.

◆ mkdir() [1/2]

bool SdBaseFile::mkdir ( SdBaseFile dir,
const char *  path 
)
inline
Deprecated:
Use: bool mkdir(SdBaseFile* dir, const char* path);
Parameters
[in]dirAn open SdFat instance for the directory that will contain the new directory.
[in]pathA path with a valid 8.3 DOS name for the new directory.
Returns
true for success or false for failure.

◆ mkdir() [2/2]

bool SdBaseFile::mkdir ( SdBaseFile parent,
const char *  path,
bool  pFlag = true 
)

Make a new directory.

Parameters
[in]parentAn open SdFat instance for the directory that will contain the new directory.
[in]pathA path with a valid 8.3 DOS name for the new directory.
[in]pFlagCreate missing parent directories if true.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include this file is already open, parent is not a directory, path is invalid or already exists in parent.

◆ open() [1/6]

bool SdBaseFile::open ( const char *  path,
uint8_t  oflag = O_READ 
)

Open a file in the current working directory.

Parameters
[in]pathA path with a valid 8.3 DOS name for a file to be opened.
[in]oflagValues for oflag are constructed by a bitwise-inclusive OR of open flags. see SdBaseFile::open(SdBaseFile*, const char*, uint8_t).
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ open() [2/6]

bool SdBaseFile::open ( SdBaseFile dirFile,
const char *  path 
)
inline
Deprecated:
Do not use in new apps
Parameters
[in]dirFileAn open SdFat instance for the directory containing the file to be opened.
[in]pathA path with a valid 8.3 DOS name for a file to be opened.
Returns
true for success or false for failure.

◆ open() [3/6]

bool SdBaseFile::open ( SdBaseFile dirFile,
const char *  path,
uint8_t  oflag 
)
inline
Deprecated:
Use: bool open(SdBaseFile* dirFile, const char* path, uint8_t oflag);
Parameters
[in]dirFileAn open SdFat instance for the directory containing the file to be opened.
[in]pathA path with a valid 8.3 DOS name for the file.
[in]oflagValues for oflag are constructed by a bitwise-inclusive OR of flags O_READ, O_WRITE, O_TRUNC, and O_SYNC.
Returns
true for success or false for failure.

◆ open() [4/6]

bool SdBaseFile::open ( SdBaseFile dirFile,
uint16_t  index,
uint8_t  oflag 
)
inline
Deprecated:
Use: bool open(SdBaseFile* dirFile, uint16_t index, uint8_t oflag);
Parameters
[in]dirFileAn open SdFat instance for the directory.
[in]indexThe index of the directory entry for the file to be opened. The value for index is (directory file position)/32.
[in]oflagValues for oflag are constructed by a bitwise-inclusive OR of flags O_READ, O_WRITE, O_TRUNC, and O_SYNC.
Returns
true for success or false for failure.

◆ open() [5/6]

bool SdBaseFile::open ( SdBaseFile dirFile,
const char *  path,
uint8_t  oflag 
)

Open a file or directory by name.

Parameters
[in]dirFileAn open SdFat instance for the directory containing the file to be opened.
[in]pathA path with a valid 8.3 DOS name for a file to be opened.
[in]oflagValues 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_AT_END - Set the initial position at the end of the file.

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 SdBaseFile object of file corruption may occur.

Note
Directory files must be opened read only. Write and truncation is not allowed for directory files.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include this file is already open, dirFile is not a directory, path is invalid, the file does not exist or can't be opened in the access mode specified by oflag.

◆ open() [6/6]

bool SdBaseFile::open ( SdBaseFile dirFile,
uint16_t  index,
uint8_t  oflag 
)

Open a file by index.

Parameters
[in]dirFileAn open SdFat instance for the directory.
[in]indexThe index of the directory entry for the file to be opened. The value for index is (directory file position)/32.
[in]oflagValues 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.

Returns
true for success or false for failure.

◆ openNext()

bool SdBaseFile::openNext ( SdBaseFile dirFile,
uint8_t  oflag 
)

Open the next file or subdirectory in a directory.

Parameters
[in]dirFileAn open SdFat instance for the directory containing the file to be opened.
[in]oflagValues 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.

Returns
true for success or false for failure.

◆ openParent()

bool SdBaseFile::openParent ( SdBaseFile dir)
protected

experimental don't use

Open a directory's parent directory.

Parameters
[in]dirParent of this directory will be opened. Must not be root.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ openRoot() [1/2]

bool SdBaseFile::openRoot ( SdVolume vol)
inline
Deprecated:
Use: bool openRoot(SdVolume* vol);
Parameters
[in]volThe FAT volume containing the root directory to be opened.
Returns
true for success or false for failure.

◆ openRoot() [2/2]

bool SdBaseFile::openRoot ( SdVolume vol)

Open a volume's root directory.

Parameters
[in]volThe FAT volume containing the root directory to be opened.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include the file is already open, the FAT volume has not been initialized or it a FAT12 volume.

◆ peek()

int SdBaseFile::peek ( void  )

Return the next available byte without consuming it.

Returns
The byte if no error and not at eof else -1;

◆ printDirName()

void SdBaseFile::printDirName ( const dir_t dir,
uint8_t  width,
bool  printSlash 
)
staticprotected

Print the name field of a directory entry in 8.3 format.

Parameters
[in]prPrint stream for output.
[in]dirThe directory structure containing the name.
[in]widthBlank fill name if length is less than width.
[in]printSlashPrint '/' after directory names if true.

◆ printFatDate()

void SdBaseFile::printFatDate ( uint16_t  fatDate)
static

Print a directory date field to Serial.

Format is yyyy-mm-dd.

Parameters
[in]fatDateThe date field from a directory entry. Print a directory date field.

Format is yyyy-mm-dd.

Parameters
[in]prPrint stream for output.
[in]fatDateThe date field from a directory entry.

◆ printFatTime()

void SdBaseFile::printFatTime ( uint16_t  fatTime)
static

Print a directory time field.

Format is hh:mm:ss.

Parameters
[in]prPrint stream for output.
[in]fatTimeThe time field from a directory entry.

◆ printName()

bool SdBaseFile::printName ( )

Print a file's name to Serial

Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ read() [1/2]

int16_t SdBaseFile::read ( void  )
protected

Read the next byte from a file.

Returns
For success read returns the next byte in the file as an int. If an error occurs or end of file is reached -1 is returned.

◆ read() [2/2]

int16_t SdBaseFile::read ( void *  buf,
uint16_t  nbyte 
)
protected

Read data from a file starting at the current position.

Parameters
[out]bufPointer to the location that will receive the data.
[in]nbyteMaximum number of bytes to read.
Returns
For success read() returns the number of bytes read. A value less than nbyte, including zero, will be returned if end of file is reached. If an error occurs, read() returns -1. Possible errors include read() called before a file has been opened, corrupt file system or an I/O error occurred.

◆ readDir() [1/2]

int8_t SdBaseFile::readDir ( dir_t dir,
char *  longFilename 
)
inline
Deprecated:
Use: int8_t readDir(dir_t* dir);
Parameters
[out]dirThe dir_t struct that will receive the data.
Returns
bytes read for success zero for eof or -1 for failure.

◆ readDir() [2/2]

int8_t SdBaseFile::readDir ( dir_t dir,
char *  longFilename 
)

Read the next directory entry from a directory file.

Parameters
[out]dirThe dir_t struct that will receive the data.
Returns
For success readDir() returns the number of bytes read. A value of zero will be returned if end of file is reached. If an error occurs, readDir() returns -1. Possible errors include readDir() called before a directory has been opened, this is not a directory file or an I/O error occurred.

◆ remove() [1/3]

bool SdBaseFile::remove ( )

Remove a file.

The directory entry and all data for the file are deleted.

Note
This function should not be used to delete the 8.3 version of a file that has a long name. For example if a file has the long name "New Text Document.txt" you should not delete the 8.3 name "NEWTEX~1.TXT".
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include the file read-only, is a directory, or an I/O error occurred.

◆ remove() [2/3]

static bool SdBaseFile::remove ( SdBaseFile dirFile,
const char *  path 
)
inlinestatic
Deprecated:
Use: static uint8_t remove(SdBaseFile* dirFile, const char* path);
Parameters
[in]dirFileThe directory that contains the file.
[in]pathThe name of the file to be removed.
Returns
true for success or false for failure.

◆ remove() [3/3]

bool SdBaseFile::remove ( SdBaseFile dirFile,
const char *  path 
)
static

Remove a file.

The directory entry and all data for the file are deleted.

Parameters
[in]dirFileThe directory that contains the file.
[in]pathPath for the file to be removed.
Note
This function should not be used to delete the 8.3 version of a file that has a long name. For example if a file has the long name "New Text Document.txt" you should not delete the 8.3 name "NEWTEX~1.TXT".
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include the file is a directory, is read only, dirFile is not a directory, path is not found or an I/O error occurred.

◆ rename()

bool SdBaseFile::rename ( SdBaseFile dirFile,
const char *  newPath 
)

Rename a file or subdirectory.

Parameters
[in]dirFileDirectory for the new path.
[in]newPathNew path name for the file/directory.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include dirFile is not open or is not a directory file, newPath is invalid or already exists, or an I/O error occurs.

◆ rewind()

void SdBaseFile::rewind ( )
inline

Set the file's current position to zero.

◆ rmdir()

bool SdBaseFile::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.

Note
This function should not be used to delete the 8.3 version of a directory that has a long name. For example if a directory has the long name "New folder" you should not delete the 8.3 name "NEWFOL~1".
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include the file is not a directory, is the root directory, is not empty, or an I/O error occurred.

◆ rmRfStar()

bool SdBaseFile::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.

Note
This function should not be used to delete the 8.3 version of a directory that has a long name. See remove() and rmdir().
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ seekCur()

bool SdBaseFile::seekCur ( int32_t  offset)
inline

Set the files position to current position + pos. See seekSet().

Parameters
[in]offsetThe new position in bytes from the current position.
Returns
true for success or false for failure.

◆ seekEnd()

bool SdBaseFile::seekEnd ( int32_t  offset = 0)
inline

Set the files position to end-of-file + offset. See seekSet().

Parameters
[in]offsetThe new position in bytes from end-of-file.
Returns
true for success or false for failure.

◆ seekSet()

bool SdBaseFile::seekSet ( uint32_t  pos)

Sets a file's position.

Parameters
[in]posThe new position in bytes from the beginning of the file.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ setpos()

void SdBaseFile::setpos ( filepos_t pos)

set position for streams

Parameters
[out]posstruct with value for new position

◆ sync()

bool SdBaseFile::sync ( )

The sync() call causes all modified data and directory fields to be written to the storage device.

Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include a call to sync() before a file has been opened or an I/O error.

◆ timestamp() [1/2]

bool SdBaseFile::timestamp ( SdBaseFile file)

Copy a file's timestamps

Parameters
[in]fileFile to copy timestamps from.
Note
Modify and access timestamps may be overwritten if a date time callback function has been set by dateTimeCallback().
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ timestamp() [2/2]

bool SdBaseFile::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.

Parameters
[in]flagsValues 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.

Parameters
[in]yearValid range 1980 - 2107 inclusive.
[in]monthValid range 1 - 12 inclusive.
[in]dayValid range 1 - 31 inclusive.
[in]hourValid range 0 - 23 inclusive.
[in]minuteValid range 0 - 59 inclusive.
[in]secondValid range 0 - 59 inclusive
Note
It is possible to set an invalid date since there is no check for the number of days in a month.
Modify and access timestamps may be overwritten if a date time callback function has been set by dateTimeCallback().
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ truncate()

bool SdBaseFile::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.

Parameters
[in]lengthThe desired length for the file.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include file is read only, file is a directory, length is greater than the current file size or an I/O error occurs.

◆ type()

uint8_t SdBaseFile::type ( ) const
inline

Type of file. You should use isFile() or isDir() instead of type() if possible.

Returns
The file or directory type.

◆ volume()

SdVolume* SdBaseFile::volume ( ) const
inline
Returns
SdVolume that contains this file.

◆ write()

int16_t SdBaseFile::write ( const void *  buf,
uint16_t  nbyte 
)

Write data to an open file.

Note
Data is moved to the cache but may not be written to the storage device until sync() is called.
Parameters
[in]bufPointer to the location of the data to be written.
[in]nbyteNumber of bytes to write.
Returns
For success write() returns the number of bytes written, always nbyte. If an error occurs, write() returns -1. Possible errors include write() is called before a file has been opened, write is called for a read-only file, device is full, a corrupt file system or an I/O error.

Member Data Documentation

◆ writeError

bool SdBaseFile::writeError

writeError is set to true if an error occurs during a write(). Set writeError to false before calling print() and/or write() and check for true after calls to print() and/or write().


The documentation for this class was generated from the following files: