Bitcoin ABC 0.32.11
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
20bool FileCommit(FILE *file);
21
26void DirectoryCommit(const fs::path &dirname);
27
28bool TruncateFile(FILE *file, unsigned int length);
29int RaiseFileDescriptorLimit(int nMinFD);
30void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);
31
36[[nodiscard]] bool RenameOver(fs::path src, fs::path dest);
37
38namespace util {
39enum class LockResult {
40 Success,
43};
44[[nodiscard]] LockResult LockDirectory(const fs::path &directory,
45 const std::string lockfile_name,
46 bool probe_only = false);
47} // namespace util
48bool LockDirectory(const fs::path &directory, const std::string lockfile_name,
49 bool probe_only = false);
50void UnlockDirectory(const fs::path &directory,
51 const std::string &lockfile_name);
52bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes = 0);
53
61std::streampos
62GetFileSize(const char *path,
63 std::streamsize max = std::numeric_limits<std::streamsize>::max());
64
70
71bool TryCreateDirectories(const fs::path &p);
73
74#ifdef WIN32
75fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
76#endif
77
78#endif // BITCOIN_UTIL_FS_HELPERS_H
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:30
fs::path GetDefaultDataDir()
Definition: args.cpp:727
void UnlockDirectory(const fs::path &directory, const std::string &lockfile_name)
Definition: fs_helpers.cpp:86
bool RenameOver(fs::path src, fs::path dest)
Rename src to dest.
Definition: fs_helpers.cpp:258
int RaiseFileDescriptorLimit(int nMinFD)
This function tries to raise the file descriptor limit to the requested number.
Definition: fs_helpers.cpp:168
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:105
void DirectoryCommit(const fs::path &dirname)
Sync directory contents.
Definition: fs_helpers.cpp:145
void ReleaseDirectoryLocks()
Release all directory locks.
Definition: fs_helpers.cpp:92
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by create_directories if the requested directory exists.
Definition: fs_helpers.cpp:269
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:194
bool LockDirectory(const fs::path &directory, const std::string lockfile_name, bool probe_only=false)
bool TruncateFile(FILE *file, unsigned int length)
Definition: fs_helpers.cpp:155
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes=0)
Definition: fs_helpers.cpp:97
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
Definition: fs_helpers.cpp:111
LockResult LockDirectory(const fs::path &directory, const std::string lockfile_name, bool probe_only)
Definition: fs_helpers.cpp:56
LockResult
Definition: fs_helpers.h:39