Bitcoin ABC 0.30.7
P2P Digital Currency
Functions | Variables
fs_helpers.cpp File Reference
#include <util/fs_helpers.h>
#include <logging.h>
#include <sync.h>
#include <tinyformat.h>
#include <util/fs.h>
#include <util/getuniquepath.h>
#include <cerrno>
#include <filesystem>
#include <fstream>
#include <map>
#include <memory>
#include <string>
#include <system_error>
#include <utility>
#include <fcntl.h>
#include <sys/resource.h>
#include <unistd.h>
Include dependency graph for fs_helpers.cpp:

Go to the source code of this file.

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...
 
bool LockDirectory (const fs::path &directory, const std::string lockfile_name, bool probe_only)
 
void UnlockDirectory (const fs::path &directory, const std::string &lockfile_name)
 
void ReleaseDirectoryLocks ()
 Release all directory locks. More...
 
bool DirIsWritable (const fs::path &directory)
 
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)
 
bool TryCreateDirectories (const fs::path &p)
 Ignores exceptions thrown by create_directories if the requested directory exists. More...
 

Variables

static GlobalMutex cs_dir_locks
 Mutex to protect dir_locks. More...
 

Function Documentation

◆ AllocateFileRange()

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 208 of file fs_helpers.cpp.

Here is the caller graph for this function:

◆ CheckDiskSpace()

bool CheckDiskSpace ( const fs::path dir,
uint64_t  additional_bytes 
)

Definition at line 111 of file fs_helpers.cpp.

Here is the caller graph for this function:

◆ DirectoryCommit()

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 159 of file fs_helpers.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DirIsWritable()

bool DirIsWritable ( const fs::path directory)

Definition at line 97 of file fs_helpers.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FileCommit()

bool FileCommit ( FILE *  file)

Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsync().

Definition at line 125 of file fs_helpers.cpp.

Here is the caller graph for this function:

◆ GetFileSize()

std::streampos GetFileSize ( const char *  path,
std::streamsize  max = std::numeric_limits< std::streamsize >::max() 
)

Get the size of a file by scanning it.

Parameters
[in]pathThe file path
[in]maxStop seeking beyond this limit
Returns
The file size or max

Definition at line 119 of file fs_helpers.cpp.

Here is the caller graph for this function:

◆ GUARDED_BY()

static std::map< std::string, std::unique_ptr< fsbridge::FileLock > > dir_locks GUARDED_BY ( cs_dir_locks  )
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.

◆ LockDirectory()

bool LockDirectory ( const fs::path directory,
const std::string  lockfile_name,
bool  probe_only 
)

Definition at line 58 of file fs_helpers.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RaiseFileDescriptorLimit()

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 182 of file fs_helpers.cpp.

Here is the caller graph for this function:

◆ ReleaseDirectoryLocks()

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 92 of file fs_helpers.cpp.

◆ RenameOver()

bool RenameOver ( fs::path  src,
fs::path  dest 
)

Definition at line 272 of file fs_helpers.cpp.

Here is the caller graph for this function:

◆ TruncateFile()

bool TruncateFile ( FILE *  file,
unsigned int  length 
)

Definition at line 169 of file fs_helpers.cpp.

Here is the caller graph for this function:

◆ TryCreateDirectories()

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 287 of file fs_helpers.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnlockDirectory()

void UnlockDirectory ( const fs::path directory,
const std::string &  lockfile_name 
)

Definition at line 86 of file fs_helpers.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ cs_dir_locks

GlobalMutex cs_dir_locks
static

Mutex to protect dir_locks.

Definition at line 49 of file fs_helpers.cpp.