mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-03 01:33:20 +02:00
util: detect and warn when using exFAT on macOS
exFAT is known to cause corruption on macOS. See #28552. Therefore we should warn when using this fs format for either the blocks or data directories on macOS. Co-authored-by: l0rinc <pap.lorinc@gmail.com>
This commit is contained in:
@@ -30,6 +30,11 @@
|
||||
#include <shlobj.h>
|
||||
#endif // WIN32
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <sys/mount.h>
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
/** Mutex to protect dir_locks. */
|
||||
static GlobalMutex cs_dir_locks;
|
||||
/** A map that contains all the currently held directory locks. After
|
||||
@@ -298,3 +303,15 @@ std::optional<fs::perms> InterpretPermString(const std::string& s)
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
FSType GetFilesystemType(const fs::path& path)
|
||||
{
|
||||
if (struct statfs fs_info; statfs(path.c_str(), &fs_info)) {
|
||||
return FSType::ERROR;
|
||||
} else if (std::string_view{fs_info.f_fstypename} == "exfat") {
|
||||
return FSType::EXFAT;
|
||||
}
|
||||
return FSType::OTHER;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -14,6 +14,23 @@
|
||||
#include <limits>
|
||||
#include <optional>
|
||||
|
||||
#ifdef __APPLE__
|
||||
enum class FSType {
|
||||
EXFAT,
|
||||
OTHER,
|
||||
ERROR
|
||||
};
|
||||
|
||||
/**
|
||||
* Detect filesystem type for a given path.
|
||||
* Currently identifies exFAT filesystems which cause issues on macOS.
|
||||
*
|
||||
* @param[in] path The directory path to check
|
||||
* @return FSType enum indicating the filesystem type
|
||||
*/
|
||||
FSType GetFilesystemType(const fs::path& path);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Ensure file contents are fully committed to disk, using a platform-specific
|
||||
* feature analogous to fsync().
|
||||
|
||||
Reference in New Issue
Block a user