M module-apps/application-desktop/CMakeLists.txt => module-apps/application-desktop/CMakeLists.txt +1 -0
@@ 67,4 67,5 @@ target_link_libraries(${PROJECT_NAME}
service-db
service-desktop
service-time
+ utils-bootconfig
)
M module-apps/application-desktop/windows/Update.cpp => module-apps/application-desktop/windows/Update.cpp +4 -5
@@ 17,6 17,7 @@
#include "service-cellular/ServiceCellular.hpp"
#include <Style.hpp>
+#include <boot/bootconfig.hpp>
namespace gui
{
@@ 175,12 176,10 @@ namespace gui
updateVersion << utils::localize.get("app_desktop_update_to");
updateVersion << ": ";
- updateVersion << msg.updateStats
- .versionInformation[purefs::json::os_version][purefs::json::version_string]
+ updateVersion << msg.updateStats.versionInformation[boot::json::os_version][boot::json::version_string]
.string_value();
updateVersion << " (";
- updateVersion << msg.updateStats
- .versionInformation[purefs::json::git_info][purefs::json::os_git_revision]
+ updateVersion << msg.updateStats.versionInformation[boot::json::git_info][boot::json::os_git_revision]
.string_value();
updateVersion << ")";
@@ 189,7 188,7 @@ namespace gui
updateFileDetails << std::to_string(msg.updateStats.totalBytes / 1024);
updateFileDetails << "Kb (";
updateFileDetails
- << msg.updateStats.versionInformation[purefs::json::misc][purefs::json::builddate].string_value();
+ << msg.updateStats.versionInformation[boot::json::misc][boot::json::builddate].string_value();
updateFileDetails << ")";
currentVersionInfo->setText(currentVersion.str());
M module-apps/application-settings-new/windows/QuotesMainWindow.cpp => module-apps/application-settings-new/windows/QuotesMainWindow.cpp +2 -2
@@ 41,7 41,7 @@ namespace gui
return false;
}
- void QuotesMainWindow::readQuotes(fs::path fn)
+ void QuotesMainWindow::readQuotes(std::filesystem::path fn)
{
std::string err;
@@ 88,7 88,7 @@ namespace gui
rebuildOptionList();
}
- std::string QuotesMainWindow::readFileToString(const fs::path &fn)
+ std::string QuotesMainWindow::readFileToString(const std::filesystem::path &fn)
{
constexpr auto tar_buf = 8192 * 4;
auto file = std::fopen(fn.c_str(), "r");
M module-apps/application-settings-new/windows/QuotesMainWindow.hpp => module-apps/application-settings-new/windows/QuotesMainWindow.hpp +3 -3
@@ 4,7 4,7 @@
#pragma once
#include "BaseSettingsWindow.hpp"
-
+#include <filesystem>
namespace gui
{
@@ 21,9 21,9 @@ namespace gui
auto buildOptionsList() -> std::list<Option> override;
private:
- void readQuotes(fs::path fn);
+ void readQuotes(std::filesystem::path fn);
void switchHandler(bool &optionSwitch);
- [[nodiscard]] static std::string readFileToString(const fs::path &fn);
+ [[nodiscard]] static std::string readFileToString(const std::filesystem::path &fn);
std::list<std::pair<std::string, bool>> quotes;
};
M module-bluetooth/Bluetooth/BtKeysStorage.cpp => module-bluetooth/Bluetooth/BtKeysStorage.cpp +1 -0
@@ 8,6 8,7 @@
#include <gsl/gsl_util>
#include "BtKeysStorage.hpp"
+#include <log/log.hpp>
json11::Json Bt::KeyStorage::fileJson = json11::Json();
btstack_link_key_db_t Bt::KeyStorage::keyStorage;
M module-bluetooth/Bluetooth/BtKeysStorage.hpp => module-bluetooth/Bluetooth/BtKeysStorage.hpp +0 -1
@@ 7,7 7,6 @@
#include <btstack_util.h>
#include <json/json11.hpp>
-#include <vfs.hpp>
namespace Bt
{
M module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.cpp => module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.cpp +1 -0
@@ 17,6 17,7 @@
#include <Audio/AudioCommon.hpp>
#include <service-audio/AudioMessage.hpp>
#include <service-evtmgr/Constants.hpp>
+#include <log/log.hpp>
extern "C"
{
#include "module-bluetooth/lib/btstack/src/btstack.h"
M module-services/service-desktop/endpoints/backup/BackupRestore.cpp => module-services/service-desktop/endpoints/backup/BackupRestore.cpp +12 -11
@@ 12,6 12,7 @@
#include <cassert>
#include <filesystem>
+#include <purefs/filesystem_paths.hpp>
#include <memory>
#include <string>
#include <vector>
@@ 23,6 24,7 @@ namespace sys
static const long unsigned int empty_dirlist_size = 2;
static const auto backup_file_name = "backup.tar";
+static constexpr auto tar_buf = 8192 * 4;
void BackupRestore::BackupUserFiles(sys::Service *ownerService)
{
@@ 38,7 40,7 @@ void BackupRestore::BackupUserFiles(sys::Service *ownerService)
return;
}
- std::string backupPathDB = PATH_BACKUP;
+ std::string backupPathDB = purefs::dir::getBackupOSPath();
backupPathDB += "/";
LOG_INFO("BackupUserFiles: database backup started...");
@@ 113,7 115,7 @@ bool BackupRestore::CreateBackupDir()
bool BackupRestore::PackUserFiles()
{
- std::string backupPathDB = PATH_BACKUP;
+ std::string backupPathDB = purefs::dir::getBackupOSPath();
backupPathDB += "/";
const auto backupOSPath = purefs::dir::getBackupOSPath();
@@ 140,8 142,7 @@ bool BackupRestore::PackUserFiles()
BackupRestore::RemoveBackupDir();
return false;
}
-
- std::unique_ptr<unsigned char[]> buffer(new unsigned char[purefs::buffer::tar_buf]);
+ std::unique_ptr<unsigned char[]> buffer(new unsigned char[tar_buf]);
for (auto &direntry : std::filesystem::directory_iterator(backupOSPath.c_str())) {
if ((direntry.path().string().compare(".") != 0) && (direntry.path().string().compare("..") != 0) &&
@@ 170,15 171,15 @@ bool BackupRestore::PackUserFiles()
return false;
}
- uint32_t loopcount = (utils::filesystem::filelength(file) / purefs::buffer::tar_buf) + 1u;
+ uint32_t loopcount = (utils::filesystem::filelength(file) / tar_buf) + 1u;
uint32_t readsize = 0u;
for (uint32_t i = 0u; i < loopcount; i++) {
if (i + 1u == loopcount) {
- readsize = utils::filesystem::filelength(file) % purefs::buffer::tar_buf;
+ readsize = utils::filesystem::filelength(file) % tar_buf;
}
else {
- readsize = purefs::buffer::tar_buf;
+ readsize = tar_buf;
}
LOG_INFO("PackUserFiles: reading file %s...", direntry.path().string().c_str());
@@ 260,7 261,7 @@ bool BackupRestore::UnpackBackupFile()
return false;
}
- std::unique_ptr<unsigned char[]> buffer(new unsigned char[purefs::buffer::tar_buf]);
+ std::unique_ptr<unsigned char[]> buffer(new unsigned char[tar_buf]);
do {
ret = mtar_read_header(&tarFile, &tarHeader);
@@ 280,16 281,16 @@ bool BackupRestore::UnpackBackupFile()
return false;
}
- uint32_t loopcount = (tarHeader.size / purefs::buffer::tar_buf) + 1u;
+ uint32_t loopcount = (tarHeader.size / tar_buf) + 1u;
uint32_t readsize = 0u;
for (uint32_t i = 0u; i < loopcount; i++) {
if (i + 1u == loopcount) {
- readsize = tarHeader.size % purefs::buffer::tar_buf;
+ readsize = tarHeader.size % tar_buf;
}
else {
- readsize = purefs::buffer::tar_buf;
+ readsize = tar_buf;
}
if (mtar_read_data(&tarFile, buffer.get(), readsize) != MTAR_ESUCCESS) {
M module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp => module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp +12 -4
@@ 12,6 12,8 @@
#include <service-desktop/service-desktop/ServiceDesktop.hpp>
#include <cstdint>
#include <string>
+#include <sys/statvfs.h>
+#include <purefs/filesystem_paths.hpp>
auto DeviceInfoEndpoint::handle(Context &context) -> void
{
@@ 27,8 29,14 @@ auto DeviceInfoEndpoint::handle(Context &context) -> void
}
auto DeviceInfoEndpoint::getDeviceInfo(Context &context) -> bool
{
- vfs::FilesystemStats fsStats = vfs.getFilesystemStats();
json11::Json updateHistory = static_cast<ServiceDesktop *>(ownerServicePtr)->updateOS->getUpdateHistory();
+ struct statvfs vfstat;
+ if (statvfs(purefs::dir::getRootDiskPath().c_str(), &vfstat) < 0) {
+ return false;
+ }
+ auto totalMbytes = (vfstat.f_frsize * vfstat.f_blocks) / 1024LLU / 1024LLU;
+ auto freeMbytes = (vfstat.f_ffree * vfstat.f_bsize) / 1024LLU / 1024LLU;
+ auto freePercent = (freeMbytes * 100) / totalMbytes;
context.setResponseBody(json11::Json::object(
{{json::batteryLevel, std::to_string(Store::Battery::get().level)},
@@ 38,9 46,9 @@ auto DeviceInfoEndpoint::getDeviceInfo(Context &context) -> bool
{json::signalStrength, std::to_string(static_cast<int>(Store::GSM::get()->getSignalStrength().rssiBar))},
{json::accessTechnology, std::to_string(static_cast<int>(Store::GSM::get()->getNetwork().accessTechnology))},
{json::networkStatus, std::to_string(static_cast<int>(Store::GSM::get()->getNetwork().status))},
- {json::fsTotal, std::to_string(fsStats.totalMbytes)},
- {json::fsFree, std::to_string(fsStats.freeMbytes)},
- {json::fsFreePercent, std::to_string(fsStats.freePercent)},
+ {json::fsTotal, std::to_string(totalMbytes)},
+ {json::fsFree, std::to_string(freeMbytes)},
+ {json::fsFreePercent, std::to_string(freePercent)},
{json::gitRevision, (std::string)(GIT_REV)},
{json::gitTag, (std::string)GIT_TAG},
{json::gitBranch, (std::string)GIT_BRANCH},
M module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp => module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp +28 -27
@@ 17,6 17,8 @@
#include <time/time_conversion.hpp>
#include <filesystem>
#include <Utils.hpp>
+#include <boot/bootconfig.hpp>
+#include <boot/bootconstants.hpp>
#if defined(TARGET_RT1051)
#include <board/cross/eMMC/eMMC.hpp>
@@ 201,9 203,8 @@ std::string UpdateMuditaOS::readContent(const char *filename) noexcept
updateos::UpdateError UpdateMuditaOS::verifyChecksums()
{
status = updateos::UpdateState::ChecksumVerification;
-
auto lineBuff = std::make_unique<char[]>(
- purefs::buffer::tar_buf); // max line should be freertos max path + checksum, so this is enough
+ boot::consts::tar_buf); // max line should be freertos max path + checksum, so this is enough
fs::path checksumsFile = getUpdateTmpChild(updateos::file::checksums);
auto fpChecksums = std::fopen(checksumsFile.c_str(), "r");
@@ 214,7 215,7 @@ updateos::UpdateError UpdateMuditaOS::verifyChecksums()
}
while (!std::feof(fpChecksums)) {
- char *line = std::fgets(lineBuff.get(), purefs::buffer::tar_buf, fpChecksums);
+ char *line = std::fgets(lineBuff.get(), boot::consts::tar_buf, fpChecksums);
std::string filePath;
unsigned long fileCRC32;
@@ 257,7 258,7 @@ updateos::UpdateError UpdateMuditaOS::verifyVersion()
else {
/* version comparison goes here */
updateRunStatus.toVersion = targetVersionInfo;
- const bool ret = bootConfig.version_compare(targetVersionInfo[purefs::json::version_string].string_value(),
+ const bool ret = bootConfig.version_compare(targetVersionInfo[boot::json::version_string].string_value(),
bootConfig.os_version());
LOG_DEBUG("verifyVersion comparison result == %s", ret ? "true" : "false");
}
@@ 267,9 268,9 @@ updateos::UpdateError UpdateMuditaOS::verifyVersion()
updateos::UpdateError UpdateMuditaOS::updateBootloader()
{
informDebug("updateBootloader");
- if (targetVersionInfo[purefs::json::bootloader][parserFSM::json::fileName].is_string()) {
+ if (targetVersionInfo[boot::json::bootloader][parserFSM::json::fileName].is_string()) {
fs::path bootloaderFile =
- getUpdateTmpChild(targetVersionInfo[purefs::json::bootloader][parserFSM::json::fileName].string_value());
+ getUpdateTmpChild(targetVersionInfo[boot::json::bootloader][parserFSM::json::fileName].string_value());
return writeBootloader(bootloaderFile);
}
return updateos::UpdateError::NoError;
@@ 290,9 291,9 @@ void UpdateMuditaOS::getChecksumInfo(const std::string &infoLine, std::string &f
std::size_t lastSpacePos = infoLine.find_last_of(' ');
if (lastSpacePos > 0) {
filePath = infoLine.substr(0, lastSpacePos);
- const std::string fileCRC32Str = infoLine.substr(lastSpacePos + 1, purefs::buffer::crc_char_size - 1);
+ const std::string fileCRC32Str = infoLine.substr(lastSpacePos + 1, boot::consts::crc_char_size - 1);
if (fileCRC32Long != nullptr) {
- *fileCRC32Long = strtoull(fileCRC32Str.c_str(), nullptr, purefs::buffer::crc_radix);
+ *fileCRC32Long = strtoull(fileCRC32Str.c_str(), nullptr, boot::consts::crc_radix);
informDebug("getChecksumInfo filePath: %s fileCRC32Str: %s fileCRC32Long: %lu fileCRC32Hex: %lX",
filePath.c_str(),
fileCRC32Str.c_str(),
@@ 382,13 383,13 @@ updateos::UpdateError UpdateMuditaOS::updateBootJSON()
if (fp != nullptr) {
utils::filesystem::computeCRC32(fp, &bootJSONAbsoulteCRC);
- bootJSONAbsoulte += purefs::extension::crc32;
+ bootJSONAbsoulte += boot::consts::ext_crc32;
auto *fpCRC = std::fopen(bootJSONAbsoulte.c_str(), "w");
if (fpCRC != nullptr) {
- std::array<char, purefs::buffer::crc_char_size> crcBuf;
+ std::array<char, boot::consts::crc_char_size> crcBuf;
snprintf(crcBuf.data(), crcBuf.size(), "%lX", bootJSONAbsoulteCRC);
- std::fwrite(crcBuf.data(), 1, purefs::buffer::crc_char_size, fpCRC);
+ std::fwrite(crcBuf.data(), 1, boot::consts::crc_char_size, fpCRC);
std::fclose(fpCRC);
}
else {
@@ 407,11 408,11 @@ updateos::UpdateError UpdateMuditaOS::updateBootJSON()
bool UpdateMuditaOS::unpackFileToTemp(mtar_header_t &h, unsigned long *crc32)
{
- auto readBuf = std::make_unique<unsigned char[]>(purefs::buffer::tar_buf);
+ auto readBuf = std::make_unique<unsigned char[]>(boot::consts::tar_buf);
const fs::path fullPath = getUpdateTmpChild(h.name);
- uint32_t blocksToRead = (h.size / purefs::buffer::tar_buf) + 1;
- uint32_t sizeToRead = purefs::buffer::tar_buf;
+ uint32_t blocksToRead = (h.size / boot::consts::tar_buf) + 1;
+ uint32_t sizeToRead = boot::consts::tar_buf;
fileExtracted = h.name;
fileExtractedSize = h.size;
@@ 434,10 435,10 @@ bool UpdateMuditaOS::unpackFileToTemp(mtar_header_t &h, unsigned long *crc32)
for (uint32_t i = 0; i < blocksToRead; i++) {
if (i + 1 == blocksToRead) {
- sizeToRead = h.size % purefs::buffer::tar_buf;
+ sizeToRead = h.size % boot::consts::tar_buf;
}
else {
- sizeToRead = purefs::buffer::tar_buf;
+ sizeToRead = boot::consts::tar_buf;
}
if (sizeToRead == 0)
@@ 620,7 621,7 @@ const json11::Json UpdateMuditaOS::getVersionInfoFromFile(const fs::path &update
return json11::Json();
}
- std::unique_ptr<char[]> versionFilename(new char[purefs::buffer::crc_buf]);
+ std::unique_ptr<char[]> versionFilename(new char[boot::consts::crc_buf]);
sprintf(versionFilename.get(), "./%s", updateos::file::version);
if (mtar_find(&tar, versionFilename.get(), &h) == MTAR_ENOTFOUND) {
LOG_INFO("UpdateMuditaOS::getVersionInfoFromFile can't find %s in %s",
@@ 631,8 632,8 @@ const json11::Json UpdateMuditaOS::getVersionInfoFromFile(const fs::path &update
return json11::Json();
}
- /* this file should never be larger then purefs::buffer::tar_buf */
- std::unique_ptr<char[]> readBuf(new char[purefs::buffer::tar_buf]);
+ /* this file should never be larger then boot::consts::tar_buf */
+ std::unique_ptr<char[]> readBuf(new char[boot::consts::tar_buf]);
if (mtar_read_data(&tar, readBuf.get(), h.size) != MTAR_ESUCCESS) {
LOG_INFO("UpdateMuditaOS::getVersionInfoFromFile can't read %s in %s",
updateos::file::version,
@@ 676,9 677,9 @@ const fs::path UpdateMuditaOS::checkForUpdate()
if (versionInfo.is_null())
continue;
- if (versionInfo[purefs::json::os_version][purefs::json::version_string].is_string()) {
+ if (versionInfo[boot::json::os_version][boot::json::version_string].is_string()) {
if (UpdateMuditaOS::isUpgradeToCurrent(
- versionInfo[purefs::json::os_version][purefs::json::version_string].string_value())) {
+ versionInfo[boot::json::os_version][boot::json::version_string].string_value())) {
return updatesOSPath / file.path();
}
}
@@ 695,9 696,9 @@ updateos::UpdateError UpdateMuditaOS::updateUserData()
updateos::UpdateError UpdateMuditaOS::informError(const updateos::UpdateError errorCode, const char *format, ...)
{
va_list argptr;
- std::unique_ptr<char[]> readBuf(new char[purefs::buffer::tar_buf]);
+ std::unique_ptr<char[]> readBuf(new char[boot::consts::tar_buf]);
va_start(argptr, format);
- vsnprintf(readBuf.get(), purefs::buffer::tar_buf, format, argptr);
+ vsnprintf(readBuf.get(), boot::consts::tar_buf, format, argptr);
va_end(argptr);
LOG_ERROR("UPDATE_ERRROR [%d] %s", static_cast<uint8_t>(errorCode), readBuf.get());
@@ 724,9 725,9 @@ updateos::UpdateError UpdateMuditaOS::informError(const updateos::UpdateError er
void UpdateMuditaOS::informDebug(const char *format, ...)
{
va_list argptr;
- std::unique_ptr<char[]> readBuf(new char[purefs::buffer::tar_buf]);
+ std::unique_ptr<char[]> readBuf(new char[boot::consts::tar_buf]);
va_start(argptr, format);
- vsnprintf(readBuf.get(), purefs::buffer::tar_buf, format, argptr);
+ vsnprintf(readBuf.get(), boot::consts::tar_buf, format, argptr);
va_end(argptr);
LOG_DEBUG("UPDATE_DEBUG %s", readBuf.get());
@@ 735,9 736,9 @@ void UpdateMuditaOS::informDebug(const char *format, ...)
void UpdateMuditaOS::informUpdate(const updateos::UpdateState statusCode, const char *format, ...)
{
va_list argptr;
- std::unique_ptr<char[]> readBuf(new char[purefs::buffer::tar_buf]);
+ std::unique_ptr<char[]> readBuf(new char[boot::consts::tar_buf]);
va_start(argptr, format);
- vsnprintf(readBuf.get(), purefs::buffer::tar_buf, format, argptr);
+ vsnprintf(readBuf.get(), boot::consts::tar_buf, format, argptr);
va_end(argptr);
LOG_INFO("UPDATE_INFO [%d] %s", static_cast<uint8_t>(statusCode), readBuf.get());
M module-services/service-desktop/endpoints/update/UpdateMuditaOS.hpp => module-services/service-desktop/endpoints/update/UpdateMuditaOS.hpp +2 -1
@@ 6,6 6,7 @@
#include <json/json11.hpp>
#include <module-utils/microtar/src/microtar.hpp>
#include <boot/bootconfig.hpp>
+#include <purefs/filesystem_paths.hpp>
#include <cstdint>
#include <filesystem>
@@ 94,7 95,7 @@ namespace updateos
{
fs::path updateFile = "";
fs::path fileExtracted = "";
- fs::path updateTempDirectory = PATH_SYS "/" PATH_TMP;
+ fs::path updateTempDirectory = purefs::dir::getTemporaryPath();
uint32_t totalBytes = 0;
uint32_t currentExtractedBytes = 0;
uint32_t fileExtractedSize = 0;
M module-services/service-fileindexer/ServiceFileIndexer.cpp => module-services/service-fileindexer/ServiceFileIndexer.cpp +0 -1
@@ 2,7 2,6 @@
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include <log/log.hpp>
-#include <vfs.hpp>
#include "ServiceFileIndexer.hpp"
#include "notesIndexer.hpp"
#include "messages/FileChangeMessage.hpp"
M module-utils/bootconfig/include/boot/bootconfig.hpp => module-utils/bootconfig/include/boot/bootconfig.hpp +20 -0
@@ 8,6 8,26 @@
namespace boot
{
+ namespace json
+ {
+ inline constexpr auto main = "main";
+ inline constexpr auto os_type = "ostype";
+ inline constexpr auto os_image = "imagename";
+ inline constexpr auto os_version = "version";
+ inline constexpr auto version_major = "major";
+ inline constexpr auto version_minor = "minor";
+ inline constexpr auto version_patch = "patch";
+ inline constexpr auto version_string = "string";
+ inline constexpr auto timestamp = "timestamp";
+ inline constexpr auto misc = "misc";
+ inline constexpr auto builddate = "builddate";
+ inline constexpr auto git_info = "git";
+ inline constexpr auto os_git_tag = "git_tag";
+ inline constexpr auto os_git_revision = "git_commit";
+ inline constexpr auto os_git_branch = "git_branch";
+ inline constexpr auto bootloader = "bootloader";
+ } // namespace json
+
class BootConfig
{
public:
A module-utils/bootconfig/include/boot/bootconstants.hpp => module-utils/bootconfig/include/boot/bootconstants.hpp +12 -0
@@ 0,0 1,12 @@
+// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#pragma once
+namespace boot::consts
+{
+ inline constexpr auto tar_buf = 8192 * 4;
+ inline constexpr auto crc_char_size = 9;
+ inline constexpr auto crc_radix = 16;
+ inline constexpr auto ext_crc32 = ".crc32";
+ inline constexpr auto crc_buf = 1024;
+} // namespace boot::consts
M module-utils/bootconfig/src/bootconfig.cpp => module-utils/bootconfig/src/bootconfig.cpp +41 -41
@@ 1,12 1,13 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include <boot/bootconfig.hpp>
+#include <boot/bootconstants.hpp>
#include <purefs/filesystem_paths.hpp>
#include <source/version.hpp>
#include <time/time_conversion.hpp>
#include <ticks.hpp>
-#include <stdio.h>
+#include <cstdio>
#include <log/log.hpp>
#include <crc32/crc32.h>
@@ 14,7 15,8 @@ namespace boot
{
namespace
{
- bool replaceWithString(const fs::path &fileToModify, const std::string &stringToWrite)
+
+ bool replaceWithString(const std::filesystem::path &fileToModify, const std::string &stringToWrite)
{
auto lamb = [](::FILE *stream) { fclose(stream); };
std::unique_ptr<::FILE, decltype(lamb)> fp(fopen(fileToModify.c_str(), "w"), lamb);
@@ 27,18 29,17 @@ namespace boot
return false;
}
}
- void computeCRC32(::FILE *file, unsigned long *outCrc32)
+ void computeCRC32(std::FILE *file, unsigned long *outCrc32)
{
if (outCrc32 == nullptr)
return;
-
- std::unique_ptr<unsigned char[]> buf(new unsigned char[purefs::buffer::crc_buf]);
+ std::unique_ptr<unsigned char[]> buf(new unsigned char[boot::consts::crc_buf]);
size_t bufLen;
*outCrc32 = 0;
- while (!::feof(file)) {
- bufLen = ::fread(buf.get(), 1, purefs::buffer::crc_buf, file);
+ while (!std::feof(file)) {
+ bufLen = std::fread(buf.get(), 1, boot::consts::crc_buf, file);
if (bufLen <= 0)
break;
@@ 46,7 47,7 @@ namespace boot
}
}
- bool updateFileCRC32(const fs::path &file)
+ bool updateFileCRC32(const std::filesystem::path &file)
{
unsigned long fileCRC32 = 0;
auto lamb = [](::FILE *stream) { ::fclose(stream); };
@@ 54,7 55,7 @@ namespace boot
std::unique_ptr<::FILE, decltype(lamb)> fp(fopen(file.c_str(), "r"), lamb);
if (fp.get() != nullptr) {
- std::unique_ptr<char[]> crc32Buf(new char[purefs::buffer::crc_char_size]);
+ std::unique_ptr<char[]> crc32Buf(new char[boot::consts::crc_char_size]);
int written = 0;
computeCRC32(fp.get(), &fileCRC32);
LOG_INFO("updateFileCRC32 writing new crc32 %08" PRIX32 " for %s",
@@ 62,20 63,20 @@ namespace boot
file.c_str());
if (fileCRC32 != 0) {
if ((written = sprintf(crc32Buf.get(), "%08" PRIX32, fileCRC32)) !=
- (purefs::buffer::crc_char_size - 1)) {
+ (boot::consts::crc_char_size - 1)) {
LOG_INFO("updateFileCRC32 can't prepare string for crc32, sprintf returned %d instead of %d",
written,
- purefs::buffer::crc_char_size - 1);
+ boot::consts::crc_char_size - 1);
return false;
}
- fs::path fileCRC32Path = file;
- fileCRC32Path += purefs::extension::crc32;
+ std::filesystem::path fileCRC32Path = file;
+ fileCRC32Path += boot::consts::ext_crc32;
std::unique_ptr<::FILE, decltype(lamb)> fpCRC32(fopen(fileCRC32Path.c_str(), "w"), lamb);
if (fpCRC32.get() != nullptr) {
- if (fwrite(crc32Buf.get(), 1, purefs::buffer::crc_char_size, fpCRC32.get()) ==
- purefs::buffer::crc_char_size) {
+ if (fwrite(crc32Buf.get(), 1, boot::consts::crc_char_size, fpCRC32.get()) ==
+ boot::consts::crc_char_size) {
LOG_INFO("updateFileCRC32 wrote \"%s\" in %s", crc32Buf.get(), fileCRC32Path.c_str());
return true;
}
@@ 97,17 98,17 @@ namespace boot
return false;
}
- std::string loadFileAsString(const fs::path &fileToLoad)
+ std::string loadFileAsString(const std::filesystem::path &fileToLoad)
{
auto lamb = [](::FILE *stream) { ::fclose(stream); };
- std::unique_ptr<char[]> readBuf(new char[purefs::buffer::tar_buf]);
+ std::unique_ptr<char[]> readBuf(new char[boot::consts::tar_buf]);
std::unique_ptr<::FILE, decltype(lamb)> fp(fopen(fileToLoad.c_str(), "r"), lamb);
std::string contents;
size_t readSize;
if (fp.get() != nullptr) {
while (!feof(fp.get())) {
- readSize = fread(readBuf.get(), 1, purefs::buffer::tar_buf, fp.get());
+ readSize = fread(readBuf.get(), 1, boot::consts::tar_buf, fp.get());
contents.append(static_cast<const char *>(readBuf.get()), readSize);
}
}
@@ 122,17 123,17 @@ namespace boot
json11::Json BootConfig::to_json() const
{
return json11::Json::object{
- {purefs::json::main,
- json11::Json::object{{purefs::json::os_image, m_os_image},
- {purefs::json::os_type, m_os_type},
- {purefs::json::os_version, m_os_version},
- {purefs::json::timestamp, m_timestamp}}},
-
- {purefs::json::git_info,
- json11::Json::object{{purefs::json::os_git_tag, std::string(GIT_TAG)},
- {purefs::json::os_git_revision, std::string(GIT_REV)},
- {purefs::json::os_git_branch, std::string(GIT_BRANCH)}}},
- {purefs::json::bootloader, json11::Json::object{{purefs::json::os_version, m_bootloader_version}}}};
+ {boot::json::main,
+ json11::Json::object{{boot::json::os_image, m_os_image},
+ {boot::json::os_type, m_os_type},
+ {boot::json::os_version, m_os_version},
+ {boot::json::timestamp, m_timestamp}}},
+
+ {boot::json::git_info,
+ json11::Json::object{{boot::json::os_git_tag, std::string(GIT_TAG)},
+ {boot::json::os_git_revision, std::string(GIT_REV)},
+ {boot::json::os_git_branch, std::string(GIT_BRANCH)}}},
+ {boot::json::bootloader, json11::Json::object{{boot::json::os_version, m_bootloader_version}}}};
}
int BootConfig::load()
{
@@ 188,12 189,11 @@ namespace boot
m_boot_json_parsed = json11::Json::parse(jsonContents, parseErrors);
if (parseErrors == "") {
- m_os_type = m_boot_json_parsed[purefs::json::main][purefs::json::os_type].string_value();
- m_os_image = m_boot_json_parsed[purefs::json::main][purefs::json::os_image].string_value();
+ m_os_type = m_boot_json_parsed[boot::json::main][boot::json::os_type].string_value();
+ m_os_image = m_boot_json_parsed[boot::json::main][boot::json::os_image].string_value();
m_os_root_path = purefs::createPath(purefs::dir::getRootDiskPath(), m_os_type);
m_boot_json = bootJsonPath;
- m_bootloader_version =
- m_boot_json_parsed[purefs::json::bootloader][purefs::json::os_version].string_value();
+ m_bootloader_version = m_boot_json_parsed[boot::json::bootloader][boot::json::os_version].string_value();
m_timestamp = utils::time::Timestamp().str("%c");
m_os_version = std::string(VERSION);
@@ 201,7 201,7 @@ namespace boot
return true;
}
else {
- m_os_type = PATH_CURRENT;
+ m_os_type = purefs::dir::getCurrentOSPath();
m_os_image = purefs::file::boot_bin;
m_os_root_path = purefs::createPath(purefs::dir::getRootDiskPath(), m_os_type);
m_boot_json = bootJsonPath;
@@ 243,24 243,24 @@ namespace boot
bool BootConfig::verifyCRC(const std::filesystem::path filePath)
{
auto lamb = [](::FILE *stream) { ::fclose(stream); };
- std::unique_ptr<char[]> crcBuf(new char[purefs::buffer::crc_char_size]);
+ std::unique_ptr<char[]> crcBuf(new char[boot::consts::crc_char_size]);
size_t readSize;
- fs::path crcFilePath(filePath);
- crcFilePath += purefs::extension::crc32;
+ std::filesystem::path crcFilePath(filePath);
+ crcFilePath += boot::consts::ext_crc32;
std::unique_ptr<::FILE, decltype(lamb)> fp(::fopen(crcFilePath.c_str(), "r"), lamb);
if (fp.get() != nullptr) {
- if ((readSize = ::fread(crcBuf.get(), 1, purefs::buffer::crc_char_size, fp.get())) !=
- (purefs::buffer::crc_char_size)) {
+ if ((readSize = ::fread(crcBuf.get(), 1, boot::consts::crc_char_size, fp.get())) !=
+ (boot::consts::crc_char_size)) {
LOG_ERROR("verifyCRC fread on %s returned different size then %d [%zu]",
crcFilePath.c_str(),
- purefs::buffer::crc_char_size,
+ boot::consts::crc_char_size,
readSize);
return false;
}
- const unsigned long crc32Read = strtoull(crcBuf.get(), nullptr, purefs::buffer::crc_radix);
+ const unsigned long crc32Read = strtoull(crcBuf.get(), nullptr, boot::consts::crc_radix);
LOG_INFO("verifyCRC read %s string:\"%s\" hex:%08lX", crcFilePath.c_str(), crcBuf.get(), crc32Read);
return verifyCRC(filePath, crc32Read);
M module-utils/i18n/i18n.hpp => module-utils/i18n/i18n.hpp +0 -1
@@ 4,7 4,6 @@
#pragma once
#include "json/json11.hpp"
#include <string>
-#include <vfs.hpp>
using Language = std::string;
M module-utils/microtar => module-utils/microtar +1 -1
@@ 1,1 1,1 @@
-Subproject commit 4b1bb35816269d956dbac1922f9cc8b3bd481c16
+Subproject commit 966b5d38f82d68152e08f8b67c04e0dc1249e4e1
M module-utils/taglib => module-utils/taglib +1 -1
@@ 1,1 1,1 @@
-Subproject commit 96d449e4163de4f5d7b448bdb2aee303a746d89f
+Subproject commit 116a66f9407d3b8d522baf464713b175ff4b73c4
M module-vfs/CMakeLists.txt => module-vfs/CMakeLists.txt +0 -1
@@ 32,7 32,6 @@ set(SOURCES
src/purefs/vfs_subsystem.cpp
drivers/src/purefs/fs/filesystem_vfat.cpp
drivers/src/purefs/fs/filesystem_littlefs.cpp
- src/deprecated/vfs.cpp
)
D module-vfs/include/user/deprecated/vfs.hpp => module-vfs/include/user/deprecated/vfs.hpp +0 -147
@@ 1,147 0,0 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
-// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-
-#pragma once
-
-#include <stdint.h>
-#include <string>
-#include <vector>
-#include <sstream>
-#include <filesystem>
-#include <log/log.hpp>
-#include <atomic>
-#include <boot/bootconfig.hpp>
-#include "vfs_globals.hpp"
-
-#ifndef TARGET_Linux
-#include "board/cross/eMMC/eMMC.hpp"
-#endif
-
-
-namespace fs = std::filesystem;
-
-namespace purefs
-{
- namespace extension
- {
- inline constexpr auto crc32 = ".crc32";
- }
-
- namespace buffer
- {
- inline constexpr auto crc_buf = 1024;
- inline constexpr auto crc_char_size = 9;
- inline constexpr auto crc_radix = 16;
- inline constexpr auto tar_buf = 8192 * 4;
- inline constexpr auto copy_buf = 8192 * 4;
- } // namespace buffer
-
- namespace json
- {
- inline constexpr auto main = "main";
- inline constexpr auto os_type = "ostype";
- inline constexpr auto os_image = "imagename";
- inline constexpr auto os_version = "version";
- inline constexpr auto version_major = "major";
- inline constexpr auto version_minor = "minor";
- inline constexpr auto version_patch = "patch";
- inline constexpr auto version_string = "string";
- inline constexpr auto timestamp = "timestamp";
- inline constexpr auto misc = "misc";
- inline constexpr auto builddate = "builddate";
- inline constexpr auto git_info = "git";
- inline constexpr auto os_git_tag = "git_tag";
- inline constexpr auto os_git_revision = "git_commit";
- inline constexpr auto os_git_branch = "git_branch";
- inline constexpr auto bootloader = "bootloader";
- } // namespace json
-
-}; // namespace purefs
-
-/* NOTE: VFS global object class is now deprecated more information
- * on the confuence page:
- * https://appnroll.atlassian.net/wiki/spaces/MFP/pages/706248802/VFS+library+migration+guide
- */
-class vfs
-{
- public:
- // using FsEvent = vfsn::utility::vfsNotifier::FsEvent;
- enum class FileAttributes
- {
- ReadOnly,
- Writable,
- Directory
- };
-
- struct DirectoryEntry
- {
- std::string fileName;
- FileAttributes attributes;
- uint32_t fileSize;
- json11::Json to_json() const
- {
- return (json11::Json::object{{"name", fileName}, {"size", std::to_string(fileSize)}});
- }
- };
-
- struct FilesystemStats
- {
- std::string type;
- uint32_t freeMbytes;
- uint32_t freePercent;
- uint32_t totalMbytes;
- };
- vfs();
- ~vfs();
- void Init();
- [[deprecated]] FILE *fopen(const char *filename, const char *mode);
- [[deprecated]] int fclose(FILE *stream);
- [[deprecated]] int remove(const char *name);
- [[deprecated]] size_t fread(void *ptr, size_t size, size_t count, FILE *stream);
- [[deprecated]] size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream);
- [[deprecated]] int fseek(FILE *stream, long int offset, int origin);
- [[deprecated]] long int ftell(FILE *stream);
- [[deprecated]] void rewind(FILE *stream);
- [[deprecated]] size_t filelength(FILE *stream);
- [[deprecated]] std::string getcurrdir();
- [[deprecated]] char *fgets(char *buffer, size_t count, FILE *stream);
- [[deprecated]] bool eof(FILE *stream);
- [[deprecated]] std::vector<DirectoryEntry> listdir(const char *path,
- const std::string &ext = "",
- const bool bypassRootCheck = false);
- [[deprecated]] std::string getline(FILE *stream, uint32_t length = 1024);
- [[deprecated]] size_t fprintf(FILE *stream, const char *format, ...);
- [[deprecated]] FilesystemStats getFilesystemStats();
- [[deprecated]] std::string relativeToRoot(const std::string path);
- [[deprecated]] std::string lastErrnoToStr();
- [[deprecated]] bool isDir(const char *path);
- [[deprecated]] bool fileExists(const char *path);
- [[deprecated]] int deltree(const char *path);
- [[deprecated]] int mkdir(const char *dir);
- [[deprecated]] int rename(const char *oldname, const char *newname);
- /*
- [[deprecated]] void registerNotificationHandler(vfsn::utility::vfsNotifier::NotifyHandler handler)
- {
- chnNotifier.registerNotificationHandler(handler);
- }
- */
- [[deprecated]] auto getAbsolutePath(std::string_view path) const -> std::string;
-
-#ifndef TARGET_Linux
- bsp::eMMC emmc;
-#endif
-
- /// FF_Disk_t *emmcFFDisk{};
-
- auto isInitialized() const noexcept
- {
- return initDone.load();
- }
-
- private:
- // vfsn::utility::vfsNotifier chnNotifier;
- static std::atomic<bool> initDone;
- boot::BootConfig bootConfig;
-};
-
-extern vfs vfs;
D module-vfs/include/user/deprecated/vfs_globals.hpp => module-vfs/include/user/deprecated/vfs_globals.hpp +0 -16
@@ 1,16 0,0 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
-// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-
-#pragma once
-
-#define PATH_SYS "/sys"
-#define PATH_USER "user"
-#define PATH_CURRENT "current"
-#define PATH_PREVIOUS "previous"
-#define PATH_UPDATES "updates"
-#define PATH_TMP "tmp"
-#define PATH_BACKUP "backup"
-#define PATH_FACTORY "factory"
-
-// this just concatenates two strings and creates a /user/ subdirectory filename
-#define USER_PATH(file) PATH_SYS "/" PATH_USER "/" file
D module-vfs/src/deprecated/vfs.cpp => module-vfs/src/deprecated/vfs.cpp +0 -182
@@ 1,182 0,0 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
-// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-
-#include "vfs.hpp"
-#include <purefs/filesystem_paths.hpp>
-#include <memory>
-#include <cstring>
-#include <log/log.hpp>
-
-#define eMMCHIDDEN_SECTOR_COUNT 8
-#define eMMCPRIMARY_PARTITIONS 2
-#define eMMCHUNDRED_64_BIT 100ULL
-#define eMMCPARTITION_NUMBER 0
-#define eMMCBYTES_PER_MB (1024ull * 1024ull)
-#define eMMCSECTORS_PER_MB (eMMCBYTES_PER_MB / 512ull)
-
-/* Used as a magic number to indicate that an FF_Disk_t structure is a RAM
- disk. */
-#define eMMCSIGNATURE 0x61606362
-#define mainIO_MANAGER_CACHE_SIZE (15UL * FSL_SDMMC_DEFAULT_BLOCK_SIZE)
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-
-std::atomic<bool> vfs::initDone{false};
-
-FILE *vfs::fopen(const char *filename, const char *mode)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return nullptr;
-}
-
-int vfs::fclose(FILE *stream)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return -1;
-}
-
-int vfs::remove(const char *name)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return -1;
-}
-
-size_t vfs::fread(void *ptr, size_t size, size_t count, FILE *stream)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return -1;
-}
-
-size_t vfs::fwrite(const void *ptr, size_t size, size_t count, FILE *stream)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return -1;
-}
-
-int vfs::fseek(FILE *stream, long int offset, int origin)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return -1;
-}
-
-long int vfs::ftell(FILE *stream)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return -1;
-}
-
-void vfs::rewind(FILE *stream)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
-}
-
-size_t vfs::filelength(FILE *stream)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return 0;
-}
-
-char *vfs::fgets(char *buff, size_t count, FILE *stream)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return nullptr;
-}
-
-std::string vfs::getcurrdir()
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return {};
-}
-
-static inline bool hasEnding(std::string const &fullString, std::string const &ending)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return false;
-}
-
-std::vector<vfs::DirectoryEntry> vfs::listdir(const char *path, const std::string &ext, const bool bypassRootCheck)
-{
-
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return {};
-}
-
-bool vfs::eof(FILE *stream)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return false;
-}
-
-std::string vfs::getline(FILE *stream, uint32_t length)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return {};
-}
-
-vfs::FilesystemStats vfs::getFilesystemStats()
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return {};
-}
-
-std::string vfs::relativeToRoot(const std::string path)
-{
- return path;
-}
-
-bool vfs::isDir(const char *path)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return false;
-}
-
-bool vfs::fileExists(const char *path)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return false;
-}
-
-int vfs::deltree(const char *path)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return -1;
-}
-
-int vfs::mkdir(const char *dir)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return -1;
-}
-
-int vfs::rename(const char *oldname, const char *newname)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return -1;
-}
-
-std::string vfs::lastErrnoToStr()
-{
- return {};
-}
-
-size_t vfs::fprintf(FILE *stream, const char *format, ...)
-{
- LOG_FATAL("Unupported call [%s] !!!!", __PRETTY_FUNCTION__);
- return -1;
-}
-auto vfs::getAbsolutePath(std::string_view path) const -> std::string
-{
- return std::string(path);
-}
-
-vfs::~vfs()
-{}
-
-vfs::vfs()
-{}
-
-void vfs::Init()
-{}
-
-#pragma GCC diagnostic pop
M source/main.cpp => source/main.cpp +0 -2
@@ 46,13 46,11 @@
#include <source/version.hpp>
#include <SystemManager/SystemManager.hpp>
#include <thread.hpp>
-#include <vfs.hpp>
#include <purefs/vfs_subsystem.hpp>
#include <memory>
#include <vector>
-class vfs vfs;
int main()
{