Bitcoin Core 29.99.0
P2P Digital Currency
fs_helpers.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-2023 The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef BITCOIN_UTIL_FS_HELPERS_H
7#define BITCOIN_UTIL_FS_HELPERS_H
8
9#include <util/fs.h>
10
11#include <cstdint>
12#include <cstdio>
13#include <iosfwd>
14#include <limits>
15#include <optional>
16
17#ifdef __APPLE__
18enum class FSType {
19 EXFAT,
20 OTHER,
21 ERROR
22};
23
31FSType GetFilesystemType(const fs::path& path);
32#endif
33
38bool FileCommit(FILE* file);
39
44void DirectoryCommit(const fs::path& dirname);
45
46bool TruncateFile(FILE* file, unsigned int length);
47int RaiseFileDescriptorLimit(int nMinFD);
48void AllocateFileRange(FILE* file, unsigned int offset, unsigned int length);
49
54[[nodiscard]] bool RenameOver(fs::path src, fs::path dest);
55
56namespace util {
57enum class LockResult {
58 Success,
61};
62[[nodiscard]] LockResult LockDirectory(const fs::path& directory, const fs::path& lockfile_name, bool probe_only = false);
63} // namespace util
64void UnlockDirectory(const fs::path& directory, const fs::path& lockfile_name);
65bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes = 0);
66
73std::streampos GetFileSize(const char* path, std::streamsize max = std::numeric_limits<std::streamsize>::max());
74
79
80bool TryCreateDirectories(const fs::path& p);
81fs::path GetDefaultDataDir();
82
88std::string PermsToSymbolicString(fs::perms p);
94std::optional<fs::perms> InterpretPermString(const std::string& s);
95
96#ifdef WIN32
97fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
98#endif
99
100#endif // BITCOIN_UTIL_FS_HELPERS_H
fs::path GetDefaultDataDir()
Definition: args.cpp:732
bool RenameOver(fs::path src, fs::path dest)
Rename src to dest.
Definition: fs_helpers.cpp:243
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
Definition: fs_helpers.cpp:157
std::streampos GetFileSize(const char *path, std::streamsize max=std::numeric_limits< std::streamsize >::max())
Get the size of a file by scanning it.
Definition: fs_helpers.cpp:95
void DirectoryCommit(const fs::path &dirname)
Sync directory contents.
Definition: fs_helpers.cpp:133
void ReleaseDirectoryLocks()
Release all directory locks.
Definition: fs_helpers.cpp:81
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by create_directories if the requested directory exists.
Definition: fs_helpers.cpp:255
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...
Definition: fs_helpers.cpp:181
std::optional< fs::perms > InterpretPermString(const std::string &s)
Interpret a custom permissions level string as fs::perms.
Definition: fs_helpers.cpp:291
bool TruncateFile(FILE *file, unsigned int length)
Definition: fs_helpers.cpp:144
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes=0)
Definition: fs_helpers.cpp:87
std::string PermsToSymbolicString(fs::perms p)
Convert fs::perms to symbolic string of the form 'rwxrwxrwx'.
Definition: fs_helpers.cpp:268
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
Definition: fs_helpers.cpp:102
void UnlockDirectory(const fs::path &directory, const fs::path &lockfile_name)
Definition: fs_helpers.cpp:75
LockResult
Definition: fs_helpers.h:57
LockResult LockDirectory(const fs::path &directory, const fs::path &lockfile_name, bool probe_only)
Definition: fs_helpers.cpp:47