Core Controller Remount SD Handling #253
@ -1235,18 +1235,42 @@ void CoreController::performWatchdogControlOperation() {
|
|||||||
|
|
||||||
void CoreController::performMountedSdCardOperations() {
|
void CoreController::performMountedSdCardOperations() {
|
||||||
currMntPrefix = sdcMan->getCurrentMountPrefix();
|
currMntPrefix = sdcMan->getCurrentMountPrefix();
|
||||||
if (doPerformMountedSdCardOps) {
|
if (performMountedSdCardOpsSwitch) {
|
||||||
bool sdCardMounted = false;
|
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);
|
sdCardMounted = sdcMan->isSdCardMounted(sdInfo.pref);
|
||||||
if (sdCardMounted) {
|
if (sdCardMounted and not performOneShotSdCardOpsSwitch) {
|
||||||
std::string path = currMntPrefix + "/" + CONF_FOLDER;
|
std::ostringstream path;
|
||||||
if (not std::filesystem::exists(path)) {
|
path << currMntPrefix << "/" << CONF_FOLDER;
|
||||||
std::filesystem::create_directory(path);
|
if (not std::filesystem::exists(path.str())) {
|
||||||
|
std::filesystem::create_directory(path.str());
|
||||||
}
|
}
|
||||||
initVersionFile();
|
initVersionFile();
|
||||||
initClockFromTimeFile();
|
initClockFromTimeFile();
|
||||||
performRebootFileHandling(false);
|
performRebootFileHandling(false);
|
||||||
doPerformMountedSdCardOps = false;
|
performOneShotSdCardOpsSwitch = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
timeFileHandler();
|
timeFileHandler();
|
||||||
|
@ -179,7 +179,8 @@ class CoreController : public ExtendedControllerBase {
|
|||||||
} sdInfo;
|
} sdInfo;
|
||||||
RebootFile rebootFile = {};
|
RebootFile rebootFile = {};
|
||||||
std::string currMntPrefix;
|
std::string currMntPrefix;
|
||||||
bool doPerformMountedSdCardOps = true;
|
bool performOneShotSdCardOpsSwitch = true;
|
||||||
|
bool performMountedSdCardOpsSwitch = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Index 0: Chip 0 Copy 0
|
* Index 0: Chip 0 Copy 0
|
||||||
|
@ -466,3 +466,59 @@ bool SdCardManager::isSdCardMounted(sd::SdCard sdCard) {
|
|||||||
}
|
}
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
@ -194,6 +194,12 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
|
|||||||
*/
|
*/
|
||||||
bool isSdCardMounted(sd::SdCard sdCard) override;
|
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:
|
private:
|
||||||
CommandExecutor cmdExecutor;
|
CommandExecutor cmdExecutor;
|
||||||
Operations currentOp = Operations::IDLE;
|
Operations currentOp = Operations::IDLE;
|
||||||
|
2
fsfw
2
fsfw
@ -1 +1 @@
|
|||||||
Subproject commit dafcaa60079ba8e57753d389e6a569ee3eb0b7cb
|
Subproject commit d1ff32bf968cbf769ca8daa37265af70e050d9c0
|
Loading…
Reference in New Issue
Block a user