pic32/libraries/SD/utility/SdFile.cpp
//------------------------------------------------------------------------------
// open a cached directory entry. Assumes vol_ is initializes
open a cached directory entry. Assumes vol_ is initializes
open a cached directory entry . Assumes vol_ is initializes
uint8_t SdFile::openCachedEntry(uint8_t dirIndex, uint8_t oflag) {
  dir_t* p = SdVolume::cacheBuffer_.dir + dirIndex;
  if (p->attributes & (DIR_ATT_READ_ONLY | DIR_ATT_DIRECTORY)) {
    if (oflag & (O_WRITE | O_TRUNC)) return false;
  }
  dirIndex_ = dirIndex;
  dirBlock_ = SdVolume::cacheBlockNumber_;
  firstCluster_ = (uint32_t)p->firstClusterHigh << 16;
  firstCluster_ |= p->firstClusterLow;
  if (DIR_IS_FILE(p)) {
    fileSize_ = p->fileSize;
    type_ = FAT_FILE_TYPE_NORMAL;
  } else if (DIR_IS_SUBDIR(p)) {
    if (!vol_->chainSize(firstCluster_, &fileSize_)) return false;
    type_ = FAT_FILE_TYPE_SUBDIR;
  } else {
    return false;
  }
  flags_ = oflag & (O_ACCMODE | O_SYNC | O_APPEND);
  curCluster_ = 0;
  curPosition_ = 0;
  if (oflag & O_TRUNC) return truncate(0);
  return true;
}
uint8_t SdFile :: openCachedEntry ( uint8_t dirIndex , uint8_t oflag ) { dir_t * p = SdVolume :: cacheBuffer_ . dir + dirIndex ; if ( p -> attributes & ( DIR_ATT_READ_ONLY | DIR_ATT_DIRECTORY ) ) { if ( oflag & ( O_WRITE | O_TRUNC ) ) return false ; } dirIndex_ = dirIndex ; dirBlock_ = SdVolume :: cacheBlockNumber_ ; firstCluster_ = ( uint32_t ) p -> firstClusterHigh << 16 ; firstCluster_ |= p -> firstClusterLow ; if ( DIR_IS_FILE ( p ) ) { fileSize_ = p -> fileSize ; type_ = FAT_FILE_TYPE_NORMAL ; } else if ( DIR_IS_SUBDIR ( p ) ) { if ( ! vol_ -> chainSize ( firstCluster_ , & fileSize_ ) ) return false ; type_ = FAT_FILE_TYPE_SUBDIR ; } else { return false ; } flags_ = oflag & ( O_ACCMODE | O_SYNC | O_APPEND ) ; curCluster_ = 0 ; curPosition_ = 0 ; if ( oflag & O_TRUNC ) return truncate ( 0 ) ; return true ; }
open a cached directory entry.
open a cached directory entry .
// location of entry in cache // write or truncate is an error for a directory or read-only file // remember location of directory entry on SD // copy first cluster number for directory fields // make sure it is a normal file or subdirectory // save open flags for read/write // set to start of file // truncate file to zero length if requested