implement most of the ExternalFS
This commit is contained in:
1 parent
f31b370cfa
commit
eff1dd9187
3 files changed
+46
-5
No files matched your search
@@ -219,7 +219,7 @@ File FatFS::open (char const *filepath, uint8_t mode)
|
||||
bool is_root = (filepath[0] == '/' && filepath[1] == 0);
|
||||
|
||||
// f_stat return FR_INVALID_NAME for root
|
||||
if ( !is_root ) f_stat(filepath, &fno);
|
||||
if ( !is_root ) rc = f_stat(filepath, &fno);
|
||||
|
||||
if ( FR_OK == rc )
|
||||
{
|
||||
@@ -242,28 +242,53 @@ File FatFS::open (char const *filepath, uint8_t mode)
|
||||
|
||||
bool FatFS::exists (char const *filepath)
|
||||
{
|
||||
if ( filepath[0] == '/' && filepath[1] == 0 ) return true; // root always exists
|
||||
|
||||
FILINFO fno;
|
||||
return FR_OK == f_stat(filepath, &fno);
|
||||
}
|
||||
|
||||
bool FatFS::mkdir (char const *filepath)
|
||||
{
|
||||
VERIFY_FAT(f_mkdir(filepath), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FatFS::remove (char const *filepath)
|
||||
{
|
||||
VERIFY_FAT(f_unlink(filepath), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FatFS::rmdir (char const *filepath)
|
||||
{
|
||||
VERIFY_FAT(f_unlink(filepath), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FatFS::rmdir_r (char const *filepath)
|
||||
{
|
||||
// not supported yet
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t FatFS::_f_write (void* fhdl, uint8_t const *buf, size_t size)
|
||||
{
|
||||
UINT byte_write = 0;
|
||||
VERIFY_FAT(f_write((FIL* ) fhdl, buf, size, &byte_write), byte_write);
|
||||
return byte_write;
|
||||
}
|
||||
|
||||
int FatFS::_f_read (void* fhdl, void *buf, uint16_t nbyte)
|
||||
{
|
||||
UINT byte_read = 0;
|
||||
VERIFY_FAT(f_read((FIL* ) fhdl, buf, nbyte, &byte_read), byte_read);
|
||||
return byte_read;
|
||||
}
|
||||
|
||||
void FatFS::_f_flush (void* fhdl)
|
||||
{
|
||||
VERIFY_FAT(f_sync((FIL* ) fhdl),);
|
||||
}
|
||||
|
||||
void FatFS::_f_close (void* fhdl, bool is_dir)
|
||||
@@ -280,10 +305,13 @@ void FatFS::_f_close (void* fhdl, bool is_dir)
|
||||
|
||||
bool FatFS::_f_seek (void* fhdl, uint32_t pos)
|
||||
{
|
||||
VERIFY_FAT(f_lseek((FIL* ) fhdl, pos), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t FatFS::_f_position (void* fhdl)
|
||||
{
|
||||
return f_tell((FIL* ) fhdl);
|
||||
}
|
||||
|
||||
uint32_t FatFS::_f_size (void* fhdl)
|
||||
@@ -319,6 +347,7 @@ File FatFS::_f_openNextFile (void* fhdl, char const* cwd, uint8_t mode)
|
||||
|
||||
void FatFS::_f_rewindDirectory (void* fhdl)
|
||||
{
|
||||
VERIFY_FAT(f_rewinddir((DIR * ) fhdl),);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#include "rtos.h"
|
||||
#include <Arduino.h>
|
||||
#include "FileIO.h"
|
||||
|
||||
namespace BluefuritLib
|
||||
@@ -62,9 +62,7 @@ File& File::operator = (const File &rhs)
|
||||
{
|
||||
// close if currently opened
|
||||
if ( _hdl ) close();
|
||||
|
||||
memcpy(this, &rhs, sizeof(File));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -84,29 +82,36 @@ bool File::open (char const *filename, uint8_t mode)
|
||||
|
||||
size_t File::write (uint8_t ch)
|
||||
{
|
||||
VERIFY(!_is_dir, 0);
|
||||
return write(&ch, 1);
|
||||
}
|
||||
|
||||
size_t File::write (uint8_t const *buf, size_t size)
|
||||
{
|
||||
VERIFY(!_is_dir, 0);
|
||||
return _fs->_f_write(_hdl, buf, size);
|
||||
}
|
||||
|
||||
int File::read (void)
|
||||
{
|
||||
VERIFY(!_is_dir, -1);
|
||||
uint8_t ch;
|
||||
return (read(&ch, 1) > 0) ? ch : -1;
|
||||
}
|
||||
|
||||
int File::read (void *buf, uint16_t nbyte)
|
||||
{
|
||||
VERIFY(!_is_dir, 0);
|
||||
return _fs->_f_read(_hdl, buf, nbyte);
|
||||
}
|
||||
|
||||
int File::peek (void)
|
||||
{
|
||||
VERIFY(!_is_dir, -1);
|
||||
|
||||
int ch = read();
|
||||
seek((position() > 0) ? (position() - 1) : 0);
|
||||
uint32_t pos = position();
|
||||
seek((pos > 0) ? (pos - 1) : 0);
|
||||
return ch;
|
||||
}
|
||||
|
||||
@@ -117,21 +122,25 @@ int File::available (void)
|
||||
|
||||
bool File::seek (uint32_t pos)
|
||||
{
|
||||
VERIFY(!_is_dir, false);
|
||||
return _fs->_f_seek(_hdl, pos);
|
||||
}
|
||||
|
||||
uint32_t File::position (void)
|
||||
{
|
||||
VERIFY(!_is_dir, 0);
|
||||
return _fs->_f_position(_hdl);
|
||||
}
|
||||
|
||||
uint32_t File::size (void)
|
||||
{
|
||||
VERIFY(!_is_dir, 0);
|
||||
return _fs->_f_size(_hdl);
|
||||
}
|
||||
|
||||
void File::flush (void)
|
||||
{
|
||||
VERIFY(!_is_dir,);
|
||||
_fs->_f_flush(_hdl);
|
||||
}
|
||||
|
||||
|
||||
@@ -343,6 +343,9 @@ bool LittleFS::rmdir (char const *filepath)
|
||||
|
||||
bool LittleFS::rmdir_r (char const *filepath)
|
||||
{
|
||||
/* adafruit: lfs is modified to remove non-empty folder,
|
||||
According to below issue, comment these 2 line won't corrupt filesystem
|
||||
https://github.com/ARMmbed/littlefs/issues/43 */
|
||||
VERIFY_LFS(lfs_remove(&_lfs, filepath));
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user