misc. pointer formatting

This commit is contained in:
Scott Lahteine 2021-04-04 18:07:16 -05:00
parent 98b2b45264
commit 8b6718c632
23 changed files with 85 additions and 99 deletions

View File

@ -187,12 +187,11 @@ bool SdBaseFile::createContiguous(SdBaseFile* dirFile, const char *path, uint32_
* \return true for success, false for failure.
*/
bool SdBaseFile::dirEntry(dir_t *dir) {
dir_t *p;
// make sure fields on SD are correct
if (!sync()) return false;
// read entry
p = cacheDirEntry(SdVolume::CACHE_FOR_READ);
dir_t *p = cacheDirEntry(SdVolume::CACHE_FOR_READ);
if (!p) return false;
// copy to caller's struct
@ -458,10 +457,6 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const char *path, bool pFlag) {
bool SdBaseFile::mkdir(SdBaseFile *parent, const uint8_t dname[11]) {
if (ENABLED(SDCARD_READONLY)) return false;
uint32_t block;
dir_t d;
dir_t *p;
if (!parent->isDir()) return false;
// create a normal file
@ -478,19 +473,20 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const uint8_t dname[11]) {
if (!sync()) return false;
// cache entry - should already be in cache due to sync() call
p = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
dir_t *p = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
if (!p) return false;
// change directory entry attribute
p->attributes = DIR_ATT_DIRECTORY;
// make entry for '.'
dir_t d;
memcpy(&d, p, sizeof(d));
d.name[0] = '.';
LOOP_S_L_N(i, 1, 11) d.name[i] = ' ';
// cache block for '.' and '..'
block = vol_->clusterStartBlock(firstCluster_);
uint32_t block = vol_->clusterStartBlock(firstCluster_);
if (!vol_->cacheRawBlock(block, SdVolume::CACHE_FOR_WRITE)) return false;
// copy '.' to block
@ -697,8 +693,6 @@ bool SdBaseFile::open(SdBaseFile* dirFile, const uint8_t dname[11], uint8_t ofla
* \return true for success or false for failure.
*/
bool SdBaseFile::open(SdBaseFile *dirFile, uint16_t index, uint8_t oflag) {
dir_t *p;
vol_ = dirFile->vol_;
// error if already open
@ -711,7 +705,7 @@ bool SdBaseFile::open(SdBaseFile* dirFile, uint16_t index, uint8_t oflag) {
if (!dirFile->seekSet(32 * index)) return false;
// read entry into cache
p = dirFile->readDirCache();
dir_t *p = dirFile->readDirCache();
if (!p) return false;
// error if empty slot or '.' or '..'
@ -785,9 +779,6 @@ bool SdBaseFile::openCachedEntry(uint8_t dirIndex, uint8_t oflag) {
* \return true for success or false for failure.
*/
bool SdBaseFile::openNext(SdBaseFile *dirFile, uint8_t oflag) {
dir_t *p;
uint8_t index;
if (!dirFile) return false;
// error if already open
@ -796,10 +787,10 @@ bool SdBaseFile::openNext(SdBaseFile* dirFile, uint8_t oflag) {
vol_ = dirFile->vol_;
while (1) {
index = 0xF & (dirFile->curPosition_ >> 5);
uint8_t index = 0xF & (dirFile->curPosition_ >> 5);
// read entry into cache
p = dirFile->readDirCache();
dir_t *p = dirFile->readDirCache();
if (!p) return false;
// done if last entry
@ -827,7 +818,6 @@ bool SdBaseFile::openNext(SdBaseFile* dirFile, uint8_t oflag) {
*/
bool SdBaseFile::openParent(SdBaseFile *dir) {
dir_t entry;
dir_t *p;
SdBaseFile file;
uint32_t c;
uint32_t cluster;
@ -850,7 +840,7 @@ bool SdBaseFile::openParent(SdBaseFile* dir) {
// first block of parent dir
if (!vol_->cacheRawBlock(lbn, SdVolume::CACHE_FOR_READ)) return false;
p = &vol_->cacheBuffer_.dir[1];
dir_t *p = &vol_->cacheBuffer_.dir[1];
// verify name for '../..'
if (p->name[0] != '.' || p->name[1] != '.') return false;
// '..' is pointer to first cluster of parent. open '../..' to find parent
@ -1136,7 +1126,7 @@ int8_t SdBaseFile::readDir(dir_t *dir, char *longFilename) {
// Reset n to the start of the long name
n = 0;
for (uint16_t idx = 0; idx < (LONG_FILENAME_LENGTH) / 2; idx += 2) { // idx is fixed since FAT LFN always contains UTF-16LE encoding
uint16_t utf16_ch = longFilename[idx] | (longFilename[idx + 1] << 8);
const uint16_t utf16_ch = longFilename[idx] | (longFilename[idx + 1] << 8);
if (0xD800 == (utf16_ch & 0xF800)) // Surrogate pair - encode as '_'
longFilename[n++] = '_';
else if (0 == (utf16_ch & 0xFF80)) // Encode as 1-byte UTF-8 char
@ -1199,12 +1189,11 @@ dir_t* SdBaseFile::readDirCache() {
bool SdBaseFile::remove() {
if (ENABLED(SDCARD_READONLY)) return false;
dir_t *d;
// free any clusters - will fail if read-only or directory
if (!truncate(0)) return false;
// cache directory entry
d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
dir_t *d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
if (!d) return false;
// mark entry deleted
@ -1255,10 +1244,7 @@ bool SdBaseFile::remove(SdBaseFile* dirFile, const char *path) {
bool SdBaseFile::rename(SdBaseFile *dirFile, const char *newPath) {
if (ENABLED(SDCARD_READONLY)) return false;
dir_t entry;
uint32_t dirCluster = 0;
SdBaseFile file;
dir_t *d;
// must be an open file or subdirectory
if (!(isFile() || isSubDir())) return false;
@ -1268,16 +1254,18 @@ bool SdBaseFile::rename(SdBaseFile* dirFile, const char *newPath) {
// sync() and cache directory entry
sync();
d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
dir_t *d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
if (!d) return false;
// save directory entry
dir_t entry;
memcpy(&entry, d, sizeof(entry));
// mark entry deleted
d->name[0] = DIR_NAME_DELETED;
// make directory entry for new path
SdBaseFile file;
if (isFile()) {
if (!file.open(dirFile, newPath, O_CREAT | O_EXCL | O_WRITE)) {
goto restore;
@ -1537,7 +1525,6 @@ bool SdBaseFile::sync() {
* \return true for success, false for failure.
*/
bool SdBaseFile::timestamp(SdBaseFile *file) {
dir_t *d;
dir_t dir;
// get timestamps
@ -1546,7 +1533,7 @@ bool SdBaseFile::timestamp(SdBaseFile* file) {
// update directory fields
if (!sync()) return false;
d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
dir_t *d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
if (!d) return false;
// copy timestamps
@ -1599,7 +1586,6 @@ bool SdBaseFile::timestamp(uint8_t flags, uint16_t year, uint8_t month,
if (ENABLED(SDCARD_READONLY)) return false;
uint16_t dirDate, dirTime;
dir_t *d;
if (!isOpen()
|| year < 1980
@ -1616,7 +1602,7 @@ bool SdBaseFile::timestamp(uint8_t flags, uint16_t year, uint8_t month,
// update directory entry
if (!sync()) return false;
d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
dir_t *d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
if (!d) return false;
dirDate = FAT_DATE(year, month, day);