Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2018-12-15 16:39:26 +0300
committerDavid Crocker <dcrocker@eschertech.com>2018-12-15 16:39:26 +0300
commita0499fe6d568df74222958a47368aea291b1471c (patch)
treeff940f06f966cfacaa20d35d77e6f975046ed181 /src/Storage/FileStore.cpp
parenta25f8204d2fe36ad174b98dea673a114503cc457 (diff)
Pre-allocate SD card storage when doing HTTP file upload
Diffstat (limited to 'src/Storage/FileStore.cpp')
-rw-r--r--src/Storage/FileStore.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/Storage/FileStore.cpp b/src/Storage/FileStore.cpp
index 6a00c9c0..b727180e 100644
--- a/src/Storage/FileStore.cpp
+++ b/src/Storage/FileStore.cpp
@@ -54,11 +54,12 @@ bool FileStore::IsOpenOn(const FATFS *fs) const
// Open a local file (for example on an SD card).
// This is protected - only Platform can access it.
-bool FileStore::Open(const char* directory, const char* fileName, OpenMode mode)
+bool FileStore::Open(const char* directory, const char* fileName, OpenMode mode, uint32_t preAllocSize)
{
String<MaxFilenameLength> location;
MassStorage::CombineName(location.GetRef(), directory, fileName);
const bool writing = (mode == OpenMode::write || mode == OpenMode::append);
+ writeBuffer = nullptr;
if (writing)
{
@@ -91,7 +92,10 @@ bool FileStore::Open(const char* directory, const char* fileName, OpenMode mode)
// We only do this if the mode is write, not append, because we don't want to use up a large buffer to append messages to the log file,
// especially as we need to flush messages to SD card regularly.
// Currently, append mode is used for the log file and for appending simulated print times to GCodes files (which required read access too).
- writeBuffer = (mode == OpenMode::write) ? reprap.GetPlatform().GetMassStorage()->AllocateWriteBuffer() : nullptr;
+ if (mode == OpenMode::write)
+ {
+ writeBuffer = reprap.GetPlatform().GetMassStorage()->AllocateWriteBuffer();
+ }
}
const FRESULT openReturn = f_open(&file, location.c_str(),
@@ -100,6 +104,12 @@ bool FileStore::Open(const char* directory, const char* fileName, OpenMode mode)
: FA_OPEN_EXISTING | FA_READ);
if (openReturn != FR_OK)
{
+ if (writeBuffer != nullptr)
+ {
+ reprap.GetPlatform().GetMassStorage()->ReleaseWriteBuffer(writeBuffer);
+ writeBuffer = nullptr;
+ }
+
// We no longer report an error if opening a file in read mode fails unless debugging is enabled, because sometimes that is quite normal.
// It is up to the caller to report an error if necessary.
if (reprap.Debug(modulePlatform))
@@ -108,9 +118,18 @@ bool FileStore::Open(const char* directory, const char* fileName, OpenMode mode)
}
return false;
}
+
crc.Reset();
usageMode = (writing) ? FileUseMode::readWrite : FileUseMode::readOnly;
openCount = 1;
+ if (mode == OpenMode::write && preAllocSize != 0)
+ {
+ const FRESULT expandReturn = f_expand(&file, preAllocSize, 1); // try to pre-allocate contiguous space - it doesn't matter if it fails
+ if (reprap.Debug(moduleStorage))
+ {
+ debugPrintf("Preallocating %" PRIu32 " bytes returned %d\n", preAllocSize, (int)expandReturn);
+ }
+ }
return true;
}