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

Linux: Add support for Btrfs filesystem when creating volumes

This commit is contained in:
Mounir IDRASSI
2020-08-05 02:05:18 +02:00
parent c8b501062d
commit 388e44c809
5 changed files with 90 additions and 41 deletions

View File

@@ -16,6 +16,11 @@
#include "Platform/Platform.h"
#include "Volume/Volume.h"
#include "RandomNumberGenerator.h"
#if defined (TC_LINUX)
#include "Platform/Unix/Process.h"
#endif
#define VC_MIN_BTRFS_VOLUME_SIZE 114294784ULL
namespace VeraCrypt
{
@@ -44,6 +49,7 @@ namespace VeraCrypt
Ext2,
Ext3,
Ext4,
Btrfs,
MacOsExt,
APFS,
UFS
@@ -63,6 +69,55 @@ namespace VeraCrypt
return VolumeCreationOptions::FilesystemType::FAT;
#endif
}
static const char* GetFsFormatter (VolumeCreationOptions::FilesystemType::Enum fsType)
{
switch (fsType)
{
#if defined (TC_LINUX)
case VolumeCreationOptions::FilesystemType::Ext2: return "mkfs.ext2";
case VolumeCreationOptions::FilesystemType::Ext3: return "mkfs.ext3";
case VolumeCreationOptions::FilesystemType::Ext4: return "mkfs.ext4";
case VolumeCreationOptions::FilesystemType::NTFS: return "mkfs.ntfs";
case VolumeCreationOptions::FilesystemType::exFAT: return "mkfs.exfat";
case VolumeCreationOptions::FilesystemType::Btrfs: return "mkfs.btrfs";
#elif defined (TC_MACOSX)
case VolumeCreationOptions::FilesystemType::MacOsExt: return "newfs_hfs";
case VolumeCreationOptions::FilesystemType::exFAT: return "newfs_exfat";
case VolumeCreationOptions::FilesystemType::APFS: return "newfs_apfs";
#elif defined (TC_FREEBSD) || defined (TC_SOLARIS)
case VolumeCreationOptions::FilesystemType::UFS: return "newfs" ;
#endif
default: return NULL;
}
}
static bool IsFsFormatterPresent (VolumeCreationOptions::FilesystemType::Enum fsType)
{
bool bRet = false;
const char* fsFormatter = GetFsFormatter (fsType);
if (fsFormatter)
{
#if defined (TC_LINUX)
try
{
list <string> args;
args.push_back ("-V");
Process::Execute (fsFormatter, args);
bRet = true;
}
catch (exception &e)
{
}
#else
bRet = true;
#endif
}
return bRet;
}
};
FilesystemType::Enum Filesystem;