Arduino IDE  0
Arduino IDE and compiler
SdVolume Class Reference

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

#include <SdFat.h>

+ Collaboration diagram for SdVolume:

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)
 
 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)
 
static uint8_t * cacheClear (void)
 
static Sd2CardsdCard (void)
 

Friends

class SdFile
 

Detailed Description

Access FAT16 and FAT32 volumes on SD and SDHC cards.

Definition at line 431 of file SdFat.h.

Constructor & Destructor Documentation

◆ SdVolume() [1/2]

SdVolume::SdVolume ( void  )

Create an instance of SdVolume

Definition at line 434 of file SdFat.h.

434 :allocSearchStart_(2), fatType_(0) {}

◆ SdVolume() [2/2]

SdVolume::SdVolume ( void  )

Create an instance of SdVolume

Definition at line 434 of file SdFat.h.

434 :allocSearchStart_(2), fatType_(0) {}

Member Function Documentation

◆ blocksPerCluster() [1/2]

uint8_t SdVolume::blocksPerCluster ( void  ) const
Returns
The volume's cluster size in blocks.

Definition at line 459 of file SdFat.h.

459 {return blocksPerCluster_;}

◆ blocksPerCluster() [2/2]

uint8_t SdVolume::blocksPerCluster ( void  ) const
Returns
The volume's cluster size in blocks.

Definition at line 459 of file SdFat.h.

459 {return blocksPerCluster_;}

◆ blocksPerFat() [1/2]

uint32_t SdVolume::blocksPerFat ( void  ) const
Returns
The number of blocks in one FAT.

Definition at line 461 of file SdFat.h.

461 {return blocksPerFat_;}

◆ blocksPerFat() [2/2]

uint32_t SdVolume::blocksPerFat ( void  ) const
Returns
The number of blocks in one FAT.

Definition at line 461 of file SdFat.h.

461 {return blocksPerFat_;}

◆ cacheClear() [1/2]

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.

Definition at line 438 of file SdFat.h.

438  {
439  cacheFlush();
440  cacheBlockNumber_ = 0XFFFFFFFF;
441  return cacheBuffer_.data;
442  }
uint8_t data[512]
Definition: SdFat.h:414

◆ cacheClear() [2/2]

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.

Definition at line 438 of file SdFat.h.

438  {
439  cacheFlush();
440  cacheBlockNumber_ = 0XFFFFFFFF;
441  return cacheBuffer_.data;
442  }
uint8_t data[512]
Definition: SdFat.h:414

◆ clusterCount() [1/2]

uint32_t SdVolume::clusterCount ( void  ) const
Returns
The total number of clusters in the volume.

Definition at line 463 of file SdFat.h.

463 {return clusterCount_;}

◆ clusterCount() [2/2]

uint32_t SdVolume::clusterCount ( void  ) const
Returns
The total number of clusters in the volume.

Definition at line 463 of file SdFat.h.

463 {return clusterCount_;}

◆ clusterSizeShift() [1/2]

uint8_t SdVolume::clusterSizeShift ( void  ) const
Returns
The shift count required to multiply by blocksPerCluster.

Definition at line 465 of file SdFat.h.

465 {return clusterSizeShift_;}

◆ clusterSizeShift() [2/2]

uint8_t SdVolume::clusterSizeShift ( void  ) const
Returns
The shift count required to multiply by blocksPerCluster.

Definition at line 465 of file SdFat.h.

465 {return clusterSizeShift_;}

◆ dataStartBlock() [1/2]

uint32_t SdVolume::dataStartBlock ( void  ) const
Returns
The logical block number for the start of file data.

Definition at line 467 of file SdFat.h.

467 {return dataStartBlock_;}

◆ dataStartBlock() [2/2]

uint32_t SdVolume::dataStartBlock ( void  ) const
Returns
The logical block number for the start of file data.

Definition at line 467 of file SdFat.h.

467 {return dataStartBlock_;}

◆ fatCount() [1/2]

uint8_t SdVolume::fatCount ( void  ) const
Returns
The number of FAT structures on the volume.

Definition at line 469 of file SdFat.h.

469 {return fatCount_;}

◆ fatCount() [2/2]

uint8_t SdVolume::fatCount ( void  ) const
Returns
The number of FAT structures on the volume.

Definition at line 469 of file SdFat.h.

469 {return fatCount_;}

◆ fatStartBlock() [1/2]

uint32_t SdVolume::fatStartBlock ( void  ) const
Returns
The logical block number for the start of the first FAT.

Definition at line 471 of file SdFat.h.

471 {return fatStartBlock_;}

◆ fatStartBlock() [2/2]

uint32_t SdVolume::fatStartBlock ( void  ) const
Returns
The logical block number for the start of the first FAT.

Definition at line 471 of file SdFat.h.

471 {return fatStartBlock_;}

