Linux/MacOSX: Allow choosing a filesystem other than FAT for outer volume but display warning about risks and implement an estimation of maximum possible size of hidden volume in this case.

This commit is contained in:
Mounir IDRASSI 2020-07-01 00:56:57 +02:00
parent 2ca867ef5d
commit 5f04e5abd0
No known key found for this signature in database
GPG Key ID: 02C30AE90FAE4A6F
1 changed files with 43 additions and 19 deletions

View File

@ -14,6 +14,7 @@
#include "Platform/SystemInfo.h"
#ifdef TC_UNIX
#include <unistd.h>
#include <sys/statvfs.h> // header for statvfs
#include "Platform/Unix/Process.h"
#endif
#include "Core/RandomNumberGenerator.h"
@ -822,15 +823,6 @@ namespace VeraCrypt
}
}
// Skip PIM
if (forward && OuterVolume)
{
// Use FAT to prevent problems with free space
QuickFormatEnabled = false;
SelectedFilesystemType = VolumeCreationOptions::FilesystemType::FAT;
return Step::CreationProgress;
}
if (VolumeSize > 4 * BYTES_PER_GB)
{
if (VolumeSize <= TC_MAX_FAT_SECTOR_COUNT * SectorSize)
@ -901,15 +893,6 @@ namespace VeraCrypt
}
}
if (forward && OuterVolume)
{
// Use FAT to prevent problems with free space
QuickFormatEnabled = false;
SelectedFilesystemType = VolumeCreationOptions::FilesystemType::FAT;
return Step::CreationProgress;
}
if (VolumeSize > 4 * BYTES_PER_GB)
{
if (VolumeSize <= TC_MAX_FAT_SECTOR_COUNT * SectorSize)
@ -945,6 +928,22 @@ namespace VeraCrypt
case Step::FormatOptions:
{
VolumeFormatOptionsWizardPage *page = dynamic_cast <VolumeFormatOptionsWizardPage *> (GetCurrentPage());
if (forward && OuterVolume)
{
if (page->GetFilesystemType() != VolumeCreationOptions::FilesystemType::FAT)
{
if (!Gui->AskYesNo (_("WARNING: You have selected a filesystem other than FAT for the outer volume.\n"
"Please Note that in this case VeraCrypt can't calculate the exact maximum allowed size for the hidden volume and it will use only an estimation that can be wrong.\n"
"Thus, it is your responsibility to use an adequate value for the size of the hidden volume so that it doesn\'t overlap the outer volume.\n\n"
"Do you want to continue using the selected filesystem for the outer volume?")
, false, true))
{
return GetCurrentStep();
}
}
}
SelectedFilesystemType = page->GetFilesystemType();
QuickFormatEnabled = page->IsQuickFormatEnabled();
@ -1098,12 +1097,23 @@ namespace VeraCrypt
// require using FUSE and loop device which cannot be used for devices with sectors larger than 512.
wxBusyCursor busy;
bool outerVolumeAvailableSpaceValid = false;
uint64 outerVolumeAvailableSpace = 0;
MaxHiddenVolumeSize = 0;
Gui->SetActiveFrame (this);
if (MountedOuterVolume)
{
#ifdef TC_UNIX
const DirectoryPath &outerVolumeMountPoint = MountedOuterVolume->MountPoint;
struct statvfs stat;
if (statvfs(((string)outerVolumeMountPoint).c_str(), &stat) == 0)
{
outerVolumeAvailableSpace = (uint64) stat.f_bsize * (uint64) stat.f_bavail;
outerVolumeAvailableSpaceValid = true;
}
#endif
Core->DismountVolume (MountedOuterVolume);
MountedOuterVolume.reset();
}
@ -1126,7 +1136,21 @@ namespace VeraCrypt
#endif
shared_ptr <Volume> outerVolume = Core->OpenVolume (make_shared <VolumePath> (SelectedVolumePath), true, Password, Pim, Kdf, false, Keyfiles, VolumeProtection::ReadOnly);
MaxHiddenVolumeSize = Core->GetMaxHiddenVolumeSize (outerVolume);
try
{
MaxHiddenVolumeSize = Core->GetMaxHiddenVolumeSize (outerVolume);
}
catch (ParameterIncorrect& )
{
// Outer volume not using FAT
// estimate maximum hidden volume size as 80% of available size of outer volume
if (outerVolumeAvailableSpaceValid)
{
MaxHiddenVolumeSize =(4ULL * outerVolumeAvailableSpace) / 5ULL;
}
else
throw;
}
// Add a reserve (in case the user mounts the outer volume and creates new files
// on it by accident or OS writes some new data behind his or her back, such as