1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 11:08:02 -06:00

FreeBSD: Support automatic detection and mounting of ext2/3/4, exFAT, NTFS filesystems (#1350)

This commit is contained in:
Jertzukka
2024-06-03 16:57:46 +03:00
committed by GitHub
parent bd1e772657
commit ea7489b93b
2 changed files with 54 additions and 3 deletions

View File

@@ -83,7 +83,7 @@ namespace VeraCrypt
#ifdef TC_MACOSX #ifdef TC_MACOSX
const string busType = "rdisk"; const string busType = "rdisk";
#else #else
foreach (const string &busType, StringConverter::Split ("ad da")) foreach (const string &busType, StringConverter::Split ("ad da vtbd"))
#endif #endif
{ {
for (int devNumber = 0; devNumber < 64; devNumber++) 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 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<char> buffer(128,0);
std::string cmd = "blkid -o value -s TYPE " + static_cast<std::string>(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
{ {
// Try to mount FAT by default as mount is unable to probe filesystem type on BSD CoreUnix::MountFilesystem (devicePath, mountPoint, chosenFilesystem, readOnly, modifiedMountOptions);
CoreUnix::MountFilesystem (devicePath, mountPoint, filesystemType.empty() ? "msdos" : filesystemType, readOnly, systemMountOptions);
} }
catch (ExecutedProcessFailed&) catch (ExecutedProcessFailed&)
{ {

View File

@@ -347,6 +347,16 @@ namespace VeraCrypt
#elif defined (TC_FREEBSD) || defined (TC_SOLARIS) #elif defined (TC_FREEBSD) || defined (TC_SOLARIS)
else if (str.IsSameAs (L"UFS", false)) else if (str.IsSameAs (L"UFS", false))
ArgFilesystem = VolumeCreationOptions::FilesystemType::UFS; 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 #endif
else else
throw_err (LangString["UNKNOWN_OPTION"] + L": " + str); throw_err (LangString["UNKNOWN_OPTION"] + L": " + str);