Browse Source

Fix open LFN by index

main
Bill Greiman 5 years ago
parent
commit
95551112eb
4 changed files with 40 additions and 8 deletions
  1. +1
    -1
      library.properties
  2. +1
    -1
      src/ExFatLib/ExFatFile.cpp
  3. +37
    -4
      src/FatLib/FatFile.cpp
  4. +1
    -2
      src/FatLib/FatFileLFN.cpp

+ 1
- 1
library.properties View File

name=SdFat name=SdFat
version=2.0.0-beta.4
version=2.0.0-beta.5
license=MIT license=MIT
author=Bill Greiman <fat16lib@sbcglobal.net> author=Bill Greiman <fat16lib@sbcglobal.net>
maintainer=Bill Greiman <fat16lib@sbcglobal.net> maintainer=Bill Greiman <fat16lib@sbcglobal.net>

+ 1
- 1
src/ExFatLib/ExFatFile.cpp View File

// Check for cache sector in read range. // Check for cache sector in read range.
if (sector <= m_vol->dataCacheSector() if (sector <= m_vol->dataCacheSector()
&& m_vol->dataCacheSector() < (sector + ns)) { && m_vol->dataCacheSector() < (sector + ns)) {
// Flush cache if a cache sector is in the range.
// Flush cache if cache sector is in the range.
if (!m_vol->dataCacheSync()) { if (!m_vol->dataCacheSync()) {
DBG_FAIL_MACRO; DBG_FAIL_MACRO;
goto fail; goto fail;

+ 37
- 4
src/FatLib/FatFile.cpp View File

} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool FatFile::open(FatFile* dirFile, uint16_t index, oflag_t oflag) { bool FatFile::open(FatFile* dirFile, uint16_t index, oflag_t oflag) {
if (dirFile->seekSet(32*index) && openNext(dirFile, oflag)) {
if (dirIndex() == index) {
return true;
if (index) {
// Find start of LFN.
DirLfn_t* ldir;
uint8_t n = index < 20 ? index : 20;
for (uint8_t i = 1; i <= n; i++) {
if (!dirFile->seekSet(32UL*(index - i))) {
DBG_FAIL_MACRO;
goto fail;
}
ldir = reinterpret_cast<DirLfn_t*>(dirFile->readDirCache());
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(); close();
DBG_FAIL_MACRO; DBG_FAIL_MACRO;
goto fail;
} }
return true;

fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Check for cache sector in read range. // Check for cache sector in read range.
if (sector <= m_vol->cacheSectorNumber() if (sector <= m_vol->cacheSectorNumber()
&& sector < (m_vol->cacheSectorNumber() + ns)) { && sector < (m_vol->cacheSectorNumber() + ns)) {
// Flush cache if a cache sector is in the range.
// Flush cache if cache sector is in the range.
if (!m_vol->cacheSyncData()) { if (!m_vol->cacheSyncData()) {
DBG_FAIL_MACRO; DBG_FAIL_MACRO;
goto fail; goto fail;

+ 1
- 2
src/FatLib/FatFileLFN.cpp View File

bool FatFile::remove() { bool FatFile::remove() {
bool last; bool last;
uint8_t checksum; uint8_t checksum;
uint8_t order;
FatFile dirFile; FatFile dirFile;
DirFat_t* dir; DirFat_t* dir;
DirLfn_t* ldir; DirLfn_t* ldir;
DBG_FAIL_MACRO; DBG_FAIL_MACRO;
goto fail; goto fail;
} }
for (order = 1; order <= m_lfnOrd; order++) {
for (uint8_t order = 1; order <= m_lfnOrd; order++) {
if (!dirFile.seekSet(32UL*(m_dirIndex - order))) { if (!dirFile.seekSet(32UL*(m_dirIndex - order))) {
DBG_FAIL_MACRO; DBG_FAIL_MACRO;
goto fail; goto fail;

Loading…
Cancel
Save