Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
fs_helpers.h File Reference
#include <util/fs.h>
#include <cstdint>
#include <cstdio>
#include <ios>
#include <limits>
#include <optional>
#include <string>
Include dependency graph for fs_helpers.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  util

Enumerations

enum class  util::LockResult { util::Success , util::ErrorWrite , util::ErrorLock }

Functions

bool FileCommit (FILE *file)
 Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsync().
void DirectoryCommit (const fs::path &dirname)
 Sync directory contents.
bool TruncateFile (FILE *file, uint64_t length)
int FileSeek64 (FILE *file, int64_t offset, int origin)
 64-bit-clean file positioning.
int64_t FileTell64 (FILE *file)
 64-bit-clean file positioning.
int RaiseFileDescriptorLimit (int min_fd)
 Try to raise the file descriptor limit to the requested number.
void AllocateFileRange (FILE *file, uint64_t 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
bool RenameOver (fs::path src, fs::path dest)
 Rename src to dest.
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)
bool CheckDiskSpace (const fs::path &dir, uint64_t additional_bytes=0)
std::streampos GetFileSize (const char *path, std::streamsize max=std::numeric_limits< std::streamsize >::max())
 Get the size of a file by scanning it.
void ReleaseDirectoryLocks ()
 Release all directory locks.
bool TryCreateDirectories (const fs::path &p)
 Ignores exceptions thrown by create_directories if the requested directory exists.
fs::path GetDefaultDataDir ()
std::string PermsToSymbolicString (fs::perms p)
 Convert fs::perms to symbolic string of the form 'rwxrwxrwx'.
std::optional< fs::perms > InterpretPermString (const std::string &s)
 Interpret a custom permissions level string as fs::perms.
bool IsDirWritable (const fs::path &dir_path)
 Check if a directory is writable by creating a temporary file on it.

Function Documentation

◆ AllocateFileRange()

void AllocateFileRange ( FILE * file,
uint64_t 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 200 of file fs_helpers.cpp.

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

◆ CheckDiskSpace()

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

Definition at line 93 of file fs_helpers.cpp.

Here is the call graph for this function:
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 139 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 108 of file fs_helpers.cpp.

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

◆ FileSeek64()

int FileSeek64 ( FILE * file,
int64_t offset,
int origin )
inline

64-bit-clean file positioning.

The wrapper is necessary for Windows, because long is only 32 bits there, even in 64-bit builds (LLP64).

Definition at line 55 of file fs_helpers.h.

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

◆ FileTell64()

int64_t FileTell64 ( FILE * file)
inline

64-bit-clean file positioning.

The wrapper is necessary for Windows, because long is only 32 bits there, even in 64-bit builds (LLP64).

Definition at line 70 of file fs_helpers.h.

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

◆ GetDefaultDataDir()

fs::path GetDefaultDataDir ( )

Definition at line 859 of file args.cpp.

Here is the call graph for this function:
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 101 of file fs_helpers.cpp.

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

◆ InterpretPermString()

std::optional< fs::perms > InterpretPermString ( const std::string & s)

Interpret a custom permissions level string as fs::perms.

Parameters
[in]sPermission level string
Returns
Permissions as fs::perms

Definition at line 310 of file fs_helpers.cpp.

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

◆ IsDirWritable()

bool IsDirWritable ( const fs::path & dir_path)

Check if a directory is writable by creating a temporary file on it.

Parameters
[in]dir_pathPath of the directory to test
Returns
true if a temporary file could be created and removed, false otherwise.
Exceptions
std::runtime_errorif dir_path is not a directory.

Definition at line 326 of file fs_helpers.cpp.

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

◆ PermsToSymbolicString()

std::string PermsToSymbolicString ( fs::perms p)

Convert fs::perms to symbolic string of the form 'rwxrwxrwx'.

Parameters
[in]pthe perms to be converted
Returns
Symbolic permissions string

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:

◆ RaiseFileDescriptorLimit()

int RaiseFileDescriptorLimit ( int min_fd)

Try to raise the file descriptor limit to the requested number.

Parameters
[in]min_fdThe requested minimum number of file descriptors.
Returns
The actual file descriptor limit. It may be lower or higher than min_fd. Returns std::numeric_limits<int>::max() if the OS imposes no limit (RLIM_INFINITY).

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:

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

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

◆ RenameOver()

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

Rename src to dest.

Returns
true if the rename was successful.

Definition at line 262 of file fs_helpers.cpp.

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

◆ TruncateFile()

bool TruncateFile ( FILE * file,
uint64_t length )

Definition at line 150 of file fs_helpers.cpp.

Here is the call graph for this function:
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 274 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 fs::path & lockfile_name )

Definition at line 81 of file fs_helpers.cpp.

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