From cfd54af70070dfef30dd783eb3e4bb9d82f83e0c Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Thu, 28 May 2026 12:43:09 +0200 Subject: [PATCH] macOS: force fresh exFAT layout when formatting volumes Pass -R to newfs_exfat in both GUI and text-mode volume creation so macOS derives a fresh exFAT layout instead of preserving stale geometry from an existing exFAT boot region. This matches Finder/Disk Utility erase behavior. Validated on Windows 11: chkdsk no longer reports boot-region corruption on volumes formatted this way. Fixes #1021. --- src/Main/Forms/VolumeCreationWizard.cpp | 3 +++ src/Main/MacOSXFormatterDevice.h | 21 ++++++++++++++++++--- src/Main/TextUserInterface.cpp | 3 +++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Main/Forms/VolumeCreationWizard.cpp b/src/Main/Forms/VolumeCreationWizard.cpp index 9f50d258..6f1001e6 100644 --- a/src/Main/Forms/VolumeCreationWizard.cpp +++ b/src/Main/Forms/VolumeCreationWizard.cpp @@ -907,6 +907,9 @@ namespace VeraCrypt } #ifdef TC_MACOSX + if (IsMacOSXExFATFormatter (fsFormatter)) + AddMacOSXExFATFormatterArgs (args); + if (IsMacOSXAPFSFormatter (fsFormatter) && !useElevatedAPFSFormatter) AddMacOSXAPFSFormatterUserArgs (args); #endif diff --git a/src/Main/MacOSXFormatterDevice.h b/src/Main/MacOSXFormatterDevice.h index d09337a3..a62898f6 100644 --- a/src/Main/MacOSXFormatterDevice.h +++ b/src/Main/MacOSXFormatterDevice.h @@ -61,11 +61,20 @@ namespace VeraCrypt return deviceIdentifier; } - inline bool IsMacOSXAPFSFormatter (const string &fsFormatter) + inline string GetMacOSXFormatterName (const string &fsFormatter) { size_t namePos = fsFormatter.find_last_of ('/'); - string fsFormatterName = namePos == string::npos ? fsFormatter : fsFormatter.substr (namePos + 1); - return fsFormatterName == "newfs_apfs"; + return namePos == string::npos ? fsFormatter : fsFormatter.substr (namePos + 1); + } + + inline bool IsMacOSXAPFSFormatter (const string &fsFormatter) + { + return GetMacOSXFormatterName (fsFormatter) == "newfs_apfs"; + } + + inline bool IsMacOSXExFATFormatter (const string &fsFormatter) + { + return GetMacOSXFormatterName (fsFormatter) == "newfs_exfat"; } inline bool UseElevatedMacOSXAPFSFormatter (const string &fsFormatter) @@ -88,6 +97,12 @@ namespace VeraCrypt args.push_back (gid.str()); } + inline void AddMacOSXExFATFormatterArgs (list &args) + { + // Match Disk Utility/Finder erase behavior by deriving a fresh exFAT layout. + args.push_back ("-R"); + } + struct MacOSXFormatterDeviceOwnerRestore { MacOSXFormatterDeviceOwnerRestore (const FilesystemPath &path, const UserId &owner) diff --git a/src/Main/TextUserInterface.cpp b/src/Main/TextUserInterface.cpp index defefafc..2d8871f8 100644 --- a/src/Main/TextUserInterface.cpp +++ b/src/Main/TextUserInterface.cpp @@ -1136,6 +1136,9 @@ namespace VeraCrypt } #ifdef TC_MACOSX + if (IsMacOSXExFATFormatter (fsFormatter)) + AddMacOSXExFATFormatterArgs (args); + if (IsMacOSXAPFSFormatter (fsFormatter) && !useElevatedAPFSFormatter) AddMacOSXAPFSFormatterUserArgs (args); #endif