Adafruit WaveHC Arduino Library
Public Member Functions | List of all members
FatReader Class Reference

FatReader implements a minimal FAT16/FAT32 file reader class. More...

#include <FatReader.h>

Public Member Functions

 FatReader (void)
 
void ls (uint8_t flags=0)
 list file in a directory More...
 
uint8_t openRoot (FatVolume &vol)
 
uint8_t open (FatVolume &vol, dir_t &dir)
 
uint8_t open (FatReader &dir, char *name)
 
uint8_t open (FatReader &dir, uint16_t index)
 
void optimizeContiguous (void)
 
int16_t read (void *buf, uint16_t count)
 
int8_t readDir (dir_t &dir)
 
void rewind (void)
 
uint8_t seekCur (uint32_t pos)
 
void close (void)
 
uint32_t fileSize (void)
 
uint8_t fileType (void)
 
uint32_t firstCluster (void)
 
uint8_t isContiguous (void)
 
uint8_t isDir (void)
 
uint8_t isFile (void)
 
uint8_t isOpen (void)
 
uint32_t readCluster (void)
 
uint32_t readPosition (void)
 
uint8_t seekSet (uint32_t pos)
 
FatVolumevolume (void)
 get the parent volume More...
 

Detailed Description

FatReader implements a minimal FAT16/FAT32 file reader class.

Constructor & Destructor Documentation

◆ FatReader()

FatReader::FatReader ( void  )
inline

Create an instance of FatReader.

Member Function Documentation

◆ ls()

void FatReader::ls ( uint8_t  flags = 0)

list file in a directory

Parameters
flagsfile flags

◆ openRoot()

uint8_t FatReader::openRoot ( FatVolume 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 FAT volume has not been initialized or it a FAT12 volume.

◆ open() [1/3]

uint8_t FatReader::open ( FatVolume vol,
dir_t dir 
)

Open a file or subdirectory by directory structure.

Parameters
[in]volThe FAT volume that contains the file or subdirectory.
[in]dirThe directory structure describing the file or subdirectory.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include the FAT volume, vol, has not been initialized, vol is a FAT12 volume or dir is not a valid directory entry.

◆ open() [2/3]

uint8_t FatReader::open ( FatReader dir,
char *  name 
)

Open a file or subdirectory by name.

Note
The file or subdirectory, name, must be in the specified directory, dir, and must have a DOS 8.3 name.
Parameters
[in]dirAn open FatReader instance for the directory.
[in]nameA valid 8.3 DOS name for a file or subdirectory in the directory dir.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include the FAT volume has not been initialized, dir is not a directory, name is invalid, the file or subdirectory does not exist, or an I/O error occurred.

◆ open() [3/3]

uint8_t FatReader::open ( FatReader dir,
uint16_t  index 
)

Open a file or subdirectory by index.

Parameters
[in]dirAn open FatReader instance for the directory.
[in]indexThe index for a file or subdirectory in the directory dir. index is the byte offset divided by 32 of the directory entry for the file or subdirectory.

To determine the index for a file open it by name. The index for the file is then is: (dir.readPosition()/32 -1)

Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include the FAT volume has not been initialized, dir is not a directory, name is invalid, the file or subdirectory does not exist, or an I/O error occurred.

◆ optimizeContiguous()

void FatReader::optimizeContiguous ( void  )

Check for a contiguous file and enable optimized reads if the file is contiguous.

◆ read()

int16_t FatReader::read ( void *  buf,
uint16_t  count 
)

Read data from a file at starting at the current read position.

Parameters
[out]bufPointer to the location that will receive the data.
[in]countMaximum number of bytes to read.
Returns
For success read() returns the number of bytes read. A value less than count, 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()

int8_t FatReader::readDir ( dir_t dir)

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.

◆ rewind()

void FatReader::rewind ( void  )

Set read position to start of file

◆ seekCur()

uint8_t FatReader::seekCur ( uint32_t  offset)

Set the read position for a file or directory to the current position plus offset.

Parameters
[in]offsetThe amount to advance the read position.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure.

◆ close()

void FatReader::close ( void  )
inline

Close this instance of FatReader.

◆ fileSize()

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

◆ fileType()

uint8_t FatReader::fileType ( void  )
inline

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

Returns
The file or directory type.

◆ firstCluster()

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

◆ isContiguous()

uint8_t FatReader::isContiguous ( void  )
inline
Returns
True if the bit for optimized reads is set. See optimizeContiguous().

◆ isDir()

uint8_t FatReader::isDir ( void  )
inline
Returns
True if this is a FatReader for a directory else false

◆ isFile()

uint8_t FatReader::isFile ( void  )
inline
Returns
True if this is a FatReader for a file else false

◆ isOpen()

uint8_t FatReader::isOpen ( void  )
inline
Returns
True if FatReader is for an open file/directory else false

◆ readCluster()

uint32_t FatReader::readCluster ( void  )
inline
Returns
The current cluster number for a file or directory.

◆ readPosition()

uint32_t FatReader::readPosition ( void  )
inline
Returns
The read position for a file or directory.

◆ seekSet()

uint8_t FatReader::seekSet ( uint32_t  pos)
inline

Set the read position for a file or directory to pos.

Parameters
[in]posThe new read 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.

◆ volume()

FatVolume* FatReader::volume ( void  )
inline

get the parent volume

Returns
the parent volume

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