Просмотр исходного кода

Remove FAT16/FAT32 directory typedef

main
Bill Greiman 5 лет назад
Родитель
Сommit
40b41c8764
16 измененных файлов: 72 добавлений и 65 удалений
  1. +1
    -1
      README.md
  2. +0
    -3
      extras/cpplint.txt
  3. +1
    -1
      library.properties
  4. +5
    -3
      src/ExFatLib/ExFatPartition.h
  5. +2
    -2
      src/FatLib/FatDbg.cpp
  6. +21
    -21
      src/FatLib/FatFile.cpp
  7. +5
    -5
      src/FatLib/FatFile.h
  8. +17
    -17
      src/FatLib/FatFileLFN.cpp
  9. +3
    -3
      src/FatLib/FatFilePrint.cpp
  10. +1
    -1
      src/FatLib/FatPartition.h
  11. +2
    -0
      src/SdCard/SdSpiCard.h
  12. +2
    -0
      src/SdFatConfig.h
  13. +4
    -0
      src/common/BlockDevice.h
  14. +7
    -5
      src/common/BlockDeviceInterface.h
  15. +1
    -1
      src/common/DebugMacros.h
  16. +0
    -2
      src/common/FsStructs.h

+ 1
- 1
README.md Просмотреть файл

@@ -34,7 +34,7 @@ KB/Sec,usec,usec,usec
3965.11,16733,110,127
```
The default version of SdFatConfig.h enables support for dedicated SPI and
optimized access to contiguous files. This make SdFat Version 2 slightly
optimized access to contiguous files. This makes SdFat Version 2 slightly
larger than Version 1. If these features are disabled, Version 2 is smaller
than Version 1.


+ 0
- 3
extras/cpplint.txt Просмотреть файл

@@ -1,3 +0,0 @@
Ignoring ../src/DigitalIO/readme.txt; not a valid file name (cc, h, cpp, cu, cuh)
Ignoring ../src/common/CPPLINT.cfg; not a valid file name (cc, h, cpp, cu, cuh)
Ignoring "../src/common/PrintTemplates.h": file excluded by "C:\Users\bill\Documents\ArduinoSdFat\libraries\SdFat\src\common\CPPLINT.cfg". File path component "PrintTemplates.h" matches pattern "PrintTemplates.h"

+ 1
- 1
library.properties Просмотреть файл

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

+ 5
- 3
src/ExFatLib/ExFatPartition.h Просмотреть файл

@@ -236,15 +236,17 @@ class ExFatPartition {
bool readSector(uint32_t sector, uint8_t* dst) {
return m_blockDev->readSector(sector, dst);
}
bool readSectors(uint32_t sector, uint8_t* dst, size_t count) {
return m_blockDev->readSectors(sector, dst, count);
}
bool writeSector(uint32_t sector, const uint8_t* src) {
return m_blockDev->writeSector(sector, src);
}
#if USE_MULTI_SECTOR_IO
bool readSectors(uint32_t sector, uint8_t* dst, size_t count) {
return m_blockDev->readSectors(sector, dst, count);
}
bool writeSectors(uint32_t sector, const uint8_t* src, size_t count) {
return m_blockDev->writeSectors(sector, src, count);
}
#endif // USE_MULTI_SECTOR_IO
//----------------------------------------------------------------------------
static const uint8_t m_bytesPerSectorShift = 9;
static const uint16_t m_bytesPerSector = 512;

+ 2
- 2
src/FatLib/FatDbg.cpp Просмотреть файл

@@ -64,7 +64,7 @@ static void printHex(print_t* pr, uint32_t val) {
}
}
//------------------------------------------------------------------------------
static void printDir(print_t* pr, dir_t* dir) {
static void printDir(print_t* pr, DirFat_t* dir) {
if (!dir->name[0] || dir->name[0] == FAT_NAME_DELETED) {
pr->println(F("Not Used"));
} else if (isFileOrSubdir(dir)) {
@@ -85,7 +85,7 @@ static void printDir(print_t* pr, dir_t* dir) {
}
//------------------------------------------------------------------------------
void FatPartition::dmpDirSector(print_t* pr, uint32_t sector) {
dir_t dir[16];
DirFat_t dir[16];
if (!readSector(sector, reinterpret_cast<uint8_t*>(dir))) {
pr->println(F("dmpDir failed"));
return;

+ 21
- 21
src/FatLib/FatFile.cpp Просмотреть файл

@@ -94,7 +94,7 @@ fail:
//------------------------------------------------------------------------------
// cache a file's directory entry
// return pointer to cached entry or null for failure
dir_t* FatFile::cacheDirEntry(uint8_t action) {
DirFat_t* FatFile::cacheDirEntry(uint8_t action) {
cache_t* pc;
pc = m_vol->cacheFetchData(m_dirSector, action);
if (!pc) {
@@ -206,8 +206,8 @@ bool FatFile::preAllocate(uint32_t length) {
return false;
}
//------------------------------------------------------------------------------
bool FatFile::dirEntry(dir_t* dst) {
dir_t* dir;
bool FatFile::dirEntry(DirFat_t* dst) {
DirFat_t* dir;
// Make sure fields on device are correct.
if (!sync()) {
DBG_FAIL_MACRO;
@@ -220,7 +220,7 @@ bool FatFile::dirEntry(dir_t* dst) {
goto fail;
}
// copy to caller's struct
memcpy(dst, dir, sizeof(dir_t));
memcpy(dst, dir, sizeof(DirFat_t));
return true;

fail:
@@ -333,8 +333,8 @@ fail:
//------------------------------------------------------------------------------
bool FatFile::mkdir(FatFile* parent, fname_t* fname) {
uint32_t sector;
dir_t dot;
dir_t* dir;
DirFat_t dot;
DirFat_t* dir;
cache_t* pc;

if (!parent->isDir()) {
@@ -473,7 +473,7 @@ bool FatFile::openCachedEntry(FatFile* dirFile, uint16_t dirIndex,
m_vol = dirFile->m_vol;
m_dirIndex = dirIndex;
m_dirCluster = dirFile->m_firstCluster;
dir_t* dir = reinterpret_cast<dir_t*>(m_vol->cacheAddress());
DirFat_t* dir = reinterpret_cast<DirFat_t*>(m_vol->cacheAddress());
dir += 0XF & dirIndex;

// Must be file or subdirectory.
@@ -549,7 +549,7 @@ fail:
//------------------------------------------------------------------------------
bool FatFile::openNext(FatFile* dirFile, oflag_t oflag) {
uint8_t checksum = 0;
ldir_t* ldir;
DirLfn_t* ldir;
uint8_t lfnOrd = 0;
uint16_t index;

@@ -561,7 +561,7 @@ bool FatFile::openNext(FatFile* dirFile, oflag_t oflag) {
while (1) {
// read entry into cache
index = dirFile->curPosition()/32;
dir_t* dir = dirFile->readDirCache();
DirFat_t* dir = dirFile->readDirCache();
if (!dir) {
if (dirFile->getError()) {
DBG_FAIL_MACRO;
@@ -586,7 +586,7 @@ bool FatFile::openNext(FatFile* dirFile, oflag_t oflag) {
}
return true;
} else if (isLongName(dir)) {
ldir = reinterpret_cast<ldir_t*>(dir);
ldir = reinterpret_cast<DirLfn_t*>(dir);
if (ldir->order & FAT_ORDER_LAST_LONG_ENTRY) {
lfnOrd = ldir->order & 0X1F;
checksum = ldir->checksum;
@@ -761,7 +761,7 @@ fail:
return -1;
}
//------------------------------------------------------------------------------
int8_t FatFile::readDir(dir_t* dir) {
int8_t FatFile::readDir(DirFat_t* dir) {
int16_t n;
// if not a directory file or miss-positioned return an error
if (!isDir() || (0X1F & m_curPosition)) {
@@ -769,8 +769,8 @@ int8_t FatFile::readDir(dir_t* dir) {
}

while (1) {
n = read(dir, sizeof(dir_t));
if (n != sizeof(dir_t)) {
n = read(dir, sizeof(DirFat_t));
if (n != sizeof(DirFat_t)) {
return n == 0 ? 0 : -1;
}
// last entry if FAT_NAME_FREE
@@ -790,7 +790,7 @@ int8_t FatFile::readDir(dir_t* dir) {
//------------------------------------------------------------------------------
// Read next directory entry into the cache
// Assumes file is correctly positioned
dir_t* FatFile::readDirCache(bool skipReadOk) {
DirFat_t* FatFile::readDirCache(bool skipReadOk) {
uint8_t i = (m_curPosition >> 5) & 0XF;

if (i == 0 || !skipReadOk) {
@@ -806,7 +806,7 @@ dir_t* FatFile::readDirCache(bool skipReadOk) {
m_curPosition += 32;
}
// return pointer to entry
return reinterpret_cast<dir_t*>(m_vol->cacheAddress()) + i;
return reinterpret_cast<DirFat_t*>(m_vol->cacheAddress()) + i;

fail:
return nullptr;
@@ -829,12 +829,12 @@ bool FatFile::rename(const char* newPath) {
}
//------------------------------------------------------------------------------
bool FatFile::rename(FatFile* dirFile, const char* newPath) {
dir_t entry;
DirFat_t entry;
uint32_t dirCluster = 0;
FatFile file;
FatFile oldFile;
cache_t* pc;
dir_t* dir;
DirFat_t* dir;

// Must be an open file or subdirectory.
if (!(isFile() || isSubDir())) {
@@ -946,7 +946,7 @@ bool FatFile::rmdir() {

// make sure directory is empty
while (1) {
dir_t* dir = readDirCache(true);
DirFat_t* dir = readDirCache(true);
if (!dir) {
// EOF if no error.
if (!getError()) {
@@ -990,7 +990,7 @@ bool FatFile::rmRfStar() {
// remember position
index = m_curPosition/32;

dir_t* dir = readDirCache();
DirFat_t* dir = readDirCache();
if (!dir) {
// At EOF if no error.
if (!getError()) {
@@ -1118,7 +1118,7 @@ bool FatFile::sync() {
return true;
}
if (m_flags & FILE_FLAG_DIR_DIRTY) {
dir_t* dir = cacheDirEntry(FatCache::CACHE_FOR_WRITE);
DirFat_t* dir = cacheDirEntry(FatCache::CACHE_FOR_WRITE);
// check for deleted by another open file object
if (!dir || dir->name[0] == FAT_NAME_DELETED) {
DBG_FAIL_MACRO;
@@ -1157,7 +1157,7 @@ bool FatFile::timestamp(uint8_t flags, uint16_t year, uint8_t month,
uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) {
uint16_t dirDate;
uint16_t dirTime;
dir_t* dir;
DirFat_t* dir;

if (!isFile()
|| year < 1980

+ 5
- 5
src/FatLib/FatFile.h Просмотреть файл

@@ -233,7 +233,7 @@ class FatFile {
*
* \return true for success or false for failure.
*/
bool dirEntry(dir_t* dir);
bool dirEntry(DirFat_t* dir);
/** \return The number of bytes allocated to a directory or zero
* if an error occurs.
*/
@@ -679,7 +679,7 @@ class FatFile {
int read(void* buf, size_t count);
/** Read the next directory entry from a directory file.
*
* \param[out] dir The dir_t struct that will receive the data.
* \param[out] dir The DirFat_t struct that will receive the data.
*
* \return For success readDir() returns the number of bytes read.
* A value of zero will be returned if end of file is reached.
@@ -687,7 +687,7 @@ class FatFile {
* readDir() called before a directory has been opened, this is not
* a directory file or an I/O error occurred.
*/
int8_t readDir(dir_t* dir);
int8_t readDir(DirFat_t* dir);
/** Remove a file.
*
* The directory entry and all data for the file are deleted.
@@ -936,7 +936,7 @@ class FatFile {
// private functions
bool addCluster();
bool addDirCluster();
dir_t* cacheDirEntry(uint8_t action);
DirFat_t* cacheDirEntry(uint8_t action);
static uint8_t lfnChecksum(uint8_t* name);
bool lfnUniqueSfn(fname_t* fname);
bool openCluster(FatFile* file);
@@ -945,7 +945,7 @@ class FatFile {
bool open(FatFile* dirFile, fname_t* fname, oflag_t oflag);
bool openCachedEntry(FatFile* dirFile, uint16_t cacheIndex, oflag_t oflag,
uint8_t lfnOrd);
dir_t* readDirCache(bool skipReadOk = false);
DirFat_t* readDirCache(bool skipReadOk = false);

// bits defined in m_flags
static const uint8_t FILE_FLAG_READ = 0X01;

+ 17
- 17
src/FatLib/FatFileLFN.cpp Просмотреть файл

@@ -59,7 +59,7 @@ static uint16_t Bernstein(uint16_t hash, const char *str, size_t len) {
* \param[in] i Index of character.
* \return The 16-bit character.
*/
static uint16_t lfnGetChar(ldir_t *ldir, uint8_t i) {
static uint16_t lfnGetChar(DirLfn_t *ldir, uint8_t i) {
if (i < 5) {
return getLe16(ldir->unicode1 + 2*i);
} else if (i < 11) {
@@ -70,7 +70,7 @@ static uint16_t lfnGetChar(ldir_t *ldir, uint8_t i) {
return 0;
}
//------------------------------------------------------------------------------
static bool lfnGetName(ldir_t *ldir, char* name, size_t n) {
static bool lfnGetName(DirLfn_t *ldir, char* name, size_t n) {
uint8_t i;
size_t k = 13*((ldir->order & 0X1F) - 1);
for (i = 0; i < 13; i++) {
@@ -104,7 +104,7 @@ inline bool lfnLegalChar(char c) {
* \param[in] i Index of character.
* \param[in] c The 16-bit character.
*/
static void lfnPutChar(ldir_t *ldir, uint8_t i, uint16_t c) {
static void lfnPutChar(DirLfn_t *ldir, uint8_t i, uint16_t c) {
if (i < 5) {
setLe16(ldir->unicode1 + 2*i, c);
} else if (i < 11) {
@@ -114,7 +114,7 @@ static void lfnPutChar(ldir_t *ldir, uint8_t i, uint16_t c) {
}
}
//------------------------------------------------------------------------------
static void lfnPutName(ldir_t *ldir, const char* name, size_t n) {
static void lfnPutName(DirLfn_t *ldir, const char* name, size_t n) {
size_t k = 13*((ldir->order & 0X1F) - 1);
for (uint8_t i = 0; i < 13; i++, k++) {
uint16_t c = k < n ? name[k] : k == n ? 0 : 0XFFFF;
@@ -124,7 +124,7 @@ static void lfnPutName(ldir_t *ldir, const char* name, size_t n) {
//==============================================================================
bool FatFile::getName(char* name, size_t size) {
FatFile dirFile;
ldir_t* ldir;
DirLfn_t* ldir;
if (!isOpen() || size < 13) {
DBG_FAIL_MACRO;
goto fail;
@@ -141,7 +141,7 @@ bool FatFile::getName(char* name, size_t size) {
DBG_FAIL_MACRO;
goto fail;
}
ldir = reinterpret_cast<ldir_t*>(dirFile.readDirCache());
ldir = reinterpret_cast<DirLfn_t*>(dirFile.readDirCache());
if (!ldir) {
DBG_FAIL_MACRO;
goto fail;
@@ -305,8 +305,8 @@ bool FatFile::open(FatFile* dirFile, fname_t* fname, oflag_t oflag) {
uint16_t curIndex;
uint16_t date;
uint16_t time;
dir_t* dir;
ldir_t* ldir;
DirFat_t* dir;
DirLfn_t* ldir;
size_t len = fname->len;

if (!dirFile->isDir() || isOpen()) {
@@ -347,7 +347,7 @@ bool FatFile::open(FatFile* dirFile, fname_t* fname, oflag_t oflag) {
if (dir->name[0] == FAT_NAME_DELETED || dir->name[0] == '.') {
lfnOrd = 0;
} else if (isLongName(dir)) {
ldir = reinterpret_cast<ldir_t*>(dir);
ldir = reinterpret_cast<DirLfn_t*>(dir);
if (!lfnOrd) {
if ((ldir->order & FAT_ORDER_LAST_LONG_ENTRY) == 0) {
continue;
@@ -452,7 +452,7 @@ create:
}
lfnOrd = freeNeed - 1;
for (order = lfnOrd ; order ; order--) {
ldir = reinterpret_cast<ldir_t*>(dirFile->readDirCache());
ldir = reinterpret_cast<DirLfn_t*>(dirFile->readDirCache());
if (!ldir) {
DBG_FAIL_MACRO;
goto fail;
@@ -472,7 +472,7 @@ create:
goto fail;
}
// initialize as empty file
memset(dir, 0, sizeof(dir_t));
memset(dir, 0, sizeof(DirFat_t));
memcpy(dir->name, fname->sfn, 11);

// Set base-name and extension lower case bits.
@@ -508,7 +508,7 @@ size_t FatFile::printName(print_t* pr) {
FatFile dirFile;
uint16_t u;
size_t n = 0;
ldir_t* ldir;
DirLfn_t* ldir;

if (!isLFN()) {
return printSFN(pr);
@@ -522,7 +522,7 @@ size_t FatFile::printName(print_t* pr) {
DBG_FAIL_MACRO;
goto fail;
}
ldir = reinterpret_cast<ldir_t*>(dirFile.readDirCache());
ldir = reinterpret_cast<DirLfn_t*>(dirFile.readDirCache());
if (!ldir) {
DBG_FAIL_MACRO;
goto fail;
@@ -560,8 +560,8 @@ bool FatFile::remove() {
uint8_t checksum;
uint8_t order;
FatFile dirFile;
dir_t* dir;
ldir_t* ldir;
DirFat_t* dir;
DirLfn_t* ldir;

// Cant' remove not open for write.
if (!isWritable()) {
@@ -606,7 +606,7 @@ bool FatFile::remove() {
DBG_FAIL_MACRO;
goto fail;
}
ldir = reinterpret_cast<ldir_t*>(dirFile.readDirCache());
ldir = reinterpret_cast<DirLfn_t*>(dirFile.readDirCache());
if (!ldir) {
DBG_FAIL_MACRO;
goto fail;
@@ -638,7 +638,7 @@ fail:
bool FatFile::lfnUniqueSfn(fname_t* fname) {
const uint8_t FIRST_HASH_SEQ = 2; // min value is 2
uint8_t pos = fname->seqPos;;
dir_t *dir;
DirFat_t *dir;
uint16_t hex;

DBG_HALT_IF(!(fname->flags & FNAME_FLAG_LOST_CHARS));

+ 3
- 3
src/FatLib/FatFilePrint.cpp Просмотреть файл

@@ -121,7 +121,7 @@ bool FatFile::ls(print_t* pr, uint8_t flags, uint8_t indent) {
}
//------------------------------------------------------------------------------
size_t FatFile::printAccessDate(print_t* pr) {
dir_t dir;
DirFat_t dir;
if (!dirEntry(&dir)) {
DBG_FAIL_MACRO;
goto fail;
@@ -133,7 +133,7 @@ fail:
}
//------------------------------------------------------------------------------
size_t FatFile::printCreateDateTime(print_t* pr) {
dir_t dir;
DirFat_t dir;
if (!dirEntry(&dir)) {
DBG_FAIL_MACRO;
goto fail;
@@ -145,7 +145,7 @@ fail:
}
//------------------------------------------------------------------------------
size_t FatFile::printModifyDateTime(print_t* pr) {
dir_t dir;
DirFat_t dir;
if (!dirEntry(&dir)) {
DBG_FAIL_MACRO;
goto fail;

+ 1
- 1
src/FatLib/FatPartition.h Просмотреть файл

@@ -58,7 +58,7 @@ union cache_t {
/** Used to access cached FAT32 entries. */
uint32_t fat32[128];
/** Used to access cached directory entries. */
dir_t dir[16];
DirFat_t dir[16];
};
//==============================================================================
/**

+ 2
- 0
src/SdCard/SdSpiCard.h Просмотреть файл

@@ -40,6 +40,8 @@
*/
#if HAS_SDIO_CLASS
class SdSpiCard : public SdCardInterface {
#elif USE_BLOCK_DEVICE_INTERFACE
class SdSpiCard : public BlockDeviceInterface {
#else // HAS_SDIO_CLASS
class SdSpiCard {
#endif // HAS_SDIO_CLASS

+ 2
- 0
src/SdFatConfig.h Просмотреть файл

@@ -38,6 +38,8 @@
#define ENABLE_ARDUINO_SERIAL 1
/** For Debug - must be one */
#define ENABLE_ARDUINO_STRING 1
/** Set USE_BLOCK_DEVICE_INTERFACE nonzero to use generic of block device */
#define USE_BLOCK_DEVICE_INTERFACE 0
//------------------------------------------------------------------------------
#if ENABLE_ARDUINO_FEATURES
#include "Arduino.h"

+ 4
- 0
src/common/BlockDevice.h Просмотреть файл

@@ -25,5 +25,9 @@
#ifndef BlockDevice_h
#define BlockDevice_h
#include "SdCard/SdCard.h"
#if HAS_SDIO_CLASS || USE_BLOCK_DEVICE_INTERFACE
typedef BlockDeviceInterface BlockDevice;
#else
typedef SdCard BlockDevice;
#endif
#endif // BlockDevice_h

+ 7
- 5
src/common/BlockDeviceInterface.h Просмотреть файл

@@ -22,14 +22,15 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef BlockDeviceInterface_h
#define BlockDeviceInterface_h
/**
* \file
* \brief BlockDeviceInterface include file.
*/
#ifndef BlockDeviceInterface_h
#define BlockDeviceInterface_h
#include <stdint.h>
#include <stddef.h>
#include "SdFatConfig.h"
/**
* \class BlockDeviceInterface
* \brief BlockDeviceInterface class.
@@ -45,7 +46,7 @@ class BlockDeviceInterface {
* \return true for success or false for failure.
*/
virtual bool readSector(uint32_t sector, uint8_t* dst) = 0;
#if USE_MULTI_SECTOR_IO
/**
* Read multiple 512 byte sectors.
*
@@ -55,7 +56,7 @@ class BlockDeviceInterface {
* \return true for success or false for failure.
*/
virtual bool readSectors(uint32_t sector, uint8_t* dst, size_t ns) = 0;
#endif // USE_MULTI_SECTOR_IO
/** \return device size in sectors. */
virtual uint32_t sectorCount() = 0;

@@ -72,7 +73,7 @@ class BlockDeviceInterface {
* \return true for success or false for failure.
*/
virtual bool writeSector(uint32_t sector, const uint8_t* src) = 0;
#if USE_MULTI_SECTOR_IO
/**
* Write multiple 512 byte sectors.
*
@@ -82,5 +83,6 @@ class BlockDeviceInterface {
* \return true for success or false for failure.
*/
virtual bool writeSectors(uint32_t sector, const uint8_t* src, size_t ns) = 0;
#endif // USE_MULTI_SECTOR_IO
};
#endif // BlockDeviceInterface_h

+ 1
- 1
src/common/DebugMacros.h Просмотреть файл

@@ -31,7 +31,7 @@
#include "Arduino.h"
#ifndef DBG_FILE
#error DBG_FILE not defined
#endif // DBG_FILE
#endif // DBG_FILE
static void dbgPrint(uint16_t line) {
Serial.print(F("DBG_FAIL: "));
Serial.print(F(DBG_FILE));

+ 0
- 2
src/common/FsStructs.h Просмотреть файл

@@ -236,7 +236,6 @@ typedef struct {
uint8_t firstClusterLow[2];
uint8_t fileSize[4];
} DirFat_t;
typedef DirFat_t dir_t;

static inline bool isFileDir(const DirFat_t* dir) {
return (dir->attributes & (FAT_ATTRIB_DIRECTORY | FAT_ATTRIB_LABEL)) == 0;
@@ -269,7 +268,6 @@ typedef struct {
uint8_t mustBeZero2[2];
uint8_t unicode3[4];
} DirLfn_t;
typedef DirLfn_t ldir_t;
//=============================================================================
inline uint32_t exFatChecksum(uint32_t sum, uint8_t data) {
return (sum << 31) + (sum >> 1) + data;

Загрузка…
Отмена
Сохранить