OpenBSD: add FFS volume formatting support

Expose FFS as the native OpenBSD filesystem option for volume creation and accept FFS/UFS on the command line, mapping mounts to the OpenBSD ffs filesystem type.

Run newfs through the elevated core service on vnd raw devices, then temporarily mount the new filesystem to transfer root directory ownership back to the invoking user.

Keep the non-interactive creation default as FAT on OpenBSD so existing unattended scripts do not start requiring elevation.
This commit is contained in:
Mounir IDRASSI committed 2026-07-06 17:11:24 +09:00
1 parent ede12bf81c
commit 48f8d87418
13 files changed
+471 -25

No files matched your search

+39 -12
View File
@@ -29,6 +29,9 @@
#ifdef TC_MACOSX
#include "Main/MacOSXFormatterDevice.h"
#endif
#ifdef TC_OPENBSD
#include "Main/OpenBSDFormatterDevice.h"
#endif
#include "TextUserInterface.h"
namespace VeraCrypt
@@ -933,7 +936,13 @@ namespace VeraCrypt
{
if (Preferences.NonInteractive)
{
#ifdef TC_OPENBSD
// Preserve the historical OpenBSD batch default. Native FFS
// formatting requires elevation, so scripts should opt in.
options->Filesystem = VolumeCreationOptions::FilesystemType::FAT;
#else
options->Filesystem = VolumeCreationOptions::FilesystemType::GetPlatformNative();
#endif
}
else
{
@@ -974,6 +983,8 @@ namespace VeraCrypt
}
#elif defined (TC_FREEBSD) || defined (TC_SOLARIS)
ShowInfo (wxString::Format (L" %li) %s", filesystems.size() + 1, "UFS")); filesystems.push_back (VolumeCreationOptions::FilesystemType::UFS);
#elif defined (TC_OPENBSD)
ShowInfo (wxString::Format (L" %li) %s", filesystems.size() + 1, "FFS")); filesystems.push_back (VolumeCreationOptions::FilesystemType::FFS);
#endif
ssize_t defaultFilesystem = fatAvailable ? 2 : 1;
@@ -1123,9 +1134,11 @@ namespace VeraCrypt
// Temporarily take ownership of the device if the user is not an administrator
DevicePath virtualDevice = volume->VirtualDevice;
DevicePath formatterDevice = virtualDevice;
#ifdef TC_MACOSX
string virtualDeviceStr = virtualDevice;
virtualDevice = GetMacOSXRawDevicePath (virtualDeviceStr);
formatterDevice = virtualDevice;
MacOSXFormatterDeviceOwnerRestoreList changedDeviceOwners;
finally_do_arg (MacOSXFormatterDeviceOwnerRestoreList *, &changedDeviceOwners,
@@ -1134,25 +1147,37 @@ namespace VeraCrypt
});
bool useElevatedAPFSFormatter = UseElevatedMacOSXAPFSFormatter (fsFormatter);
if (!useElevatedAPFSFormatter)
PrepareMacOSXFormatterDevice (virtualDevice, changedDeviceOwners);
PrepareMacOSXFormatterDevice (formatterDevice, changedDeviceOwners);
#else
#ifdef TC_OPENBSD
if (options->Filesystem == VolumeCreationOptions::FilesystemType::FFS)
formatterDevice = GetOpenBSDRawFormatterDevicePath (virtualDevice);
#endif
bool prepareFormatterDeviceOwnership = true;
#ifdef TC_OPENBSD
if (options->Filesystem == VolumeCreationOptions::FilesystemType::FFS)
prepareFormatterDeviceOwnership = false;
#endif
UserId origDeviceOwner ((uid_t) -1);
try
if (prepareFormatterDeviceOwnership)
{
File file;
file.Open (virtualDevice, File::OpenReadWrite);
}
catch (...)
{
if (!Core->HasAdminPrivileges())
try
{
origDeviceOwner = virtualDevice.GetOwner();
Core->SetFileOwner (virtualDevice, UserId (getuid()));
File file;
file.Open (formatterDevice, File::OpenReadWrite);
}
catch (...)
{
if (!Core->HasAdminPrivileges())
{
origDeviceOwner = formatterDevice.GetOwner();
Core->SetFileOwner (formatterDevice, UserId (getuid()));
}
}
}
finally_do_arg2 (FilesystemPath, virtualDevice, UserId, origDeviceOwner,
finally_do_arg2 (FilesystemPath, formatterDevice, UserId, origDeviceOwner,
{
if (finally_arg2.SystemId != (uid_t) -1)
Core->SetFileOwner (finally_arg, finally_arg2);
@@ -1187,10 +1212,12 @@ namespace VeraCrypt
AddMacOSXAPFSFormatterUserArgs (args);
#endif
args.push_back (string (virtualDevice));
args.push_back (string (formatterDevice));
#ifdef TC_MACOSX
ExecuteMacOSXFilesystemFormatter (fsFormatter, args);
#elif defined (TC_OPENBSD)
ExecuteOpenBSDFilesystemFormatter (fsFormatter, args);
#else
Process::Execute (fsFormatter, args);
#endif