pic32/libraries/SD/utility/SdFile.cpp
//------------------------------------------------------------------------------
/**
 * 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.
 *
 * \param[in] dirFile The directory where the file will be created.
 * \param[in] fileName A valid DOS 8.3 file name.
 * \param[in] size The desired file size.
 *
 * \return The value one, true, is returned for success and
 * the value zero, false, is returned for failure.
 * Reasons for failure include \a fileName 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.
 *
 */
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.

\param[in] dirFile The directory where the file will be created.
\param[in] fileName A valid DOS 8.3 file name.
\param[in] size The desired file size.

\return The value one, true, is returned for success and
the value zero, false, is returned for failure.
Reasons for failure include \a fileName 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.
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 . \ param [ in ] dirFile The directory where the file will be created . \ param [ in ] fileName A valid DOS 8 . 3 file name . \ param [ in ] size The desired file size . \ return The value one true is returned for success and the value zero false is returned for failure . Reasons for failure include \ a fileName 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 .
uint8_t SdFile::createContiguous(SdFile* dirFile,
        const char* fileName, uint32_t size) {
  if (size == 0) return false;
  if (!open(dirFile, fileName, O_CREAT | O_EXCL | O_RDWR)) return false;
  uint32_t count = ((size - 1) >> (vol_->clusterSizeShift_ + 9)) + 1;
  if (!vol_->allocContiguous(count, &firstCluster_)) {
    remove();
    return false;
  }
  fileSize_ = size;
  flags_ |= F_FILE_DIR_DIRTY;
  return sync();
}
uint8_t SdFile :: createContiguous ( SdFile * dirFile , const char * fileName , uint32_t size ) { if ( size == 0 ) return false ; if ( ! open ( dirFile , fileName , O_CREAT | O_EXCL | O_RDWR ) ) return false ; uint32_t count = ( ( size - 1 ) >> ( vol_ -> clusterSizeShift_ + 9 ) ) + 1 ; if ( ! vol_ -> allocContiguous ( count , & firstCluster_ ) ) { remove ( ) ; return false ; } fileSize_ = size ; flags_ |= F_FILE_DIR_DIRTY ; return sync ( ) ; }
Create and open a new contiguous file of a specified size.
Create and open a new contiguous file of a specified size .
// don't allow zero length file // calculate number of clusters needed // allocate clusters // insure sync() will update dir entry