Styling adjustments (PR#2668 & PR#2670)
Keep "astyled" reformatting
This commit is contained in:
committed by
Richard Wackerbarth
parent
b5fb7075b9
commit
0c7f7ebcfb
@ -48,7 +48,7 @@ bool SdBaseFile::addCluster() {
|
||||
bool SdBaseFile::addDirCluster() {
|
||||
uint32_t block;
|
||||
// max folder size
|
||||
if (fileSize_/sizeof(dir_t) >= 0XFFFF) goto fail;
|
||||
if (fileSize_ / sizeof(dir_t) >= 0XFFFF) goto fail;
|
||||
|
||||
if (!addCluster()) goto fail;
|
||||
if (!vol_->cacheFlush()) goto fail;
|
||||
@ -68,8 +68,7 @@ bool SdBaseFile::addDirCluster() {
|
||||
// Increase directory file size by cluster size
|
||||
fileSize_ += 512UL << vol_->clusterSizeShift_;
|
||||
return true;
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -78,8 +77,7 @@ bool SdBaseFile::addDirCluster() {
|
||||
dir_t* SdBaseFile::cacheDirEntry(uint8_t action) {
|
||||
if (!vol_->cacheRawBlock(dirBlock_, action)) goto fail;
|
||||
return vol_->cache()->dir + dirIndex_;
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return 0;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -125,7 +123,7 @@ bool SdBaseFile::contiguousRange(uint32_t* bgnBlock, uint32_t* endBlock) {
|
||||
}
|
||||
}
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -147,7 +145,7 @@ bool SdBaseFile::contiguousRange(uint32_t* bgnBlock, uint32_t* endBlock) {
|
||||
*
|
||||
*/
|
||||
bool SdBaseFile::createContiguous(SdBaseFile* dirFile,
|
||||
const char* path, uint32_t size) {
|
||||
const char* path, uint32_t size) {
|
||||
uint32_t count;
|
||||
// don't allow zero length file
|
||||
if (size == 0) goto fail;
|
||||
@ -167,8 +165,7 @@ bool SdBaseFile::createContiguous(SdBaseFile* dirFile,
|
||||
flags_ |= F_FILE_DIR_DIRTY;
|
||||
|
||||
return sync();
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -191,8 +188,7 @@ bool SdBaseFile::dirEntry(dir_t* dir) {
|
||||
// copy to caller's struct
|
||||
memcpy(dir, p, sizeof(dir_t));
|
||||
return true;
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -258,7 +254,8 @@ int16_t SdBaseFile::fgets(char* str, int16_t num, char* delim) {
|
||||
str[n++] = ch;
|
||||
if (!delim) {
|
||||
if (ch == '\n') break;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (strchr(delim, ch)) break;
|
||||
}
|
||||
}
|
||||
@ -318,11 +315,11 @@ void SdBaseFile::getpos(fpos_t* pos) {
|
||||
void SdBaseFile::ls(uint8_t flags, uint8_t indent) {
|
||||
rewind();
|
||||
int8_t status;
|
||||
while ((status = lsPrintNext( flags, indent))) {
|
||||
while ((status = lsPrintNext(flags, indent))) {
|
||||
if (status > 1 && (flags & LS_R)) {
|
||||
uint16_t index = curPosition()/32 - 1;
|
||||
uint16_t index = curPosition() / 32 - 1;
|
||||
SdBaseFile s;
|
||||
if (s.open(this, index, O_READ)) s.ls( flags, indent + 2);
|
||||
if (s.open(this, index, O_READ)) s.ls(flags, indent + 2);
|
||||
seekSet(32 * (index + 1));
|
||||
}
|
||||
}
|
||||
@ -330,7 +327,7 @@ void SdBaseFile::ls(uint8_t flags, uint8_t indent) {
|
||||
//------------------------------------------------------------------------------
|
||||
// saves 32 bytes on stack for ls recursion
|
||||
// return 0 - EOF, 1 - normal file, or 2 - directory
|
||||
int8_t SdBaseFile::lsPrintNext( uint8_t flags, uint8_t indent) {
|
||||
int8_t SdBaseFile::lsPrintNext(uint8_t flags, uint8_t indent) {
|
||||
dir_t dir;
|
||||
uint8_t w = 0;
|
||||
|
||||
@ -340,7 +337,7 @@ int8_t SdBaseFile::lsPrintNext( uint8_t flags, uint8_t indent) {
|
||||
|
||||
// skip deleted entry and entries for . and ..
|
||||
if (dir.name[0] != DIR_NAME_DELETED && dir.name[0] != '.'
|
||||
&& DIR_IS_FILE_OR_SUBDIR(&dir)) break;
|
||||
&& DIR_IS_FILE_OR_SUBDIR(&dir)) break;
|
||||
}
|
||||
// indent for dir level
|
||||
for (uint8_t i = 0; i < indent; i++) MYSERIAL.write(' ');
|
||||
@ -365,9 +362,9 @@ int8_t SdBaseFile::lsPrintNext( uint8_t flags, uint8_t indent) {
|
||||
// print modify date/time if requested
|
||||
if (flags & LS_DATE) {
|
||||
MYSERIAL.write(' ');
|
||||
printFatDate( dir.lastWriteDate);
|
||||
printFatDate(dir.lastWriteDate);
|
||||
MYSERIAL.write(' ');
|
||||
printFatTime( dir.lastWriteTime);
|
||||
printFatTime(dir.lastWriteTime);
|
||||
}
|
||||
// print size if requested
|
||||
if (!DIR_IS_SUBDIR(&dir) && (flags & LS_SIZE)) {
|
||||
@ -392,7 +389,8 @@ bool SdBaseFile::make83Name(const char* str, uint8_t* name, const char** ptr) {
|
||||
if (n == 10) goto fail; // only one dot allowed
|
||||
n = 10; // max index for full 8.3 name
|
||||
i = 8; // place for extension
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// illegal FAT characters
|
||||
PGM_P p = PSTR("|<>^+=?/[];,*\"\\");
|
||||
uint8_t b;
|
||||
@ -400,14 +398,13 @@ bool SdBaseFile::make83Name(const char* str, uint8_t* name, const char** ptr) {
|
||||
// check size and only allow ASCII printable characters
|
||||
if (i > n || c < 0X21 || c > 0X7E)goto fail;
|
||||
// only upper case allowed in 8.3 names - convert lower to upper
|
||||
name[i++] = (c < 'a' || c > 'z') ? (c) : (c + ('A' - 'a'));
|
||||
name[i++] = (c < 'a' || c > 'z') ? (c) : (c + ('A' - 'a'));
|
||||
}
|
||||
}
|
||||
*ptr = str;
|
||||
// must have a file name, extension is optional
|
||||
return name[0] != ' ';
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -454,8 +451,7 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const char* path, bool pFlag) {
|
||||
sub = parent != &dir1 ? &dir1 : &dir2;
|
||||
}
|
||||
return mkdir(parent, dname);
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -503,7 +499,8 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const uint8_t dname[11]) {
|
||||
if (parent->isRoot()) {
|
||||
d.firstClusterLow = 0;
|
||||
d.firstClusterHigh = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
d.firstClusterLow = parent->firstCluster_ & 0XFFFF;
|
||||
d.firstClusterHigh = parent->firstCluster_ >> 16;
|
||||
}
|
||||
@ -512,24 +509,23 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const uint8_t dname[11]) {
|
||||
|
||||
// write first block
|
||||
return vol_->cacheFlush();
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/** Open a file in the current working directory.
|
||||
*
|
||||
* \param[in] path A path with a valid 8.3 DOS name for a file to be opened.
|
||||
*
|
||||
* \param[in] oflag Values for \a oflag are constructed by a bitwise-inclusive
|
||||
* OR of open flags. see SdBaseFile::open(SdBaseFile*, const char*, uint8_t).
|
||||
*
|
||||
* \return The value one, true, is returned for success and
|
||||
* the value zero, false, is returned for failure.
|
||||
*/
|
||||
bool SdBaseFile::open(const char* path, uint8_t oflag) {
|
||||
return open(cwd_, path, oflag);
|
||||
}
|
||||
/** Open a file in the current working directory.
|
||||
*
|
||||
* \param[in] path A path with a valid 8.3 DOS name for a file to be opened.
|
||||
*
|
||||
* \param[in] oflag Values for \a oflag are constructed by a bitwise-inclusive
|
||||
* OR of open flags. see SdBaseFile::open(SdBaseFile*, const char*, uint8_t).
|
||||
*
|
||||
* \return The value one, true, is returned for success and
|
||||
* the value zero, false, is returned for failure.
|
||||
*/
|
||||
bool SdBaseFile::open(const char* path, uint8_t oflag) {
|
||||
return open(cwd_, path, oflag);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/** Open a file or directory by name.
|
||||
*
|
||||
@ -584,8 +580,8 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const uint8_t dname[11]) {
|
||||
bool SdBaseFile::open(SdBaseFile* dirFile, const char* path, uint8_t oflag) {
|
||||
uint8_t dname[11];
|
||||
SdBaseFile dir1, dir2;
|
||||
SdBaseFile *parent = dirFile;
|
||||
SdBaseFile *sub = &dir1;
|
||||
SdBaseFile* parent = dirFile;
|
||||
SdBaseFile* sub = &dir1;
|
||||
|
||||
if (!dirFile) goto fail;
|
||||
|
||||
@ -609,14 +605,13 @@ bool SdBaseFile::open(SdBaseFile* dirFile, const char* path, uint8_t oflag) {
|
||||
sub = parent != &dir1 ? &dir1 : &dir2;
|
||||
}
|
||||
return open(parent, dname, oflag);
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
// open with filename in dname
|
||||
bool SdBaseFile::open(SdBaseFile* dirFile,
|
||||
const uint8_t dname[11], uint8_t oflag) {
|
||||
const uint8_t dname[11], uint8_t oflag) {
|
||||
bool emptyFound = false;
|
||||
bool fileFound = false;
|
||||
uint8_t index;
|
||||
@ -641,7 +636,8 @@ bool SdBaseFile::open(SdBaseFile* dirFile,
|
||||
}
|
||||
// done if no entries follow
|
||||
if (p->name[0] == DIR_NAME_FREE) break;
|
||||
} else if (!memcmp(dname, p->name, 11)) {
|
||||
}
|
||||
else if (!memcmp(dname, p->name, 11)) {
|
||||
fileFound = true;
|
||||
break;
|
||||
}
|
||||
@ -649,14 +645,16 @@ bool SdBaseFile::open(SdBaseFile* dirFile,
|
||||
if (fileFound) {
|
||||
// don't open existing file if O_EXCL
|
||||
if (oflag & O_EXCL) goto fail;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// don't create unless O_CREAT and O_WRITE
|
||||
if (!(oflag & O_CREAT) || !(oflag & O_WRITE)) goto fail;
|
||||
if (emptyFound) {
|
||||
index = dirIndex_;
|
||||
p = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
|
||||
if (!p) goto fail;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (dirFile->type_ == FAT_FILE_TYPE_ROOT_FIXED) goto fail;
|
||||
|
||||
// add and zero cluster for dirFile - first cluster is in cache for write
|
||||
@ -674,7 +672,8 @@ bool SdBaseFile::open(SdBaseFile* dirFile,
|
||||
if (dateTime_) {
|
||||
// call user date/time function
|
||||
dateTime_(&p->creationDate, &p->creationTime);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// use default date/time
|
||||
p->creationDate = FAT_DEFAULT_DATE;
|
||||
p->creationTime = FAT_DEFAULT_TIME;
|
||||
@ -688,8 +687,7 @@ bool SdBaseFile::open(SdBaseFile* dirFile,
|
||||
}
|
||||
// open entry in cache
|
||||
return openCachedEntry(index, oflag);
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -731,8 +729,7 @@ bool SdBaseFile::open(SdBaseFile* dirFile, uint16_t index, uint8_t oflag) {
|
||||
}
|
||||
// open cached entry
|
||||
return openCachedEntry(index & 0XF, oflag);
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -757,10 +754,12 @@ bool SdBaseFile::openCachedEntry(uint8_t dirIndex, uint8_t oflag) {
|
||||
if (DIR_IS_FILE(p)) {
|
||||
fileSize_ = p->fileSize;
|
||||
type_ = FAT_FILE_TYPE_NORMAL;
|
||||
} else if (DIR_IS_SUBDIR(p)) {
|
||||
}
|
||||
else if (DIR_IS_SUBDIR(p)) {
|
||||
if (!vol_->chainSize(firstCluster_, &fileSize_)) goto fail;
|
||||
type_ = FAT_FILE_TYPE_SUBDIR;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
goto fail;
|
||||
}
|
||||
// save open flags for read/write
|
||||
@ -771,8 +770,7 @@ bool SdBaseFile::openCachedEntry(uint8_t dirIndex, uint8_t oflag) {
|
||||
curPosition_ = 0;
|
||||
if ((oflag & O_TRUNC) && !truncate(0)) return false;
|
||||
return oflag & O_AT_END ? seekEnd(0) : true;
|
||||
|
||||
fail:
|
||||
fail:
|
||||
type_ = FAT_FILE_TYPE_CLOSED;
|
||||
return false;
|
||||
}
|
||||
@ -818,8 +816,7 @@ bool SdBaseFile::openNext(SdBaseFile* dirFile, uint8_t oflag) {
|
||||
return openCachedEntry(index, oflag);
|
||||
}
|
||||
}
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -862,8 +859,9 @@ bool SdBaseFile::openParent(SdBaseFile* dir) {
|
||||
// '..' is pointer to first cluster of parent. open '../..' to find parent
|
||||
if (p->firstClusterHigh == 0 && p->firstClusterLow == 0) {
|
||||
if (!file.openRoot(dir->volume())) goto fail;
|
||||
} else {
|
||||
if (!file.openCachedEntry(1, O_READ)) goto fail;
|
||||
}
|
||||
else if (!file.openCachedEntry(1, O_READ)) {
|
||||
goto fail;
|
||||
}
|
||||
// search for parent in '../..'
|
||||
do {
|
||||
@ -872,9 +870,8 @@ bool SdBaseFile::openParent(SdBaseFile* dir) {
|
||||
c |= (uint32_t)entry.firstClusterHigh << 16;
|
||||
} while (c != cluster);
|
||||
// open parent
|
||||
return open(&file, file.curPosition()/32 - 1, O_READ);
|
||||
|
||||
fail:
|
||||
return open(&file, file.curPosition() / 32 - 1, O_READ);
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -895,11 +892,13 @@ bool SdBaseFile::openRoot(SdVolume* vol) {
|
||||
type_ = FAT_FILE_TYPE_ROOT_FIXED;
|
||||
firstCluster_ = 0;
|
||||
fileSize_ = 32 * vol->rootDirEntryCount();
|
||||
} else if (vol->fatType() == 32) {
|
||||
}
|
||||
else if (vol->fatType() == 32) {
|
||||
type_ = FAT_FILE_TYPE_ROOT32;
|
||||
firstCluster_ = vol->rootDirStart();
|
||||
if (!vol->chainSize(firstCluster_, &fileSize_)) goto fail;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// volume is not initialized, invalid, or FAT12 without support
|
||||
return false;
|
||||
}
|
||||
@ -915,8 +914,7 @@ bool SdBaseFile::openRoot(SdVolume* vol) {
|
||||
dirBlock_ = 0;
|
||||
dirIndex_ = 0;
|
||||
return true;
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -940,7 +938,7 @@ int SdBaseFile::peek() {
|
||||
* \param[in] printSlash Print '/' after directory names if true.
|
||||
*/
|
||||
void SdBaseFile::printDirName(const dir_t& dir,
|
||||
uint8_t width, bool printSlash) {
|
||||
uint8_t width, bool printSlash) {
|
||||
uint8_t w = 0;
|
||||
for (uint8_t i = 0; i < 11; i++) {
|
||||
if (dir.name[i] == ' ')continue;
|
||||
@ -962,7 +960,7 @@ void SdBaseFile::printDirName(const dir_t& dir,
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
// print uint8_t with width 2
|
||||
static void print2u( uint8_t v) {
|
||||
static void print2u(uint8_t v) {
|
||||
if (v < 10) MYSERIAL.write('0');
|
||||
MYSERIAL.print(v, DEC);
|
||||
}
|
||||
@ -985,9 +983,9 @@ static void print2u( uint8_t v) {
|
||||
void SdBaseFile::printFatDate(uint16_t fatDate) {
|
||||
MYSERIAL.print(FAT_YEAR(fatDate));
|
||||
MYSERIAL.write('-');
|
||||
print2u( FAT_MONTH(fatDate));
|
||||
print2u(FAT_MONTH(fatDate));
|
||||
MYSERIAL.write('-');
|
||||
print2u( FAT_DAY(fatDate));
|
||||
print2u(FAT_DAY(fatDate));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -998,12 +996,12 @@ void SdBaseFile::printFatDate(uint16_t fatDate) {
|
||||
* \param[in] pr Print stream for output.
|
||||
* \param[in] fatTime The time field from a directory entry.
|
||||
*/
|
||||
void SdBaseFile::printFatTime( uint16_t fatTime) {
|
||||
print2u( FAT_HOUR(fatTime));
|
||||
void SdBaseFile::printFatTime(uint16_t fatTime) {
|
||||
print2u(FAT_HOUR(fatTime));
|
||||
MYSERIAL.write(':');
|
||||
print2u( FAT_MINUTE(fatTime));
|
||||
print2u(FAT_MINUTE(fatTime));
|
||||
MYSERIAL.write(':');
|
||||
print2u( FAT_SECOND(fatTime));
|
||||
print2u(FAT_SECOND(fatTime));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/** Print a file's name to Serial
|
||||
@ -1060,14 +1058,16 @@ int16_t SdBaseFile::read(void* buf, uint16_t nbyte) {
|
||||
offset = curPosition_ & 0X1FF; // offset in block
|
||||
if (type_ == FAT_FILE_TYPE_ROOT_FIXED) {
|
||||
block = vol_->rootDirStart() + (curPosition_ >> 9);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
uint8_t blockOfCluster = vol_->blockOfCluster(curPosition_);
|
||||
if (offset == 0 && blockOfCluster == 0) {
|
||||
// start of new cluster
|
||||
if (curPosition_ == 0) {
|
||||
// use first cluster in file
|
||||
curCluster_ = firstCluster_;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// get next cluster from FAT
|
||||
if (!vol_->fatGet(curCluster_, &curCluster_)) goto fail;
|
||||
}
|
||||
@ -1082,7 +1082,8 @@ int16_t SdBaseFile::read(void* buf, uint16_t nbyte) {
|
||||
// no buffering needed if n == 512
|
||||
if (n == 512 && block != vol_->cacheBlockNumber()) {
|
||||
if (!vol_->readBlock(block, dst)) goto fail;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// read block to cache and copy data to caller
|
||||
if (!vol_->cacheRawBlock(block, SdVolume::CACHE_FOR_READ)) goto fail;
|
||||
uint8_t* src = vol_->cache()->data + offset;
|
||||
@ -1093,8 +1094,7 @@ int16_t SdBaseFile::read(void* buf, uint16_t nbyte) {
|
||||
toRead -= n;
|
||||
}
|
||||
return nbyte;
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1113,7 +1113,7 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
|
||||
int16_t n;
|
||||
// if not a directory file or miss-positioned return an error
|
||||
if (!isDir() || (0X1F & curPosition_)) return -1;
|
||||
|
||||
|
||||
//If we have a longFilename buffer, mark it as invalid. If we find a long filename it will be filled automaticly.
|
||||
if (longFilename != NULL) longFilename[0] = '\0';
|
||||
|
||||
@ -1131,15 +1131,15 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
|
||||
// Fill the long filename if we have a long filename entry.
|
||||
// Long filename entries are stored before the short filename.
|
||||
if (longFilename != NULL && DIR_IS_LONG_NAME(dir)) {
|
||||
vfat_t *VFAT = (vfat_t*)dir;
|
||||
vfat_t* VFAT = (vfat_t*)dir;
|
||||
// Sanity-check the VFAT entry. The first cluster is always set to zero. And the sequence number should be higher than 0
|
||||
if (VFAT->firstClusterLow == 0 && (VFAT->sequenceNumber & 0x1F) > 0 && (VFAT->sequenceNumber & 0x1F) <= MAX_VFAT_ENTRIES) {
|
||||
// TODO: Store the filename checksum to verify if a none-long filename aware system modified the file table.
|
||||
n = ((VFAT->sequenceNumber & 0x1F) - 1) * FILENAME_LENGTH;
|
||||
for (uint8_t i=0; i<FILENAME_LENGTH; i++)
|
||||
longFilename[n+i] = (i < 5) ? VFAT->name1[i] : (i < 11) ? VFAT->name2[i-5] : VFAT->name3[i-11];
|
||||
for (uint8_t i = 0; i < FILENAME_LENGTH; i++)
|
||||
longFilename[n + i] = (i < 5) ? VFAT->name1[i] : (i < 11) ? VFAT->name2[i - 5] : VFAT->name3[i - 11];
|
||||
// If this VFAT entry is the last one, add a NUL terminator at the end of the string
|
||||
if (VFAT->sequenceNumber & 0x40) longFilename[n+FILENAME_LENGTH] = '\0';
|
||||
if (VFAT->sequenceNumber & 0x40) longFilename[n + FILENAME_LENGTH] = '\0';
|
||||
}
|
||||
}
|
||||
// Return if normal file or subdirectory
|
||||
@ -1166,8 +1166,7 @@ dir_t* SdBaseFile::readDirCache() {
|
||||
|
||||
// return pointer to entry
|
||||
return vol_->cache()->dir + i;
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return 0;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -1202,8 +1201,7 @@ bool SdBaseFile::remove() {
|
||||
// write entry to SD
|
||||
return vol_->cacheFlush();
|
||||
return true;
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -1228,8 +1226,7 @@ bool SdBaseFile::remove(SdBaseFile* dirFile, const char* path) {
|
||||
SdBaseFile file;
|
||||
if (!file.open(dirFile, path, O_WRITE)) goto fail;
|
||||
return file.remove();
|
||||
|
||||
fail:
|
||||
fail:
|
||||
// can't set iostate - static function
|
||||
return false;
|
||||
}
|
||||
@ -1272,7 +1269,8 @@ bool SdBaseFile::rename(SdBaseFile* dirFile, const char* newPath) {
|
||||
if (!file.open(dirFile, newPath, O_CREAT | O_EXCL | O_WRITE)) {
|
||||
goto restore;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// don't create missing path prefix components
|
||||
if (!file.mkdir(dirFile, newPath, false)) {
|
||||
goto restore;
|
||||
@ -1311,14 +1309,14 @@ bool SdBaseFile::rename(SdBaseFile* dirFile, const char* newPath) {
|
||||
}
|
||||
return vol_->cacheFlush();
|
||||
|
||||
restore:
|
||||
restore:
|
||||
d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
|
||||
if (!d) goto fail;
|
||||
// restore entry
|
||||
d->name[0] = entry.name[0];
|
||||
vol_->cacheFlush();
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -1358,8 +1356,7 @@ bool SdBaseFile::rmdir() {
|
||||
type_ = FAT_FILE_TYPE_NORMAL;
|
||||
flags_ |= O_WRITE;
|
||||
return remove();
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -1384,7 +1381,7 @@ bool SdBaseFile::rmRfStar() {
|
||||
rewind();
|
||||
while (curPosition_ < fileSize_) {
|
||||
// remember position
|
||||
index = curPosition_/32;
|
||||
index = curPosition_ / 32;
|
||||
|
||||
dir_t* p = readDirCache();
|
||||
if (!p) goto fail;
|
||||
@ -1402,14 +1399,15 @@ bool SdBaseFile::rmRfStar() {
|
||||
if (f.isSubDir()) {
|
||||
// recursively delete
|
||||
if (!f.rmRfStar()) goto fail;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// ignore read-only
|
||||
f.flags_ |= O_WRITE;
|
||||
if (!f.remove()) goto fail;
|
||||
}
|
||||
// position to next entry if required
|
||||
if (curPosition_ != (32*(index + 1))) {
|
||||
if (!seekSet(32*(index + 1))) goto fail;
|
||||
if (curPosition_ != (32 * (index + 1))) {
|
||||
if (!seekSet(32 * (index + 1))) goto fail;
|
||||
}
|
||||
}
|
||||
// don't try to delete root
|
||||
@ -1417,8 +1415,7 @@ bool SdBaseFile::rmRfStar() {
|
||||
if (!rmdir()) goto fail;
|
||||
}
|
||||
return true;
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -1465,7 +1462,8 @@ bool SdBaseFile::seekSet(uint32_t pos) {
|
||||
if (nNew < nCur || curPosition_ == 0) {
|
||||
// must follow chain from first cluster
|
||||
curCluster_ = firstCluster_;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// advance from curPosition
|
||||
nNew -= nCur;
|
||||
}
|
||||
@ -1474,10 +1472,10 @@ bool SdBaseFile::seekSet(uint32_t pos) {
|
||||
}
|
||||
curPosition_ = pos;
|
||||
|
||||
done:
|
||||
done:
|
||||
return true;
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -1520,7 +1518,7 @@ bool SdBaseFile::sync() {
|
||||
}
|
||||
return vol_->cacheFlush();
|
||||
|
||||
fail:
|
||||
fail:
|
||||
writeError = true;
|
||||
return false;
|
||||
}
|
||||
@ -1560,7 +1558,7 @@ bool SdBaseFile::timestamp(SdBaseFile* file) {
|
||||
// write back entry
|
||||
return vol_->cacheFlush();
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -1598,22 +1596,22 @@ bool SdBaseFile::timestamp(SdBaseFile* file) {
|
||||
* the value zero, false, is returned for failure.
|
||||
*/
|
||||
bool SdBaseFile::timestamp(uint8_t flags, uint16_t year, uint8_t month,
|
||||
uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) {
|
||||
uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) {
|
||||
uint16_t dirDate;
|
||||
uint16_t dirTime;
|
||||
dir_t* d;
|
||||
|
||||
if (!isOpen()
|
||||
|| year < 1980
|
||||
|| year > 2107
|
||||
|| month < 1
|
||||
|| month > 12
|
||||
|| day < 1
|
||||
|| day > 31
|
||||
|| hour > 23
|
||||
|| minute > 59
|
||||
|| second > 59) {
|
||||
goto fail;
|
||||
|| year < 1980
|
||||
|| year > 2107
|
||||
|| month < 1
|
||||
|| month > 12
|
||||
|| day < 1
|
||||
|| day > 31
|
||||
|| hour > 23
|
||||
|| minute > 59
|
||||
|| second > 59) {
|
||||
goto fail;
|
||||
}
|
||||
// update directory entry
|
||||
if (!sync()) goto fail;
|
||||
@ -1637,8 +1635,7 @@ bool SdBaseFile::timestamp(uint8_t flags, uint16_t year, uint8_t month,
|
||||
d->lastWriteTime = dirTime;
|
||||
}
|
||||
return vol_->cacheFlush();
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -1674,7 +1671,8 @@ bool SdBaseFile::truncate(uint32_t length) {
|
||||
// free all clusters
|
||||
if (!vol_->freeChain(firstCluster_)) goto fail;
|
||||
firstCluster_ = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
uint32_t toFree;
|
||||
if (!vol_->fatGet(curCluster_, &toFree)) goto fail;
|
||||
|
||||
@ -1696,7 +1694,7 @@ bool SdBaseFile::truncate(uint32_t length) {
|
||||
// set file to correct position
|
||||
return seekSet(newPos);
|
||||
|
||||
fail:
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -1739,16 +1737,19 @@ int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) {
|
||||
if (firstCluster_ == 0) {
|
||||
// allocate first cluster of file
|
||||
if (!addCluster()) goto fail;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
curCluster_ = firstCluster_;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
uint32_t next;
|
||||
if (!vol_->fatGet(curCluster_, &next)) goto fail;
|
||||
if (vol_->isEOC(next)) {
|
||||
// add cluster if at end of chain
|
||||
if (!addCluster()) goto fail;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
curCluster_ = next;
|
||||
}
|
||||
}
|
||||
@ -1768,13 +1769,15 @@ int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) {
|
||||
vol_->cacheSetBlockNumber(0XFFFFFFFF, false);
|
||||
}
|
||||
if (!vol_->writeBlock(block, src)) goto fail;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (blockOffset == 0 && curPosition_ >= fileSize_) {
|
||||
// start of new block don't need to read into cache
|
||||
if (!vol_->cacheFlush()) goto fail;
|
||||
// set cache dirty and SD address of block
|
||||
vol_->cacheSetBlockNumber(block, true);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// rewrite part of block
|
||||
if (!vol_->cacheRawBlock(block, SdVolume::CACHE_FOR_WRITE)) goto fail;
|
||||
}
|
||||
@ -1789,7 +1792,8 @@ int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) {
|
||||
// update fileSize and insure sync will update dir entry
|
||||
fileSize_ = curPosition_;
|
||||
flags_ |= F_FILE_DIR_DIRTY;
|
||||
} else if (dateTime_ && nbyte) {
|
||||
}
|
||||
else if (dateTime_ && nbyte) {
|
||||
// insure sync will update modified date and time
|
||||
flags_ |= F_FILE_DIR_DIRTY;
|
||||
}
|
||||
@ -1799,7 +1803,7 @@ int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) {
|
||||
}
|
||||
return nbyte;
|
||||
|
||||
fail:
|
||||
fail:
|
||||
// return for write error
|
||||
writeError = true;
|
||||
return -1;
|
||||
@ -1807,7 +1811,7 @@ int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) {
|
||||
//------------------------------------------------------------------------------
|
||||
// suppress cpplint warnings with NOLINT comment
|
||||
#if ALLOW_DEPRECATED_FUNCTIONS && !defined(DOXYGEN)
|
||||
void (*SdBaseFile::oldDateTime_)(uint16_t& date, uint16_t& time) = 0; // NOLINT
|
||||
void (*SdBaseFile::oldDateTime_)(uint16_t& date, uint16_t& time) = 0; // NOLINT
|
||||
#endif // ALLOW_DEPRECATED_FUNCTIONS
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user