lfs add open directory support, isDirectory()

This commit is contained in:
hathach committed 2018-10-17 16:34:18 +07:00
1 parent 1fd30e3eed
commit 823e1f425c
4 files changed
+63 -25

No files matched your search

+3 -1
View File
@@ -44,12 +44,14 @@ File::File (FileSystemClass &fs)
{
_fs = &fs;
_hdl = NULL;
_is_dir = false;
}
File::File (char const *filename, uint8_t mode, FileSystemClass &fs)
{
_fs = &fs;
_hdl = NULL;
_is_dir = false;
open(filename, mode);
}
@@ -141,7 +143,7 @@ char const * File::name (void)
bool File::isDirectory (void)
{
return _is_dir;
}
File File::openNextFile (uint8_t mode)
+5 -1
View File
@@ -71,7 +71,7 @@ class File: public Stream
operator bool (void);
char const * name (void);
bool isDirectory ();
bool isDirectory (void);
File openNextFile (uint8_t mode = FILE_READ);
void rewindDirectory (void);
@@ -80,6 +80,7 @@ class File: public Stream
private:
FileSystemClass* _fs;
void* _hdl;
bool _is_dir;
// String filename;
@@ -120,6 +121,9 @@ class FileSystemClass
virtual bool _f_seek (void* fhdl, uint32_t pos) = 0;
virtual uint32_t _f_position (void* fhdl) = 0;
virtual uint32_t _f_size (void* fhdl) = 0;
virtual File _f_openNextFile (void* fhdl, uint8_t mode) = 0;
virtual void _f_rewindDirectory (void* fhdl) = 0;
};
}
+53 -23
View File
@@ -213,24 +213,65 @@ BluefuritLib::File LittleFS::open (char const *filename, uint8_t mode)
if ( flags )
{
lfs_file_t* fhdl = (lfs_file_t*) rtos_malloc(sizeof(lfs_file_t));
int rc = lfs_file_open(&_lfs, fhdl, filename, flags);
struct lfs_info info;
if ( rc )
if ( 0 == lfs_stat(&_lfs, filename, &info) )
{
rtos_free(fhdl);
// print error if error is other than file not existed
if ( rc != LFS_ERR_NOENT ) VERIFY_MESS(rc, dbg_strerr_lfs);
}
else
{
file._hdl = fhdl;
void* fhdl;
int rc;
if ( info.type == LFS_TYPE_REG )
{
// Open file
fhdl = rtos_malloc(sizeof(lfs_file_t));
rc = lfs_file_open(&_lfs, (lfs_file_t*) fhdl, filename, flags);
}
else if ( info.type == LFS_TYPE_DIR )
{
// open a dir
fhdl = rtos_malloc(sizeof(lfs_dir_t));
rc = lfs_dir_open(&_lfs, (lfs_dir_t*) fhdl, filename);
}
if ( rc )
{
rtos_free(fhdl);
VERIFY_MESS(rc, dbg_strerr_lfs);
}
else
{
file._hdl = fhdl;
file._is_dir = (info.type == LFS_TYPE_DIR);
}
}
}
return file;
}
bool LittleFS::exists (char const *filepath)
{
}
bool LittleFS::mkdir (char const *filepath)
{
}
bool LittleFS::remove (char const *filepath)
{
}
bool LittleFS::rmdir (char const *filepath)
{
}
//--------------------------------------------------------------------+
// FILE API
//--------------------------------------------------------------------+
size_t LittleFS::_f_write (void* fhdl, uint8_t const *buf, size_t size)
{
lfs_ssize_t wrcount = lfs_file_write(&_lfs, (lfs_file_t*) fhdl, buf, size);
@@ -263,28 +304,17 @@ uint32_t LittleFS::_f_size (void* fhdl)
return lfs_file_size(&_lfs, (lfs_file_t*) fhdl);
}
void LittleFS::_f_close (void* fhdl)
{
lfs_file_close(&_lfs, (lfs_file_t*) fhdl);
}
bool LittleFS::exists (char const *filepath)
File LittleFS::_f_openNextFile (void* fhdl, uint8_t mode)
{
}
bool LittleFS::mkdir (char const *filepath)
{
}
bool LittleFS::remove (char const *filepath)
{
}
bool LittleFS::rmdir (char const *filepath)
void LittleFS::_f_rewindDirectory (void* fhdl)
{
}
+2
View File
@@ -64,6 +64,8 @@ class LittleFS: public BluefuritLib::FileSystemClass
virtual uint32_t _f_position (void* fhdl);
virtual uint32_t _f_size (void* fhdl);
virtual File _f_openNextFile (void* fhdl, uint8_t mode);
virtual void _f_rewindDirectory (void* fhdl);
private:
struct lfs_config _lfs_cfg;