IBC#026: Bitcoin Core Initialization, Step 11: Apple Specific Checks
Checking MacOS filesytem
Hello everyone and welcome to this new episode of Inside Bitcoin Code.
A special welcome to the new people that recently subscribed to this newsletter, I hope that you will enjoy what I write. A small suggestion for you: if you know nothing about coding, start reading the posts from Learn2Code to get some basic knowledge before diving in the real deal.
A huge thanks to each of the 159 subscribers of this newsletter and to those who decided to contribute with some sats to this project. It means the world to me!
Last episode was focused on step 9 and 10. Today we are continuing step 11 of the initialization of Bitcoin Core, with some checks needed on MacOS filesystem. [Code Link]
Let’s start!
Apple Specific Checks
The following part of the program is found inside a conditional compilation directive. This means that the code is actually compiled and run only if a so-called preprocessor definition has been defined.
In this specific code snippet, compilation occurs when __APPLE__ is defined, which basically means that we are running this part of the code on MacOS systems only.
This code needs to check the kind of filesystem used to store block data on MacOS, since there are some types that are known to be subject to corruption.
#ifdef __APPLE__
#endifInside, the program defines a Lambda Function, an expression that allows a developer to define an inline function that will not be reused somewhere else. This function takes as input a fs::path variable, containing a location chosen in the filesystem, and a std::string_view, which stores a description for the chosen location.
auto check_and_warn_fs{[&](const fs::path& path, std::string_view desc) {
}};The, a description string is created, merging the description desc and the path, which is also printed through the strprintf function.
const auto path_desc{strprintf(”%s (\”%s\”)”, desc, fs::PathToString(path))};Consider supporting this newsletter by using one of my affiliate links. These are not sponsorships, just products I use everyday. Thank you!
Then a switch block, a flow control construct used to execute one block of code among multiple options, is used to check the type of the filesystem in use. First, the type of path is evaluated using the GetFilesystemType() function.
switch (GetFilesystemType(path)) {
}It returns an FSType, an enumerator that can assume one of the following values.
enum class FSType {
EXFAT,
OTHER,
ERROR
};Here, three different case can occur:
FSType::EXFAT: This type of filesystem is know to give issues on MacOS, undergoing intermittent corruption. A warning is launched, with the suggestion to move the directory to another filesystem.
case FSType::EXFAT:
InitWarning(strprintf(_(”The %s path uses exFAT, which is known to have intermittent corruption problems on macOS. “
“Move this directory to a different filesystem to avoid data loss.”), path_desc));
break;FSType::ERROR: In case it is not possible to retrieve the filesystem type, a message is logged to inform the user that it was not possible to perform the check.
case FSType::ERROR:
LogInfo(”Failed to detect filesystem type for %s”, path_desc);
break;FSType::OTHER: Everything is ok, all other filesystems are not subject to corruption, the program can continue to run.
case FSType::OTHER:
break;The Lamba function check_and_warn_fs if finally used to to check both the data and the block directories.
check_and_warn_fs(args.GetDataDirNet(), “data directory”);
check_and_warn_fs(args.GetBlocksDirPath(), “blocks directory”);Let’s keep in touch:
Check out my writings on btc++ insider edition
Try my new app Sats Tracker, an expense tracker app for people living in the Bitcoin standard.
Zap me a coffee and leave me a message: tuma@wallet.yakihonne.com


