From 1fb59b58ee9ec9215880dfa218d709fae02f6a53 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Wed, 26 Aug 2020 08:28:37 +0200 Subject: Linux: Reduce minimal size requirement for BTRFS support to 16 MiB by using mixed mode for volumes whose size is less than 109 MiB --- src/Main/Forms/VolumeCreationWizard.cpp | 15 ++++++++++++++- src/Main/Forms/VolumeFormatOptionsWizardPage.cpp | 11 +++++------ src/Main/Forms/VolumeFormatOptionsWizardPage.h | 2 +- src/Main/TextUserInterface.cpp | 9 ++++++++- 4 files changed, 28 insertions(+), 9 deletions(-) (limited to 'src/Main') diff --git a/src/Main/Forms/VolumeCreationWizard.cpp b/src/Main/Forms/VolumeCreationWizard.cpp index 4df20301..5d814e89 100644 --- a/src/Main/Forms/VolumeCreationWizard.cpp +++ b/src/Main/Forms/VolumeCreationWizard.cpp @@ -258,7 +258,10 @@ namespace VeraCrypt case Step::FormatOptions: { - VolumeFormatOptionsWizardPage *page = new VolumeFormatOptionsWizardPage (GetPageParent(), VolumeSize, SectorSize, + shared_ptr layout ((OuterVolume || SelectedVolumeType != VolumeType::Hidden)? (VolumeLayout*) new VolumeLayoutV2Normal() : (VolumeLayout*) new VolumeLayoutV2Hidden()); + uint64 filesystemSize = layout->GetMaxDataSize (VolumeSize); + + VolumeFormatOptionsWizardPage *page = new VolumeFormatOptionsWizardPage (GetPageParent(), filesystemSize, SectorSize, SelectedVolumePath.IsDevice() && (OuterVolume || SelectedVolumeType != VolumeType::Hidden), OuterVolume, LargeFilesSupport); page->SetPageTitle (_("Format Options")); @@ -484,6 +487,9 @@ namespace VeraCrypt shared_ptr volume = Core->MountVolume (mountOptions); finally_do_arg (shared_ptr , volume, { Core->DismountVolume (finally_arg, true); }); + + shared_ptr layout((volume->Type == VolumeType::Normal)? (VolumeLayout*) new VolumeLayoutV2Normal() : (VolumeLayout*) new VolumeLayoutV2Hidden()); + uint64 filesystemSize = layout->GetMaxDataSize (VolumeSize); Thread::Sleep (2000); // Try to prevent race conditions caused by OS @@ -527,7 +533,14 @@ namespace VeraCrypt args.push_back ("-f"); if (SelectedFilesystemType == VolumeCreationOptions::FilesystemType::Btrfs) + { args.push_back ("-f"); + if (filesystemSize < VC_MIN_LARGE_BTRFS_VOLUME_SIZE) + { + // use mixed mode for small BTRFS volumes + args.push_back ("-M"); + } + } args.push_back (string (virtualDevice)); diff --git a/src/Main/Forms/VolumeFormatOptionsWizardPage.cpp b/src/Main/Forms/VolumeFormatOptionsWizardPage.cpp index 30f8c6ba..d3bd5216 100644 --- a/src/Main/Forms/VolumeFormatOptionsWizardPage.cpp +++ b/src/Main/Forms/VolumeFormatOptionsWizardPage.cpp @@ -17,7 +17,7 @@ namespace VeraCrypt { - VolumeFormatOptionsWizardPage::VolumeFormatOptionsWizardPage (wxPanel* parent, uint64 volumeSize, uint32 sectorSize, bool enableQuickFormatButton, bool disableNoneFilesystem, bool disable32bitFilesystems) + VolumeFormatOptionsWizardPage::VolumeFormatOptionsWizardPage (wxPanel* parent, uint64 filesystemSize, uint32 sectorSize, bool enableQuickFormatButton, bool disableNoneFilesystem, bool disable32bitFilesystems) : VolumeFormatOptionsWizardPageBase (parent) { InfoStaticText->SetLabel (_( @@ -26,7 +26,7 @@ namespace VeraCrypt if (!disableNoneFilesystem) FilesystemTypeChoice->Append (LangString["NONE"], (void *) VolumeCreationOptions::FilesystemType::None); - if (!disable32bitFilesystems && volumeSize <= TC_MAX_FAT_SECTOR_COUNT * sectorSize) + if (!disable32bitFilesystems && filesystemSize <= TC_MAX_FAT_SECTOR_COUNT * sectorSize) FilesystemTypeChoice->Append (L"FAT", (void *) VolumeCreationOptions::FilesystemType::FAT); #ifdef TC_WINDOWS @@ -43,9 +43,8 @@ namespace VeraCrypt FilesystemTypeChoice->Append (L"exFAT", (void *) VolumeCreationOptions::FilesystemType::exFAT); if (VolumeCreationOptions::FilesystemType::IsFsFormatterPresent (VolumeCreationOptions::FilesystemType::Btrfs)) { - uint64 minVolumeSizeForBtrfs = VC_MIN_BTRFS_VOLUME_SIZE + (uint64) (VC_MAX (TC_TOTAL_VOLUME_HEADERS_SIZE, TC_HIDDEN_VOLUME_HOST_FS_RESERVED_END_AREA_SIZE_HIGH)); - // minimum size to be able to format as Btrfs is 114294784 bytes - if (volumeSize >= minVolumeSizeForBtrfs) + // minimum size to be able to format as Btrfs is 16777216 bytes + if (filesystemSize >= VC_MIN_SMALL_BTRFS_VOLUME_SIZE) FilesystemTypeChoice->Append (L"Btrfs", (void *) VolumeCreationOptions::FilesystemType::Btrfs); } #elif defined (TC_MACOSX) @@ -57,7 +56,7 @@ namespace VeraCrypt FilesystemTypeChoice->Append (L"UFS", (void *) VolumeCreationOptions::FilesystemType::UFS); #endif - if (!disable32bitFilesystems && volumeSize <= TC_MAX_FAT_SECTOR_COUNT * sectorSize) + if (!disable32bitFilesystems && filesystemSize <= TC_MAX_FAT_SECTOR_COUNT * sectorSize) SetFilesystemType (VolumeCreationOptions::FilesystemType::FAT); else SetFilesystemType (VolumeCreationOptions::FilesystemType::GetPlatformNative()); diff --git a/src/Main/Forms/VolumeFormatOptionsWizardPage.h b/src/Main/Forms/VolumeFormatOptionsWizardPage.h index 25ca2b37..b38f6e99 100644 --- a/src/Main/Forms/VolumeFormatOptionsWizardPage.h +++ b/src/Main/Forms/VolumeFormatOptionsWizardPage.h @@ -21,7 +21,7 @@ namespace VeraCrypt class VolumeFormatOptionsWizardPage : public VolumeFormatOptionsWizardPageBase { public: - VolumeFormatOptionsWizardPage (wxPanel* parent, uint64 volumeSize, uint32 sectorSize, bool enableQuickFormatButton = true, bool disableNoneFilesystem = false, bool disable32bitFilesystems = false); + VolumeFormatOptionsWizardPage (wxPanel* parent, uint64 filesystemSize, uint32 sectorSize, bool enableQuickFormatButton = true, bool disableNoneFilesystem = false, bool disable32bitFilesystems = false); VolumeCreationOptions::FilesystemType::Enum GetFilesystemType () const; bool IsValid () { return true; } diff --git a/src/Main/TextUserInterface.cpp b/src/Main/TextUserInterface.cpp index 95becfdf..0ad0b958 100644 --- a/src/Main/TextUserInterface.cpp +++ b/src/Main/TextUserInterface.cpp @@ -810,7 +810,7 @@ namespace VeraCrypt } if (options->Filesystem == VolumeCreationOptions::FilesystemType::Btrfs - && (filesystemSize < VC_MIN_BTRFS_VOLUME_SIZE)) + && (filesystemSize < VC_MIN_SMALL_BTRFS_VOLUME_SIZE)) { throw_err (_("Specified volume size is too small to be used with Btrfs filesystem.")); } @@ -939,7 +939,14 @@ namespace VeraCrypt args.push_back ("-f"); if (options->Filesystem == VolumeCreationOptions::FilesystemType::Btrfs) + { args.push_back ("-f"); + if (filesystemSize < VC_MIN_LARGE_BTRFS_VOLUME_SIZE) + { + // use mixed mode for small BTRFS volumes + args.push_back ("-M"); + } + } args.push_back (string (virtualDevice)); -- cgit v1.2.3