Files
MuditaOS/module-vfs/vfs-utils.cpp
T
rkubiak01andAlek Rudnik 7cac882c7a [2306] VFS: support .boot.ini and "current" and "previous" os types (#315)
* VFS: support .boot.ini and "current" and "previous" os types

* fixes for first batch of comments
- moved crc32 functions to a seperate file
- changed naming of constant with _
- removed one magic number
- crc methods now cross platform

* using smart pointer for buffer management

* created a simple USER_FILE macro for database names

* removed commented-out code

* style fixes

* Updated crc32 version

* Update module-vfs/vfs-utils.cpp

Co-Authored-By: Alek Rudnik <54846206+alekrudnik@users.noreply.github.com>

* Update module-vfs/vfs-utils.cpp

Co-Authored-By: Alek Rudnik <54846206+alekrudnik@users.noreply.github.com>

* renamed USER_FILE to USER_PATH macro, this was also
bromen and was returning incorrect paths, std::filesystem::path
behavior is causing these issues.

* VFS: remove method changed

* fixed path for assets copy

* UNITTEST: vfs test fixed

* VFS: changed computeCRC32 return type to void

* Max supported partition to 2 (was 1)

* EOL in vfs.cpp

* nullptr check in computeCRC32
include for log.hpp fixed

* flash_eMMC merged properly

* CRC32 commit update

* testBuild

* fix newline at start of smsdb.cpp
removed test from cmake

* no user/ folder on the root of emmc causes sqlite3 to fault
this adds a create empty user call for rt1051

* flash script fixes
- do not use build-*/sys
- common.sh contains a static list of iles that land on the flash

Co-authored-by: Alek Rudnik <54846206+alekrudnik@users.noreply.github.com>
2020-05-08 10:27:17 +02:00

56 lines
1.6 KiB
C++

#include <vfs.hpp>
void vfs::computeCRC32(vfs::FILE *file, unsigned long *outCrc32)
{
if (outCrc32 == nullptr)
return;
std::unique_ptr<unsigned char[]> buf(new unsigned char[purefs::buffer::crc_buf]);
size_t bufLen;
*outCrc32 = 0;
while (!::vfs.eof(file)) {
bufLen = ::vfs.fread(buf.get(), 1, purefs::buffer::crc_buf, file);
if (bufLen <= 0)
break;
*outCrc32 = Crc32_ComputeBuf(*outCrc32, buf.get(), bufLen);
}
}
bool vfs::verifyCRC(const std::string filePath, const unsigned long crc32)
{
unsigned long crc32Read;
vfs::FILE *fp = ::vfs.fopen(filePath.c_str(), "r");
if (fp != NULL) {
computeCRC32(fp, &crc32Read);
::vfs.fclose(fp);
return (crc32Read == crc32);
}
LOG_ERROR("verifyCRC can't open %s", filePath.c_str());
return (false);
}
bool vfs::verifyCRC(const fs::path filePath)
{
std::unique_ptr<char[]> crcBuf(new char[purefs::buffer::crc_char_size]);
fs::path crcFilePath(filePath);
crcFilePath += purefs::extension::crc32;
vfs::FILE *fp = ::vfs.fopen(crcFilePath.c_str(), "r");
if (fp != NULL) {
if (::vfs.fgets(crcBuf.get(), purefs::buffer::crc_char_size, fp) == NULL) {
LOG_ERROR("verifyCRC ff_fgets on %s returned NULL", crcFilePath.c_str());
return (false);
}
::vfs.fclose(fp);
const unsigned long crc32Read = strtoull(crcBuf.get(), nullptr, purefs::buffer::crc_radix);
return (verifyCRC(filePath, crc32Read));
}
LOG_ERROR("verifyCRC can't open %s", crcFilePath.c_str());
return (false);
}