Skip to content

Commit ec484bd

Browse files
committed
Merge bitcoin/bitcoin#31453: util: detect and warn when using exFAT on MacOS
db32280 util: detect and warn when using exFAT on macOS (willcl-ark) Pull request description: exFAT is known to cause intermittent corruption on MacOS. Therefore we should warn when using this fs format for either the blocks or data directories. See #28552 for more context. ACKs for top commit: l0rinc: ACK db32280 marcofleon: reACK db32280 ismaelsadeeq: reACK db32280 Tree-SHA512: e4453a8e24b35c135e4eb0b4e47fe0c80f8b54700f458909c403aa37a0d2979ee165347bcd76e48e4d1ae5d3bae13f50e6afe714e33226a52f907b95df9d3b46
2 parents 273e600 + db32280 commit ec484bd

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

doc/files.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
- [Installed Files](#installed-files)
2020

21+
- [Filesystem recommendations](#filesystem-recommendations)
22+
2123
## Data directory location
2224

2325
The data directory is the default location where the Bitcoin Core files are stored.
@@ -160,3 +162,8 @@ This table describes the files installed by Bitcoin Core across different platfo
160162
- *Italicized* files are only installed in source builds if relevant CMake options are enabled. They are not included in binary releases.
161163
- README and bitcoin.conf files are included in binary releases but not installed in source builds.
162164
- On Windows, binaries have a `.exe` suffix (e.g., `bitcoin-cli.exe`).
165+
166+
## Filesystem recommendations
167+
168+
When choosing a filesystem for the data directory (`datadir`) or blocks directory (`blocksdir`) on **macOS**,the `exFAT` filesystem should be avoided.
169+
There have been multiple reports of database corruption and data loss when using this filesystem with Bitcoin Core, see [Issue #31454](https://github.com/bitcoin/bitcoin/issues/31454) for more details.

src/init.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,26 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
18661866
}
18671867
}
18681868

1869+
#ifdef __APPLE__
1870+
auto check_and_warn_fs{[&](const fs::path& path, std::string_view desc) {
1871+
const auto path_desc{strprintf("%s (\"%s\")", desc, fs::PathToString(path))};
1872+
switch (GetFilesystemType(path)) {
1873+
case FSType::EXFAT:
1874+
InitWarning(strprintf(_("The %s path uses exFAT, which is known to have intermittent corruption problems on macOS. "
1875+
"Move this directory to a different filesystem to avoid data loss."), path_desc));
1876+
break;
1877+
case FSType::ERROR:
1878+
LogInfo("Failed to detect filesystem type for %s", path_desc);
1879+
break;
1880+
case FSType::OTHER:
1881+
break;
1882+
}
1883+
}};
1884+
1885+
check_and_warn_fs(args.GetDataDirNet(), "data directory");
1886+
check_and_warn_fs(args.GetBlocksDirPath(), "blocks directory");
1887+
#endif
1888+
18691889
#if HAVE_SYSTEM
18701890
const std::string block_notify = args.GetArg("-blocknotify", "");
18711891
if (!block_notify.empty()) {

src/util/fs_helpers.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
#include <shlobj.h>
3131
#endif // WIN32
3232

33+
#ifdef __APPLE__
34+
#include <sys/mount.h>
35+
#include <sys/param.h>
36+
#endif
37+
3338
/** Mutex to protect dir_locks. */
3439
static GlobalMutex cs_dir_locks;
3540
/** A map that contains all the currently held directory locks. After
@@ -298,3 +303,15 @@ std::optional<fs::perms> InterpretPermString(const std::string& s)
298303
return std::nullopt;
299304
}
300305
}
306+
307+
#ifdef __APPLE__
308+
FSType GetFilesystemType(const fs::path& path)
309+
{
310+
if (struct statfs fs_info; statfs(path.c_str(), &fs_info)) {
311+
return FSType::ERROR;
312+
} else if (std::string_view{fs_info.f_fstypename} == "exfat") {
313+
return FSType::EXFAT;
314+
}
315+
return FSType::OTHER;
316+
}
317+
#endif

src/util/fs_helpers.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414
#include <limits>
1515
#include <optional>
1616

17+
#ifdef __APPLE__
18+
enum class FSType {
19+
EXFAT,
20+
OTHER,
21+
ERROR
22+
};
23+
24+
/**
25+
* Detect filesystem type for a given path.
26+
* Currently identifies exFAT filesystems which cause issues on macOS.
27+
*
28+
* @param[in] path The directory path to check
29+
* @return FSType enum indicating the filesystem type
30+
*/
31+
FSType GetFilesystemType(const fs::path& path);
32+
#endif
33+
1734
/**
1835
* Ensure file contents are fully committed to disk, using a platform-specific
1936
* feature analogous to fsync().

0 commit comments

Comments
 (0)