Skip to content

Commit

Permalink
util: detect and warn of exFAT on MacOS
Browse files Browse the repository at this point in the history
Detect and warn of these.
  • Loading branch information
willcl-ark committed Dec 5, 2024
1 parent e8cc790 commit b593c9a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,23 @@ bool AppInitParameterInteraction(const ArgsManager& args)
InitWarning(warnings);
}

// Check if we are running on exFAT on MacOS
#ifdef __APPLE__
std::vector<fs::path> paths_to_check = {args.GetDataDirNet(), args.GetBlocksDirPath()};
for (const auto& path : paths_to_check) {
FSType fs_type = GetFilesystemType(path);
switch(fs_type) {
case FSType::EXFAT:
return InitError(strprintf(_("Specified directory \"%s\" is exFAT which is known to cause corruption on MacOS."), fs::PathToString(path)));
case FSType::ERROR:
LogPrintf("Warning: Failed to detect filesystem at %s\n", fs::PathToString(path));
break;
default:
break;
}
}
#endif

if (!fs::is_directory(args.GetBlocksDirPath())) {
return InitError(strprintf(_("Specified blocks directory \"%s\" does not exist."), args.GetArg("-blocksdir", "")));
}
Expand Down
18 changes: 18 additions & 0 deletions src/util/fs_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
#include <shlobj.h> /* For SHGetSpecialFolderPathW */
#endif // WIN32

#ifdef __APPLE__
#include <sys/statfs.h>
#endif

/** Mutex to protect dir_locks. */
static GlobalMutex cs_dir_locks;
/** A map that contains all the currently held directory locks. After
Expand Down Expand Up @@ -309,3 +313,17 @@ std::optional<fs::perms> InterpretPermString(const std::string& s)
return std::nullopt;
}
}

#ifdef __APPLE__
FSType GetFilesystemType(const fs::path& path) {
struct statfs fs_info;
if (statfs(path.c_str(), &fs_info) != 0) {
return FSType::ERROR;
}

if (strcmp(fs_info.f_fstypename, "exfat") == 0) {
return FSType::EXFAT;
}
return FSType::OTHER;
}
#endif
17 changes: 17 additions & 0 deletions src/util/fs_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down

0 comments on commit b593c9a

Please sign in to comment.