8#if defined(HAVE_CONFIG_H)
9#include <config/bitcoin-config.h>
24#include <system_error>
36#define _POSIX_C_SOURCE 200112L
41#include <sys/resource.h>
55static std::map<std::string, std::unique_ptr<fsbridge::FileLock>>
74 auto lock = std::make_unique<fsbridge::FileLock>(
pathLockFile);
75 if (!lock->TryLock()) {
76 return error(
"Error while attempting to lock directory %s: %s",
119std::streampos
GetFileSize(
const char *path, std::streamsize max) {
120 std::ifstream file{path, std::ios::binary};
122 return file.gcount();
138#elif defined(MAC_OSX) && defined(F_FULLFSYNC)
218#elif defined(MAC_OSX)
229 fst.fst_bytesalloc = 0;
235#elif defined(HAVE_POSIX_FALLOCATE)
242 static const char buf[65536] = {};
247 unsigned int now = 65536;
252 fwrite(buf, 1, now, file);
267 "SHGetSpecialFolderPathW() failed, could not obtain requested path.\n");
274 return MoveFileExW(src.wstring().c_str(), dest.wstring().c_str(),
277 int rc = std::rename(src.c_str(), dest.c_str());
290 }
catch (
const fs::filesystem_error &) {
Different type to mark Mutex at global scope.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
bool LockDirectory(const fs::path &directory, const std::string lockfile_name, bool probe_only)
static GlobalMutex cs_dir_locks
Mutex to protect dir_locks.
void UnlockDirectory(const fs::path &directory, const std::string &lockfile_name)
bool DirIsWritable(const fs::path &directory)
bool RenameOver(fs::path src, fs::path dest)
std::streampos GetFileSize(const char *path, std::streamsize max)
Get the size of a file by scanning it.
int RaiseFileDescriptorLimit(int nMinFD)
This function tries to raise the file descriptor limit to the requested number.
void DirectoryCommit(const fs::path &dirname)
Sync directory contents.
void ReleaseDirectoryLocks()
Release all directory locks.
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by create_directories if the requested directory exists.
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length)
This function tries to make a particular range of a file allocated (corresponding to disk space) it i...
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes)
bool TruncateFile(FILE *file, unsigned int length)
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
fs::path GetUniquePath(const fs::path &base)
Helper function for getting a unique path.
bool error(const char *fmt, const Args &...args)
static bool create_directories(const std::filesystem::path &p)
Create directory (and if necessary its parents), unless the leaf directory already exists or is a sym...
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to byte string.
FILE * fopen(const fs::path &p, const char *mode)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...