From ea7489b93bca1476fd485982ebce8a1b11284ae9 Mon Sep 17 00:00:00 2001 From: Jertzukka Date: Mon, 3 Jun 2024 16:57:46 +0300 Subject: FreeBSD: Support automatic detection and mounting of ext2/3/4, exFAT, NTFS filesystems (#1350) --- src/Core/Unix/FreeBSD/CoreFreeBSD.cpp | 47 ++++++++++++++++++++++++++++++++--- src/Main/CommandLineInterface.cpp | 10 ++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Core/Unix/FreeBSD/CoreFreeBSD.cpp b/src/Core/Unix/FreeBSD/CoreFreeBSD.cpp index 01463c35..05520274 100644 --- a/src/Core/Unix/FreeBSD/CoreFreeBSD.cpp +++ b/src/Core/Unix/FreeBSD/CoreFreeBSD.cpp @@ -83,7 +83,7 @@ namespace VeraCrypt #ifdef TC_MACOSX const string busType = "rdisk"; #else - foreach (const string &busType, StringConverter::Split ("ad da")) + foreach (const string &busType, StringConverter::Split ("ad da vtbd")) #endif { for (int devNumber = 0; devNumber < 64; devNumber++) @@ -185,10 +185,51 @@ namespace VeraCrypt void CoreFreeBSD::MountFilesystem (const DevicePath &devicePath, const DirectoryPath &mountPoint, const string &filesystemType, bool readOnly, const string &systemMountOptions) const { + std::string chosenFilesystem = "msdos"; + std::string modifiedMountOptions = systemMountOptions; + + if (filesystemType.empty() && modifiedMountOptions.find("mountprog") == string::npos) { + // No filesystem type specified through CLI, attempt to identify with blkid + // as mount is unable to probe filesystem type on BSD + // Make sure we don't override user defined mountprog + std::vector buffer(128,0); + std::string cmd = "blkid -o value -s TYPE " + static_cast(devicePath) + " 2>/dev/null"; + std::string result; + + FILE* pipe = popen(cmd.c_str(), "r"); + if (pipe) { + while (!feof(pipe)) { + if (fgets(buffer.data(), 128, pipe) != nullptr) + result += buffer.data(); + } + fflush(pipe); + pclose(pipe); + pipe = nullptr; + } + + if (result.find("ext") == 0 || StringConverter::ToLower(filesystemType).find("ext") == 0) { + chosenFilesystem = "ext2fs"; + } + else if (result.find("exfat") == 0 || StringConverter::ToLower(filesystemType) == "exfat") { + chosenFilesystem = "exfat"; + modifiedMountOptions += string(!systemMountOptions.empty() ? "," : "") + + "mountprog=/usr/local/sbin/mount.exfat"; + } + else if (result.find("ntfs") == 0 || StringConverter::ToLower(filesystemType) == "ntfs") { + chosenFilesystem = "ntfs"; + modifiedMountOptions += string(!systemMountOptions.empty() ? "," : "") + + "mountprog=/usr/local/bin/ntfs-3g"; + } + else if (!filesystemType.empty()) { + // Filesystem is specified but is none of the above, then supply as is + chosenFilesystem = filesystemType; + } + } else + chosenFilesystem = filesystemType; + try { - // Try to mount FAT by default as mount is unable to probe filesystem type on BSD - CoreUnix::MountFilesystem (devicePath, mountPoint, filesystemType.empty() ? "msdos" : filesystemType, readOnly, systemMountOptions); + CoreUnix::MountFilesystem (devicePath, mountPoint, chosenFilesystem, readOnly, modifiedMountOptions); } catch (ExecutedProcessFailed&) { diff --git a/src/Main/CommandLineInterface.cpp b/src/Main/CommandLineInterface.cpp index 2bbc73ea..17d7c147 100644 --- a/src/Main/CommandLineInterface.cpp +++ b/src/Main/CommandLineInterface.cpp @@ -347,6 +347,16 @@ namespace VeraCrypt #elif defined (TC_FREEBSD) || defined (TC_SOLARIS) else if (str.IsSameAs (L"UFS", false)) ArgFilesystem = VolumeCreationOptions::FilesystemType::UFS; + else if (str.IsSameAs (L"Ext2", false)) + ArgFilesystem = VolumeCreationOptions::FilesystemType::Ext2; + else if (str.IsSameAs (L"Ext3", false)) + ArgFilesystem = VolumeCreationOptions::FilesystemType::Ext3; + else if (str.IsSameAs (L"Ext4", false)) + ArgFilesystem = VolumeCreationOptions::FilesystemType::Ext4; + else if (str.IsSameAs (L"NTFS", false)) + ArgFilesystem = VolumeCreationOptions::FilesystemType::NTFS; + else if (str.IsSameAs (L"exFAT", false)) + ArgFilesystem = VolumeCreationOptions::FilesystemType::exFAT; #endif else throw_err (LangString["UNKNOWN_OPTION"] + L": " + str); -- cgit v1.2.3