Core Controller Remount SD Handling #253

Merged
muellerr merged 12 commits from mueller/core-controller-remount-sd-handling into develop 2022-05-25 10:27:10 +02:00
5 changed files with 95 additions and 8 deletions
Showing only changes of commit 5a82fe93d9 - Show all commits

View File

@ -1235,18 +1235,42 @@ void CoreController::performWatchdogControlOperation() {
void CoreController::performMountedSdCardOperations() {
currMntPrefix = sdcMan->getCurrentMountPrefix();
if (doPerformMountedSdCardOps) {
if (performMountedSdCardOpsSwitch) {
bool sdCardMounted = false;
bool mountedReadOnly = false;
ReturnValue_t result = sdcMan->isSdCardMountedReadOnly(sdInfo.pref, mountedReadOnly);
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "CoreController::performMountedSdCardOperations: Could not check "
"read-only mount state" << std::endl;
mountedReadOnly = true;
}
if (mountedReadOnly) {
int linuxErrno = 0;
result = sdcMan->performFsck(sdInfo.pref, true, linuxErrno);
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "CoreController::performMountedSdCardOperations: fsck command on SD Card "
<< sdInfo.prefChar << " failed with code " << linuxErrno << " | " << strerror(linuxErrno);
}
result = sdcMan->remountReadWrite(sdInfo.pref);
if(result == HasReturnvaluesIF::RETURN_OK) {
sif::warning << "CoreController::performMountedSdCardOperations: Remounted SD Card " <<
sdInfo.prefChar << " read-write";
} else {
sif::error << "CoreController::performMountedSdCardOperations: Remounting SD Card " <<
sdInfo.prefChar << " read-write failed";
}
}
sdCardMounted = sdcMan->isSdCardMounted(sdInfo.pref);
if (sdCardMounted) {
std::string path = currMntPrefix + "/" + CONF_FOLDER;
if (not std::filesystem::exists(path)) {
std::filesystem::create_directory(path);
if (sdCardMounted and not performOneShotSdCardOpsSwitch) {
std::ostringstream path;
path << currMntPrefix << "/" << CONF_FOLDER;
if (not std::filesystem::exists(path.str())) {
std::filesystem::create_directory(path.str());
}
initVersionFile();
initClockFromTimeFile();
performRebootFileHandling(false);
doPerformMountedSdCardOps = false;
performOneShotSdCardOpsSwitch = true;
}
}
timeFileHandler();

View File

@ -179,7 +179,8 @@ class CoreController : public ExtendedControllerBase {
} sdInfo;
RebootFile rebootFile = {};
std::string currMntPrefix;
bool doPerformMountedSdCardOps = true;
bool performOneShotSdCardOpsSwitch = true;
bool performMountedSdCardOpsSwitch = true;
/**
* Index 0: Chip 0 Copy 0

View File

@ -466,3 +466,59 @@ bool SdCardManager::isSdCardMounted(sd::SdCard sdCard) {
}
return false;
}
ReturnValue_t SdCardManager::isSdCardMountedReadOnly(sd::SdCard sdcard, bool& readOnly) {
std::ostringstream command;
if(sdcard == sd::SdCard::SLOT_0) {
command << "grep -q \"" << SD_0_DEV_NAME << " vfat ro, \" /proc/mounts";
} else {
command << "grep -q \"" << SD_1_DEV_NAME << " vfat ro, \" /proc/mounts";
}
ReturnValue_t result = cmdExecutor.load(command.str(), true, false);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = cmdExecutor.execute();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
auto& readVec = cmdExecutor.getReadVector();
size_t readLen = strnlen(readVec.data(), readVec.size());
if(readLen == 0) {
readOnly = false;
}
readOnly = true;
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t SdCardManager::remountReadWrite(sd::SdCard sdcard) {
std::ostringstream command;
if(sdcard == sd::SdCard::SLOT_0) {
command << "mount -o remount,rw " << SD_0_DEV_NAME << " " << SD_0_MOUNT_POINT;
} else {
command << "mount -o remount,rw " << SD_1_DEV_NAME << " " << SD_1_MOUNT_POINT;
}
ReturnValue_t result = cmdExecutor.load(command.str(), true, false);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return cmdExecutor.execute();
}
ReturnValue_t SdCardManager::performFsck(sd::SdCard sdcard, bool printOutput, int& linuxError) {
std::ostringstream command;
if(sdcard == sd::SdCard::SLOT_0) {
command << "fsck -y " << SD_0_DEV_NAME;
} else {
command << "fsck -y " << SD_1_DEV_NAME;
}
ReturnValue_t result = cmdExecutor.load(command.str(), true, printOutput);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = cmdExecutor.execute();
if(result != HasReturnvaluesIF::RETURN_OK) {
linuxError = cmdExecutor.getLastError();
}
return result;
}

View File

@ -194,6 +194,12 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
*/
bool isSdCardMounted(sd::SdCard sdCard) override;
ReturnValue_t isSdCardMountedReadOnly(sd::SdCard sdcard, bool& readOnly);
ReturnValue_t remountReadWrite(sd::SdCard sdcard);
ReturnValue_t performFsck(sd::SdCard sdcard, bool printOutput, int& linuxError);
private:
CommandExecutor cmdExecutor;
Operations currentOp = Operations::IDLE;

2
fsfw

@ -1 +1 @@
Subproject commit dafcaa60079ba8e57753d389e6a569ee3eb0b7cb
Subproject commit d1ff32bf968cbf769ca8daa37265af70e050d9c0