From ecd3a5689751c35cad571b52fe13aafece6b81bb Mon Sep 17 00:00:00 2001 From: askaine Date: Tue, 15 Sep 2026 09:47:36 +0300 Subject: [PATCH] Issue #1872 fix - FUSE-T usb stick unmounting --- src/Core/Unix/MacOSX/CoreMacOSX.cpp | 33 +++++++++++++++++++++++++++++ src/Driver/Fuse/FuseService.cpp | 11 ++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/Core/Unix/MacOSX/CoreMacOSX.cpp b/src/Core/Unix/MacOSX/CoreMacOSX.cpp index aeff76ec3d..2ac031d4b9 100644 --- a/src/Core/Unix/MacOSX/CoreMacOSX.cpp +++ b/src/Core/Unix/MacOSX/CoreMacOSX.cpp @@ -268,6 +268,36 @@ namespace VeraCrypt shared_ptr CoreMacOSX::DismountVolume (shared_ptr mountedVolume, bool ignoreOpenFiles, bool syncVolumeInfo) { + mountedVolume = CoreUnix::DismountVolume(mountedVolume, ignoreOpenFiles, syncVolumeInfo); + + +#ifdef VC_MACOSX_FUSET + // FUSE-T bug workaround: Forcefully terminate the FUSE-T daemon process before + // calling hdiutil detach. If left alive, it holds an open handle on the virtual device, + // causing hdiutil detach to throw a "resource busy" exception. + std::string pidFilePath = "/tmp/veracrypt_fuset_slot_" + std::to_string(mountedVolume->SlotNumber) + ".pid"; + FILE* pidFile = fopen(pidFilePath.c_str(), "r"); + if (pidFile) + { + pid_t fusePid = 0; + if (fscanf(pidFile, "%d", &fusePid) == 1 && fusePid > 0) + { + if (kill(fusePid, 0) == 0) + { + kill(fusePid, SIGTERM); + usleep(200000); + + if (kill(fusePid, 0) == 0) + { + kill(fusePid, SIGKILL); + } + } + } + fclose(pidFile); + unlink(pidFilePath.c_str()); + } +#endif + if (!mountedVolume->AuxMountPoint.IsEmpty()) { try @@ -289,6 +319,8 @@ namespace VeraCrypt try { Process::Execute ("/usr/bin/hdiutil", args); + + } catch (ExecutedProcessFailed &e) { @@ -326,6 +358,7 @@ namespace VeraCrypt try { Process::Execute ("/sbin/umount", args); + break; } catch (ExecutedProcessFailed&) diff --git a/src/Driver/Fuse/FuseService.cpp b/src/Driver/Fuse/FuseService.cpp index d1cc507be6..38a3dfe525 100644 --- a/src/Driver/Fuse/FuseService.cpp +++ b/src/Driver/Fuse/FuseService.cpp @@ -846,6 +846,17 @@ namespace VeraCrypt SignalHandlerPipe->GetWriteFD(); +#ifdef VC_MACOSX_FUSET + // FUSE-T bug workaround: Save PID so DismountVolume can forcefully terminate later + std::string pidFilePath = "/tmp/veracrypt_fuset_slot_" + std::to_string(FuseService::SlotNumber) + ".pid"; + FILE* pidFile = fopen(pidFilePath.c_str(), "w"); + if (pidFile) + { + fprintf(pidFile, "%d\n", getpid()); + fclose(pidFile); + } +#endif + #ifdef VC_FUSE3 _exit (fuse_main (argc, argv, &fuse_service_oper, nullptr)); #elif defined(TC_OPENBSD)