//------------------------------------------------------------------------------
bool FatFile::open(const char* path, oflag_t oflag) {
ST Serial.println("Open I");
return open(FatVolume::cwv(), path, oflag);
}
//------------------------------------------------------------------------------
bool FatFile::open(FatVolume* vol, const char* path, oflag_t oflag) {
ST Serial.println("Open II");
if (!vol) Serial.println("***** NOT vol! FAIL *****");
return vol && open(vol->vwd(), path, oflag);
}
//------------------------------------------------------------------------------
bool FatFile::open(FatFile* dirFile, const char* path, oflag_t oflag) {
ST Serial.println("Open III");
//Serial.println("Boo!");
FatFile tmpDir;
FatName_t fname;
// error if already open
if (isOpen() || !dirFile->isDir()) {
DBG_FAIL_MACRO;
Serial.println("***** Already open! FAIL *****");
goto fail;
}
if (isDirSeparator(*path)) {
while (isDirSeparator(*path)) {
path++;
}
if (*path == 0) {
return openRoot(dirFile->m_vol);
}
if (!tmpDir.openRoot(dirFile->m_vol)) {
DBG_FAIL_MACRO;
Serial.println("***** Can't open temp root! FAIL *****");
goto fail;
}
dirFile = &tmpDir;
}
while (1) {
if (!parsePathName(path, &fname, &path)) {
DBG_FAIL_MACRO;
Serial.println("***** Can't parse path name! FAIL *****");
goto fail;
}
if (*path == 0) {
break;
}
if (!open(dirFile, &fname, O_RDONLY)) {
Serial.println("***** Can't open directory? FAIL *****");
DBG_WARN_MACRO;
goto fail;
}
tmpDir = *this;
dirFile = &tmpDir;
close();
}
Serial.println("So far so good. Calling unknown open(dirFile, &fname, oflag)");
return open(dirFile, &fname, oflag);
fail:
return false;
}
//------------------------------------------------------------------------------
bool FatFile::open(FatFile* dirFile, uint16_t index, oflag_t oflag) {
ST
Serial.println("Open IV");
if (index) {
// Find start of LFN.
DirLfn_t* ldir;
uint8_t n = index < 20 ? index : 20;
for (uint8_t i = 1; i <= n; i++) {
ldir = reinterpret_cast<DirLfn_t*>(dirFile->cacheDir(index - i));
if (!ldir) {
DBG_FAIL_MACRO;
goto fail;
}
if (ldir->attributes != FAT_ATTRIB_LONG_NAME) {
break;
}
if (ldir->order & FAT_ORDER_LAST_LONG_ENTRY) {
if (!dirFile->seekSet(32UL*(index - i))) {
DBG_FAIL_MACRO;
goto fail;
}
break;
}
}
} else {
dirFile->rewind();
}
if (!openNext(dirFile, oflag)) {
DBG_FAIL_MACRO;
goto fail;
}
if (dirIndex() != index) {
close();
DBG_FAIL_MACRO;
goto fail;
}
return true;
fail:
return false;
}
//------------------------------------------------------------------------------