![]() |
Bitcoin Core 31.99.0
P2P Digital Currency
|
#include <bitcoin-build-config.h>#include <util/fs_helpers.h>#include <random.h>#include <sync.h>#include <tinyformat.h>#include <util/byte_units.h>#include <util/fs.h>#include <util/log.h>#include <util/syserror.h>#include <cerrno>#include <fstream>#include <map>#include <memory>#include <optional>#include <stdexcept>#include <string>#include <system_error>#include <utility>#include <fcntl.h>#include <sys/resource.h>#include <sys/types.h>#include <unistd.h>Go to the source code of this file.
Namespaces | |
| namespace | util |
Functions | |
| static std::map< std::string, std::unique_ptr< fsbridge::FileLock > > dir_locks | GUARDED_BY (cs_dir_locks) |
| A map that contains all the currently held directory locks. More... | |
| LockResult | util::LockDirectory (const fs::path &directory, const fs::path &lockfile_name, bool probe_only) |
| void | UnlockDirectory (const fs::path &directory, const fs::path &lockfile_name) |
| void | ReleaseDirectoryLocks () |
| Release all directory locks. More... | |
| bool | CheckDiskSpace (const fs::path &dir, uint64_t additional_bytes) |
| std::streampos | GetFileSize (const char *path, std::streamsize max) |
| Get the size of a file by scanning it. More... | |
| bool | FileCommit (FILE *file) |
| Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsync(). More... | |
| void | DirectoryCommit (const fs::path &dirname) |
| Sync directory contents. More... | |
| bool | TruncateFile (FILE *file, unsigned int length) |
| int | RaiseFileDescriptorLimit (int nMinFD) |
| this function tries to raise the file descriptor limit to the requested number. More... | |
| 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 is advisory, and the range specified in the arguments will never contain live data More... | |
| bool | RenameOver (fs::path src, fs::path dest) |
| Rename src to dest. More... | |
| bool | TryCreateDirectories (const fs::path &p) |
| Ignores exceptions thrown by create_directories if the requested directory exists. More... | |
| std::string | PermsToSymbolicString (fs::perms p) |
| Convert fs::perms to symbolic string of the form 'rwxrwxrwx'. More... | |
| std::optional< fs::perms > | InterpretPermString (const std::string &s) |
| Interpret a custom permissions level string as fs::perms. More... | |
| bool | IsDirWritable (const fs::path &dir_path) |
| Check if a directory is writable by creating a temporary file on it. More... | |
Variables | |
| static GlobalMutex | cs_dir_locks |
| Mutex to protect dir_locks. More... | |
| 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 is advisory, and the range specified in the arguments will never contain live data
Definition at line 185 of file fs_helpers.cpp.
| bool CheckDiskSpace | ( | const fs::path & | dir, |
| uint64_t | additional_bytes | ||
| ) |
| void DirectoryCommit | ( | const fs::path & | dirname | ) |
Sync directory contents.
This is required on some environments to ensure that newly created files are committed to disk.
Definition at line 137 of file fs_helpers.cpp.
| bool FileCommit | ( | FILE * | file | ) |
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsync().
Definition at line 106 of file fs_helpers.cpp.
| std::streampos GetFileSize | ( | const char * | path, |
| std::streamsize | max = std::numeric_limits< std::streamsize >::max() |
||
| ) |
Get the size of a file by scanning it.
| [in] | path | The file path |
| [in] | max | Stop seeking beyond this limit |
Definition at line 99 of file fs_helpers.cpp.
|
static |
A map that contains all the currently held directory locks.
After successful locking, these will be held here until the global destructor cleans them up and thus automatically unlocks them, or ReleaseDirectoryLocks is called.
| std::optional< fs::perms > InterpretPermString | ( | const std::string & | s | ) |
Interpret a custom permissions level string as fs::perms.
| [in] | s | Permission level string |
Definition at line 295 of file fs_helpers.cpp.
| bool IsDirWritable | ( | const fs::path & | dir_path | ) |
Check if a directory is writable by creating a temporary file on it.
| [in] | dir_path | Path of the directory to test |
| std::runtime_error | if dir_path is not a directory. |
Definition at line 311 of file fs_helpers.cpp.
| std::string PermsToSymbolicString | ( | fs::perms | p | ) |
Convert fs::perms to symbolic string of the form 'rwxrwxrwx'.
| [in] | p | the perms to be converted |
Definition at line 272 of file fs_helpers.cpp.
| int RaiseFileDescriptorLimit | ( | int | nMinFD | ) |
this function tries to raise the file descriptor limit to the requested number.
It returns the actual file descriptor limit (which may be more or less than nMinFD)
Definition at line 161 of file fs_helpers.cpp.
| void ReleaseDirectoryLocks | ( | ) |
Release all directory locks.
This is used for unit testing only, at runtime the global destructor will take care of the locks.
Definition at line 85 of file fs_helpers.cpp.
Rename src to dest.
Definition at line 247 of file fs_helpers.cpp.
| bool TruncateFile | ( | FILE * | file, |
| unsigned int | length | ||
| ) |
| bool TryCreateDirectories | ( | const fs::path & | p | ) |
Ignores exceptions thrown by create_directories if the requested directory exists.
Specifically handles case where path p exists, but it wasn't possible for the user to write to the parent directory.
Definition at line 259 of file fs_helpers.cpp.
Definition at line 79 of file fs_helpers.cpp.
|
static |
Mutex to protect dir_locks.
Definition at line 43 of file fs_helpers.cpp.