◆ fatType() [1/2]

uint8_t SdVolume::fatType ( void  ) const
Returns
The FAT type of the volume. Values are 12, 16 or 32.

Definition at line 473 of file SdFat.h.

473 {return fatType_;}

◆ fatType() [2/2]

uint8_t SdVolume::fatType ( void  ) const
Returns
The FAT type of the volume. Values are 12, 16 or 32.

Definition at line 473 of file SdFat.h.

Referenced by SdFile::openRoot().

473 {return fatType_;}
+ Here is the caller graph for this function:

◆ init() [1/8]

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.

Definition at line 454 of file SdFat.h.

References init(), and part.

Referenced by SDLib::SDClass::begin(), and init().

454 { return init(dev, 1) ? true : init(dev, 0);}
uint8_t init(Sd2Card *dev)
Definition: SdFat.h:454
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init() [2/8]

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.

Definition at line 454 of file SdFat.h.

References init(), and part.

Referenced by init().

454 { return init(dev, 1) ? true : init(dev, 0);}
uint8_t init(Sd2Card *dev)
Definition: SdFat.h:454
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init() [3/8]

uint8_t SdVolume::init ( Sd2Card dev,
uint8_t  part 
)

◆ init() [4/8]

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.

Definition at line 227 of file SdVolume.cpp.

References partitionTable::boot, bpb, fat32BootSector::bpb, biosParmBlock::bytesPerSector, biosParmBlock::fat32RootCluster, biosParmBlock::fatCount, cache_t::fbs, partitionTable::firstSector, cache_t::mbr, masterBootRecord::part, biosParmBlock::reservedSectorCount, biosParmBlock::rootDirEntryCount, biosParmBlock::sectorsPerCluster, biosParmBlock::sectorsPerFat16, biosParmBlock::sectorsPerFat32, partitionTable::totalSectors, biosParmBlock::totalSectors16, and biosParmBlock::totalSectors32.

227  {
228  uint32_t volumeStartBlock = 0;
229  sdCard_ = dev;
230  // if part == 0 assume super floppy with FAT boot sector in block zero
231  // if part > 0 assume mbr volume with partition table
232  if (part) {
233  if (part > 4)return false;
234  if (!cacheRawBlock(volumeStartBlock, CACHE_FOR_READ)) return false;
235  part_t* p = &cacheBuffer_.mbr.part[part-1];
236  if ((p->boot & 0X7F) !=0 ||
237  p->totalSectors < 100 ||
238  p->firstSector == 0) {
239  // not a valid partition
240  return false;
241  }
242  volumeStartBlock = p->firstSector;
243  }
244  if (!cacheRawBlock(volumeStartBlock, CACHE_FOR_READ)) return false;
245  bpb_t* bpb = &cacheBuffer_.fbs.bpb;
246  if (bpb->bytesPerSector != 512 ||
247  bpb->fatCount == 0 ||
248  bpb->reservedSectorCount == 0 ||
249  bpb->sectorsPerCluster == 0) {
250  // not valid FAT volume
251  return false;
252  }
253  fatCount_ = bpb->fatCount;
254  blocksPerCluster_ = bpb->sectorsPerCluster;
255 
256  // determine shift that is same as multiply by blocksPerCluster_
257  clusterSizeShift_ = 0;
258  while (blocksPerCluster_ != (1 << clusterSizeShift_)) {
259  // error if not power of 2
260  if (clusterSizeShift_++ > 7) return false;
261  }
262  blocksPerFat_ = bpb->sectorsPerFat16 ?
263  bpb->sectorsPerFat16 : bpb->sectorsPerFat32;
264 
265  fatStartBlock_ = volumeStartBlock + bpb->reservedSectorCount;
266 
267  // count for FAT16 zero for FAT32
268  rootDirEntryCount_ = bpb->rootDirEntryCount;
269 
270  // directory start for FAT16 dataStart for FAT32
271  rootDirStart_ = fatStartBlock_ + bpb->fatCount * blocksPerFat_;
272 
273  // data start for FAT16 and FAT32
274  dataStartBlock_ = rootDirStart_ + ((32 * bpb->rootDirEntryCount + 511)/512);
275 
276  // total blocks for FAT16 or FAT32
277  uint32_t totalBlocks = bpb->totalSectors16 ?
278  bpb->totalSectors16 : bpb->totalSectors32;
279  // total data blocks
280  clusterCount_ = totalBlocks - (dataStartBlock_ - volumeStartBlock);
281 
282  // divide by cluster size to get cluster count
283  clusterCount_ >>= clusterSizeShift_;
284 
285  // FAT type is determined by cluster count
286  if (clusterCount_ < 4085) {
287  fatType_ = 12;
288  } else if (clusterCount_ < 65525) {
289  fatType_ = 16;
290  } else {
291  rootDirStart_ = bpb->fat32RootCluster;
292  fatType_ = 32;
293  }
294  return true;
295 }
uint32_t totalSectors32
Definition: FatStructs.h:197
uint32_t firstSector
Definition: FatStructs.h:90
uint16_t totalSectors16
Definition: FatStructs.h:167
uint32_t sectorsPerFat32
Definition: FatStructs.h:201
uint32_t totalSectors
Definition: FatStructs.h:92
uint16_t sectorsPerFat16
Definition: FatStructs.h:180
uint8_t sectorsPerCluster
Definition: FatStructs.h:139
fbs_t fbs
Definition: SdFat.h:424
uint32_t fat32RootCluster
Definition: FatStructs.h:222
uint16_t bytesPerSector
Definition: FatStructs.h:133
BIOS parameter block.
Definition: FatStructs.h:128
bpb_t bpb
Definition: FatStructs.h:40
MBR partition table entry.
Definition: FatStructs.h:43
uint8_t fatCount
Definition: FatStructs.h:148
part_t part[4]
Definition: FatStructs.h:112
uint16_t rootDirEntryCount
Definition: FatStructs.h:157
mbr_t mbr
Definition: SdFat.h:422
part_t part[4]
Definition: FatStructs.h:42
uint8_t boot
Definition: FatStructs.h:49
uint16_t reservedSectorCount
Definition: FatStructs.h:144

