6#include <bitcoin-build-config.h>
21#include <system_error>
26#include <sys/resource.h>
63 auto lock = std::make_unique<fsbridge::FileLock>(
pathLockFile);
64 if (!lock->TryLock()) {
95std::streampos
GetFileSize(
const char* path, std::streamsize max)
97 std::ifstream file{path, std::ios::binary};
114#elif defined(__APPLE__) && defined(F_FULLFSYNC)
192#elif defined(__APPLE__)
200 fst.fst_length = length;
201 fst.fst_bytesalloc = 0;
208#if defined(HAVE_POSIX_FALLOCATE)
215 static const char buf[65536] = {};
220 unsigned int now = 65536;
223 fwrite(buf, 1, now, file);
238 LogError(
"SHGetSpecialFolderPathW() failed, could not obtain requested path.");
245 std::error_code error;
246 fs::rename(
src, dest, error);
258 return fs::create_directories(
p);
259 }
catch (
const fs::filesystem_error&) {
278 set_perm(0, fs::perms::owner_read,
'r');
279 set_perm(1, fs::perms::owner_write,
'w');
280 set_perm(2, fs::perms::owner_exec,
'x');
281 set_perm(3, fs::perms::group_read,
'r');
282 set_perm(4, fs::perms::group_write,
'w');
283 set_perm(5, fs::perms::group_exec,
'x');
284 set_perm(6, fs::perms::others_read,
'r');
285 set_perm(7, fs::perms::others_write,
'w');
286 set_perm(8, fs::perms::others_exec,
'x');
294 return fs::perms::owner_read | fs::perms::owner_write;
295 }
else if (s ==
"group") {
296 return fs::perms::owner_read | fs::perms::owner_write |
297 fs::perms::group_read;
298 }
else if (s ==
"all") {
299 return fs::perms::owner_read | fs::perms::owner_write |
300 fs::perms::group_read |
301 fs::perms::others_read;
311 return FSType::ERROR;
312 }
else if (std::string_view{
fs_info.f_fstypename} ==
"exfat") {
313 return FSType::EXFAT;
315 return FSType::OTHER;
Different type to mark Mutex at global scope.
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to a byte string.
static GlobalMutex cs_dir_locks
Mutex to protect dir_locks.
bool RenameOver(fs::path src, fs::path dest)
Rename src to 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)
std::optional< fs::perms > InterpretPermString(const std::string &s)
Interpret a custom permissions level string as fs::perms.
bool TruncateFile(FILE *file, unsigned int length)
std::string PermsToSymbolicString(fs::perms p)
Convert fs::perms to symbolic string of the form 'rwxrwxrwx'.
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
void UnlockDirectory(const fs::path &directory, const fs::path &lockfile_name)
FILE * fopen(const fs::path &p, const char *mode)
LockResult LockDirectory(const fs::path &directory, const fs::path &lockfile_name, bool probe_only)
std::string SysErrorString(int err)
Return system error string from errno value.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.