ESP8266
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
SdVolume Class Reference

Access FAT16 and FAT32 volumes on SD and SDHC cards. More...

Public Member Functions

 SdVolume (void)
 
uint8_t init (Sd2Card *dev)
 
uint8_t init (Sd2Card *dev, uint8_t part)
 
uint8_t blocksPerCluster (void) const
 
uint32_t blocksPerFat (void) const
 
uint32_t clusterCount (void) const
 
uint8_t clusterSizeShift (void) const
 
uint32_t dataStartBlock (void) const
 
uint8_t fatCount (void) const
 
uint32_t fatStartBlock (void) const
 
uint8_t fatType (void) const
 
uint32_t rootDirEntryCount (void) const
 
uint32_t rootDirStart (void) const
 
uint8_t init (Sd2Card &dev)
 
uint8_t init (Sd2Card &dev, uint8_t part)
 

Static Public Member Functions

static uint8_t * cacheClear (void)
 
static Sd2CardsdCard (void)
 

Private Member Functions

uint8_t allocContiguous (uint32_t count, uint32_t *curCluster)
 
uint8_t blockOfCluster (uint32_t position) const
 
uint32_t clusterStartBlock (uint32_t cluster) const
 
uint32_t blockNumber (uint32_t cluster, uint32_t position) const
 
uint8_t chainSize (uint32_t beginCluster, uint32_t *size) const
 
uint8_t fatGet (uint32_t cluster, uint32_t *value) const
 
uint8_t fatPut (uint32_t cluster, uint32_t value)
 
uint8_t fatPutEOC (uint32_t cluster)
 
uint8_t freeChain (uint32_t cluster)
 
uint8_t isEOC (uint32_t cluster) const
 
uint8_t readBlock (uint32_t block, uint8_t *dst)
 
uint8_t readData (uint32_t block, uint16_t offset, uint16_t count, uint8_t *dst)
 
uint8_t writeBlock (uint32_t block, const uint8_t *dst)
 

Static Private Member Functions

static uint8_t cacheFlush (void)
 
static uint8_t cacheRawBlock (uint32_t blockNumber, uint8_t action)
 
static void cacheSetDirty (void)
 
static uint8_t cacheZeroBlock (uint32_t blockNumber)
 

Private Attributes

uint32_t allocSearchStart_
 
uint8_t blocksPerCluster_
 
uint32_t blocksPerFat_
 
uint32_t clusterCount_
 
uint8_t clusterSizeShift_
 
uint32_t dataStartBlock_
 
uint8_t fatCount_
 
uint32_t fatStartBlock_
 
uint8_t fatType_
 
uint16_t rootDirEntryCount_
 
uint32_t rootDirStart_
 

Static Private Attributes

static uint8_t const CACHE_FOR_READ = 0
 
static uint8_t const CACHE_FOR_WRITE = 1
 
static cache_t cacheBuffer_
 
static uint32_t cacheBlockNumber_ = 0XFFFFFFFF
 
static Sd2CardsdCard_
 
static uint8_t cacheDirty_ = 0
 
static uint32_t cacheMirrorBlock_ = 0
 

Detailed Description

Access FAT16 and FAT32 volumes on SD and SDHC cards.

Constructor & Destructor Documentation

SdVolume::SdVolume ( void  )

Create an instance of SdVolume

Member Function Documentation

uint8_t SdVolume::allocContiguous ( uint32_t  count,
uint32_t *  curCluster 
)
private
uint32_t SdVolume::blockNumber ( uint32_t  cluster,
uint32_t  position 
) const
private
uint8_t SdVolume::blockOfCluster ( uint32_t  position) const
private
uint8_t SdVolume::blocksPerCluster ( void  ) const
Returns
The volume's cluster size in blocks.
uint32_t SdVolume::blocksPerFat ( void  ) const
Returns
The number of blocks in one FAT.
static uint8_t* SdVolume::cacheClear ( void  )
static

Clear the cache and returns a pointer to the cache. Used by the WaveRP recorder to do raw write to the SD card. Not for normal apps.