◆ init() [5/8]

uint8_t SdVolume::init ( Sd2Card dev)
Deprecated:
Use: uint8_t SdVolume::init(Sd2Card* dev);

Definition at line 485 of file SdFat.h.

References init().

Referenced by init().

485 {return init(&dev);} // NOLINT
uint8_t init(Sd2Card *dev)
Definition: SdFat.h:454
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init() [6/8]

uint8_t SdVolume::init ( Sd2Card dev)
Deprecated:
Use: uint8_t SdVolume::init(Sd2Card* dev);

Definition at line 485 of file SdFat.h.

References init().

Referenced by init().

485 {return init(&dev);} // NOLINT
uint8_t init(Sd2Card *dev)
Definition: SdFat.h:454
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init() [7/8]

uint8_t SdVolume::init ( Sd2Card dev,
uint8_t  part 
)
Deprecated:
Use: uint8_t SdVolume::init(Sd2Card* dev, uint8_t vol);

Definition at line 488 of file SdFat.h.

488  { // NOLINT
489  return init(&dev, part);
490  }
uint8_t init(Sd2Card *dev)
Definition: SdFat.h:454
part_t part[4]
Definition: FatStructs.h:42

◆ init() [8/8]

uint8_t SdVolume::init ( Sd2Card dev,
uint8_t  part 
)
Deprecated:
Use: uint8_t SdVolume::init(Sd2Card* dev, uint8_t vol);

Definition at line 488 of file SdFat.h.

References SdFile::curCluster(), FAT16EOC_MIN, FAT32EOC_MIN, Sd2Card::readBlock(), Sd2Card::readData(), and Sd2Card::writeBlock().

488  { // NOLINT
489  return init(&dev, part);
490  }
uint8_t init(Sd2Card *dev)
Definition: SdFat.h:454
part_t part[4]
Definition: FatStructs.h:42
+ Here is the call graph for this function:

◆ rootDirEntryCount() [1/2]

uint32_t SdVolume::rootDirEntryCount ( void  ) const
Returns
The number of entries in the root directory for FAT16 volumes.

Definition at line 475 of file SdFat.h.

475 {return rootDirEntryCount_;}

◆ rootDirEntryCount() [2/2]

uint32_t SdVolume::rootDirEntryCount ( void  ) const
Returns
The number of entries in the root directory for FAT16 volumes.

Definition at line 475 of file SdFat.h.

Referenced by SdFile::openRoot().

475 {return rootDirEntryCount_;}
+ Here is the caller graph for this function:

◆ rootDirStart() [1/2]

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.

Definition at line 478 of file SdFat.h.

478 {return rootDirStart_;}

◆ rootDirStart() [2/2]

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.

Definition at line 478 of file SdFat.h.

Referenced by SdFile::openRoot(), and SdFile::read().

478 {return rootDirStart_;}
+ Here is the caller graph for this function:

◆ sdCard() [1/2]

static Sd2Card* SdVolume::sdCard ( void  )
static

return a pointer to the Sd2Card object for this volume

Definition at line 480 of file SdFat.h.

480 {return sdCard_;}

◆ sdCard() [2/2]

static Sd2Card* SdVolume::sdCard ( void  )
static

return a pointer to the Sd2Card object for this volume

Definition at line 480 of file SdFat.h.

480 {return sdCard_;}

Friends And Related Function Documentation

◆ SdFile

SdFile
friend

Definition at line 495 of file SdFat.h.


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