Any Marlin experts here? Trying to figure out how to make SD card auto-remount work

I have one remaining annoyance with this printer. I’m using an extension cable for my SD card, and that means every time I swap a card I need to power-cycle the printer.

I am messing up with the source code (specifically the fork created by smkent, GitHub - smkent/sovol-sv06-plus-firmware: A fork of Sovol's Marlin firmware for the SV06 Plus 3D printer). I am trying to modify it so when I click on a “Print from file” icon, it would auto-remount the SD card. I think I am getting close, but still not fully functional. What I did was I placed the following lines inside the LCD_RTS.cpp file, right after the line “case SelectFileKey:” (I also tried “case PrintFileKey:”):

if (!IS_SD_PRINTING())
{
RTS_SDCardInit();
delay(100);
}

It kind of works, but the file names get garbled (if the new name is shorter than the old one, I see the new name, then the leftover from the old name). Also it doesn’t seem to work every time.

Anyone knows how to do this properly?

Of course, ideally I’d love to have a separate GUI button “Refresh the card”, but that would be much more work.

…and no, I am not planning to install Octoprint for a variety of reasons.

Personally, I removed Octoprint for using a Beagle camera. Much simpler and almost as many features.
With this camera. SD cards are useless.