uint8_t SdVolume::cacheFlush ( void  )
staticprivate
uint8_t SdVolume::cacheRawBlock ( uint32_t  blockNumber,
uint8_t  action 
)
staticprivate
static void SdVolume::cacheSetDirty ( void  )
staticprivate
uint8_t SdVolume::cacheZeroBlock ( uint32_t  blockNumber)
staticprivate
uint8_t SdVolume::chainSize ( uint32_t  beginCluster,
uint32_t *  size 
) const
private
uint32_t SdVolume::clusterCount ( void  ) const
Returns
The total number of clusters in the volume.
uint8_t SdVolume::clusterSizeShift ( void  ) const
Returns
The shift count required to multiply by blocksPerCluster.
uint32_t SdVolume::clusterStartBlock ( uint32_t  cluster) const
private
uint32_t SdVolume::dataStartBlock ( void  ) const
Returns
The logical block number for the start of file data.
uint8_t SdVolume::fatCount ( void  ) const
Returns
The number of FAT structures on the volume.
uint8_t SdVolume::fatGet ( uint32_t  cluster,
uint32_t *  value 
) const
private
uint8_t SdVolume::fatPut ( uint32_t  cluster,
uint32_t  value 
)
private
uint8_t SdVolume::fatPutEOC ( uint32_t  cluster)
private
uint32_t SdVolume::fatStartBlock ( void  ) const
Returns
The logical block number for the start of the first FAT.
uint8_t SdVolume::fatType ( void  ) const
Returns
The FAT type of the volume. Values are 12, 16 or 32.
uint8_t SdVolume::freeChain ( uint32_t  cluster)
private
uint8_t SdVolume::init ( Sd2Card dev)

Initialize a FAT volume. Try partition one first then try super floppy format.

Parameters
[in]devThe Sd2Card where the volume is located.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include not finding a valid partition, not finding a valid FAT file system or an I/O error.
uint8_t SdVolume::init ( Sd2Card dev,
uint8_t  part 
)

Initialize a FAT volume.

Parameters
[in]devThe SD card where the volume is located.
[in]partThe partition to be used. Legal values for part are 1-4 to use the corresponding partition on a device formatted with a MBR, Master Boot Record, or zero if the device is formatted as a super floppy with the FAT boot sector in block zero.
Returns
The value one, true, is returned for success and the value zero, false, is returned for failure. Reasons for failure include not finding a valid partition, not finding a valid FAT file system in the specified partition or an I/O error.
uint8_t SdVolume::init ( Sd2Card dev)
uint8_t SdVolume::init ( Sd2Card dev,
uint8_t  part 
)
uint8_t SdVolume::isEOC ( uint32_t  cluster) const
private
uint8_t SdVolume::readBlock ( uint32_t  block,
uint8_t *  dst 
)
private
uint8_t SdVolume::readData ( uint32_t  block,
uint16_t  offset,
uint16_t  count,
uint8_t *  dst 
)
private
uint32_t SdVolume::rootDirEntryCount ( void  ) const
Returns
The number of entries in the root directory for FAT16 volumes.
uint32_t SdVolume::rootDirStart ( void  ) const
Returns
The logical block number for the start of the root directory on FAT16 volumes or the first cluster number on FAT32 volumes.
static Sd2Card* SdVolume::sdCard ( void  )
static

return a pointer to the Sd2Card object for this volume

uint8_t SdVolume::writeBlock ( uint32_t  block,
const uint8_t *  dst 
)
private

Member Data Documentation

uint32_t SdVolume::allocSearchStart_
private
uint8_t SdVolume::blocksPerCluster_
private
uint32_t SdVolume::blocksPerFat_
private
uint8_t const SdVolume::CACHE_FOR_READ = 0
staticprivate
uint8_t const SdVolume::CACHE_FOR_WRITE = 1
staticprivate
uint32_t SdVolume::cacheBlockNumber_ = 0XFFFFFFFF
staticprivate
cache_t SdVolume::cacheBuffer_
staticprivate
uint8_t SdVolume::cacheDirty_ = 0
staticprivate
uint32_t SdVolume::cacheMirrorBlock_ = 0
staticprivate
uint32_t SdVolume::clusterCount_
private
uint8_t SdVolume::clusterSizeShift_
private
uint32_t SdVolume::dataStartBlock_
private
uint8_t SdVolume::fatCount_
private
uint32_t SdVolume::fatStartBlock_
private
uint8_t SdVolume::fatType_
private
uint16_t SdVolume::rootDirEntryCount_
private
uint32_t SdVolume::rootDirStart_
private
Sd2Card * SdVolume::sdCard_
staticprivate