Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Core/Unix/MacOSX/CoreMacOSX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,36 @@ namespace VeraCrypt

shared_ptr <VolumeInfo> CoreMacOSX::DismountVolume (shared_ptr <VolumeInfo> 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
Expand All @@ -289,6 +319,8 @@ namespace VeraCrypt
try
{
Process::Execute ("/usr/bin/hdiutil", args);


}
catch (ExecutedProcessFailed &e)
{
Expand Down Expand Up @@ -326,6 +358,7 @@ namespace VeraCrypt
try
{
Process::Execute ("/sbin/umount", args);

break;
}
catch (ExecutedProcessFailed&)
Expand Down
11 changes: 11 additions & 0 deletions src/Driver/Fuse/FuseService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down