From 26adb5e8823fe7095036bd8ea2b7e780a93d04e9 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sun, 21 Jun 2026 18:08:29 +0900 Subject: [PATCH] Linux: retry auto FAT mounts with blkid Keep the historical auto-mount behavior as the first attempt when the user did not request a filesystem type. If that mount fails on Linux, detect the filesystem with blkid and retry only for FAT-family types that minimal mount implementations may not auto-probe. Leave explicit filesystem types and NTFS kernel-driver resolution unchanged. --- src/Core/Unix/CoreUnix.cpp | 48 +++++++++++++++++++++++++++++-- src/Core/Unix/CoreUnix.h | 4 +++ src/Core/Unix/Linux/CoreLinux.cpp | 5 +++- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/Core/Unix/CoreUnix.cpp b/src/Core/Unix/CoreUnix.cpp index 1eb35289..61520d49 100644 --- a/src/Core/Unix/CoreUnix.cpp +++ b/src/Core/Unix/CoreUnix.cpp @@ -989,6 +989,40 @@ namespace VeraCrypt filesystemType = StringConverter::ToWide (SelectNtfsKernelFilesystemType()); internalMountOnly = true; } + + string CoreUnix::DetectLinuxMountFallbackFilesystemType (const DevicePath &devicePath) const + { + string detectedFilesystemType = DetectFilesystemType (devicePath); + + if (detectedFilesystemType == "vfat" || detectedFilesystemType == "exfat" || detectedFilesystemType == "msdos") + return detectedFilesystemType; + + if (detectedFilesystemType == "fat") + return "vfat"; + + return string(); + } + + void CoreUnix::MountFilesystemWithFallback (const DevicePath &devicePath, const DirectoryPath &mountPoint, + const string &filesystemType, bool allowFilesystemTypeFallback, bool readOnly, + const string &systemMountOptions, bool internalMountOnly) const + { + try + { + MountFilesystem (devicePath, mountPoint, filesystemType, readOnly, systemMountOptions, internalMountOnly); + } + catch (ExecutedProcessFailed&) + { + if (!allowFilesystemTypeFallback || !filesystemType.empty() || internalMountOnly) + throw; + + string fallbackFilesystemType = DetectLinuxMountFallbackFilesystemType (devicePath); + if (fallbackFilesystemType.empty()) + throw; + + MountFilesystem (devicePath, mountPoint, fallbackFilesystemType, readOnly, systemMountOptions, false); + } + } #endif void CoreUnix::MountFilesystem (const DevicePath &devicePath, const DirectoryPath &mountPoint, const string &filesystemType, bool readOnly, const string &systemMountOptions, bool internalMountOnly) const @@ -1346,14 +1380,24 @@ namespace VeraCrypt bool internalMountOnly = false; #ifdef TC_LINUX - ResolveNtfsKernelMountOptions (loopDev, options.MountNtfsWithKernelDriver, filesystemType, internalMountOnly); -#endif + bool allowFilesystemTypeFallback = filesystemType.empty(); + ResolveNtfsKernelMountOptions (loopDev, options.MountNtfsWithKernelDriver, filesystemType, internalMountOnly); + allowFilesystemTypeFallback = allowFilesystemTypeFallback && filesystemType.empty() && !internalMountOnly; + + MountFilesystemWithFallback (loopDev, *options.MountPoint, + StringConverter::ToSingle (filesystemType), + allowFilesystemTypeFallback, + options.Protection == VolumeProtection::ReadOnly, + StringConverter::ToSingle (options.FilesystemOptions), + internalMountOnly); +#else MountFilesystem (loopDev, *options.MountPoint, StringConverter::ToSingle (filesystemType), options.Protection == VolumeProtection::ReadOnly, StringConverter::ToSingle (options.FilesystemOptions), internalMountOnly); +#endif } return loopDev; diff --git a/src/Core/Unix/CoreUnix.h b/src/Core/Unix/CoreUnix.h index af5c03c0..a48dfbd6 100644 --- a/src/Core/Unix/CoreUnix.h +++ b/src/Core/Unix/CoreUnix.h @@ -80,6 +80,10 @@ namespace VeraCrypt bool IsFilesystemTypeRegistered (const string &filesystemType) const; bool IsKernelFilesystemTypeAvailable (const string &filesystemType) const; bool IsNtfsReadWriteKernelFilesystemTypeAvailable () const; + string DetectLinuxMountFallbackFilesystemType (const DevicePath &devicePath) const; + void MountFilesystemWithFallback (const DevicePath &devicePath, const DirectoryPath &mountPoint, + const string &filesystemType, bool allowFilesystemTypeFallback, bool readOnly, + const string &systemMountOptions, bool internalMountOnly) const; void ResolveNtfsKernelMountOptions (const DevicePath &devicePath, bool mountNtfsWithKernelDriver, wstring &filesystemType, bool &internalMountOnly) const; string SelectNtfsKernelFilesystemType () const; diff --git a/src/Core/Unix/Linux/CoreLinux.cpp b/src/Core/Unix/Linux/CoreLinux.cpp index f4889cbd..054e665d 100644 --- a/src/Core/Unix/Linux/CoreLinux.cpp +++ b/src/Core/Unix/Linux/CoreLinux.cpp @@ -630,11 +630,14 @@ namespace VeraCrypt { wstring filesystemType = options.FilesystemType; bool internalMountOnly = false; + bool allowFilesystemTypeFallback = filesystemType.empty(); ResolveNtfsKernelMountOptions (nativeDevPath, options.MountNtfsWithKernelDriver, filesystemType, internalMountOnly); + allowFilesystemTypeFallback = allowFilesystemTypeFallback && filesystemType.empty() && !internalMountOnly; - MountFilesystem (nativeDevPath, *options.MountPoint, + MountFilesystemWithFallback (nativeDevPath, *options.MountPoint, StringConverter::ToSingle (filesystemType), + allowFilesystemTypeFallback, options.Protection == VolumeProtection::ReadOnly, StringConverter::ToSingle (options.FilesystemOptions), internalMountOnly);