Only unmounts devices if they were mounted before

This commit is contained in:
Maschell 2022-10-07 14:20:26 +02:00
parent bba4877281
commit 3f0d70cc4c

View File

@ -29,6 +29,7 @@ BackgroundThread *thread = nullptr;
bool gFTPServerEnabled = true; bool gFTPServerEnabled = true;
bool gSystemFilesAllowed = false; bool gSystemFilesAllowed = false;
bool gMochaPathsWereMounted = false;
MochaUtilsStatus MountWrapper(const char *mount, const char *dev, const char *mountTo) { MochaUtilsStatus MountWrapper(const char *mount, const char *dev, const char *mountTo) {
auto res = Mocha_MountFS(mount, dev, mountTo); auto res = Mocha_MountFS(mount, dev, mountTo);
@ -107,6 +108,7 @@ void startServer() {
MountWrapper("storage_slc", "/dev/slc01", "/vol/storage_slc01"); MountWrapper("storage_slc", "/dev/slc01", "/vol/storage_slc01");
Mocha_MountFS("storage_mlc", nullptr, "/vol/storage_mlc01"); Mocha_MountFS("storage_mlc", nullptr, "/vol/storage_mlc01");
Mocha_MountFS("storage_usb", nullptr, "/vol/storage_usb01"); Mocha_MountFS("storage_usb", nullptr, "/vol/storage_usb01");
gMochaPathsWereMounted = true;
} else { } else {
DEBUG_FUNCTION_LINE_ERR("Failed to init libmocha: %s [%d]", Mocha_GetStatusStr(res), res); DEBUG_FUNCTION_LINE_ERR("Failed to init libmocha: %s [%d]", Mocha_GetStatusStr(res), res);
} }
@ -122,7 +124,7 @@ void startServer() {
void stopServer() { void stopServer() {
BackgroundThread::destroyInstance(); BackgroundThread::destroyInstance();
if (gSystemFilesAllowed) { if (gMochaPathsWereMounted) {
Mocha_UnmountFS("slccmpt01"); Mocha_UnmountFS("slccmpt01");
Mocha_UnmountFS("storage_odd_tickets"); Mocha_UnmountFS("storage_odd_tickets");
Mocha_UnmountFS("storage_odd_updates"); Mocha_UnmountFS("storage_odd_updates");
@ -131,6 +133,7 @@ void stopServer() {
Mocha_UnmountFS("storage_slc"); Mocha_UnmountFS("storage_slc");
Mocha_UnmountFS("storage_mlc"); Mocha_UnmountFS("storage_mlc");
Mocha_UnmountFS("storage_usb"); Mocha_UnmountFS("storage_usb");
gMochaPathsWereMounted = false;
} }
DEBUG_FUNCTION_LINE("Unmount virtual paths"); DEBUG_FUNCTION_LINE("Unmount virtual paths");