Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Bugfix fs read+speed improvements #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added default file buffer size + function to change it by user
  • Loading branch information
P-R-O-C-H-Y committed Apr 12, 2022
commit 757479c2b3c764870255c46b850807ce93a559b2
9 changes: 9 additions & 0 deletions 9 libraries/FS/src/FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ size_t File::size() const
return _p->size();
}

bool File::setBufferSize(size_t size)
{
if (!*this) {
return 0;
}

return _p->setBufferSize(size);
}

void File::close()
{
if (_p) {
Expand Down
1 change: 1 addition & 0 deletions 1 libraries/FS/src/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class File : public Stream
}
size_t position() const;
size_t size() const;
bool setBufferSize(size_t size);
void close();
operator bool() const;
time_t getLastWrite();
Expand Down
1 change: 1 addition & 0 deletions 1 libraries/FS/src/FSImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class FileImpl
virtual bool seek(uint32_t pos, SeekMode mode) = 0;
virtual size_t position() const = 0;
virtual size_t size() const = 0;
virtual bool setBufferSize(size_t size) = 0;
virtual void close() = 0;
virtual time_t getLastWrite() = 0;
virtual const char* path() const = 0;
Expand Down
23 changes: 23 additions & 0 deletions 23 libraries/FS/src/vfs_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

using namespace fs;

#define DEFAULT_FILE_BUFFER_SIZE 4096

FileImplPtr VFSImpl::open(const char* fpath, const char* mode, const bool create)
{
if(!_mountpoint) {
Expand Down Expand Up @@ -280,6 +282,10 @@ VFSFileImpl::VFSFileImpl(VFSImpl* fs, const char* fpath, const char* mode)
if(!_f) {
log_e("fopen(%s) failed", temp);
}
if(_f && (_stat.st_blksize == 0))
{
setvbuf(_f,NULL,_IOFBF,DEFAULT_FILE_BUFFER_SIZE);
}
} else if(S_ISDIR(_stat.st_mode)) {
_isDirectory = true;
_d = opendir(temp);
Expand Down Expand Up @@ -307,6 +313,10 @@ VFSFileImpl::VFSFileImpl(VFSImpl* fs, const char* fpath, const char* mode)
if(!_f) {
log_e("fopen(%s) failed", temp);
}
if(_f && (_stat.st_blksize == 0))
{
setvbuf(_f,NULL,_IOFBF,DEFAULT_FILE_BUFFER_SIZE);
}
}
}
free(temp);
Expand Down Expand Up @@ -415,6 +425,19 @@ size_t VFSFileImpl::size() const
return _stat.st_size;
}

/*
* Change size of files internal buffer used for read / write operations.
* Need to be called right after opening file before any other operation!
*/
bool VFSFileImpl::setBufferSize(size_t size)
{
if(_isDirectory || !_f) {
return 0;
}
int res = setvbuf(_f,NULL,_IOFBF,size);
return res == 0;
}

const char* VFSFileImpl::path() const
{
return (const char*) _path;
Expand Down
3 changes: 2 additions & 1 deletion 3 libraries/FS/src/vfs_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ class VFSFileImpl : public FileImpl
bool seek(uint32_t pos, SeekMode mode) override;
size_t position() const override;
size_t size() const override;
bool setBufferSize(size_t size);
void close() override;
const char* path() const override;
const char* name() const override;
time_t getLastWrite() override;
time_t getLastWrite() override;
boolean isDirectory(void) override;
FileImplPtr openNextFile(const char* mode) override;
void rewindDirectory(void) override;
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.