Bitcoin Core 31.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-present 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#include <string>
17
18#ifdef __APPLE__
19enum class FSType {
20 EXFAT,
21 OTHER,
22 ERROR
23};
24
32FSType GetFilesystemType(const fs::path& path);
33#endif
34
39bool FileCommit(FILE* file);
40
45void DirectoryCommit(const fs::path& dirname);
46
47bool TruncateFile(FILE* file, unsigned int length);
48int RaiseFileDescriptorLimit(int nMinFD);
49void AllocateFileRange(FILE* file, unsigned int offset, unsigned int length);
50
55[[nodiscard]] bool RenameOver(fs::path src, fs::path dest);
56
57namespace util {
58enum class LockResult {
59 Success,
62};
63[[nodiscard]] LockResult LockDirectory(const fs::path& directory, const fs::path& lockfile_name, bool probe_only = false);
64} // namespace util
65void UnlockDirectory(const fs::path& directory, const fs::path& lockfile_name);
66bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes = 0);
67
74std::streampos GetFileSize(const char* path, std::streamsize max = std::numeric_limits<std::streamsize>::max());
75
80
81bool TryCreateDirectories(const fs::path& p);
82fs::path GetDefaultDataDir();
83
89std::string PermsToSymbolicString(fs::perms p);
95std::optional<fs::perms> InterpretPermString(const std::string& s);
96
97#ifdef WIN32
98fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
99#endif
100
101#endif // BITCOIN_UTIL_FS_HELPERS_H
fs::path GetDefaultDataDir()
Definition: args.cpp:782
bool RenameOver(fs::path src, fs::path dest)
Rename src to dest.
Definition: fs_helpers.cpp:244
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
Definition: fs_helpers.cpp:158
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:96
void DirectoryCommit(const fs::path &dirname)
Sync directory contents.
Definition: fs_helpers.cpp:134
void ReleaseDirectoryLocks()
Release all directory locks.
Definition: fs_helpers.cpp:82
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by create_directories if the requested directory exists.
Definition: fs_helpers.cpp:256
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:182
std::optional< fs::perms > InterpretPermString(const std::string &s)
Interpret a custom permissions level string as fs::perms.
Definition: fs_helpers.cpp:292
bool TruncateFile(FILE *file, unsigned int length)
Definition: fs_helpers.cpp:145
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes=0)
Definition: fs_helpers.cpp:88
std::string PermsToSymbolicString(fs::perms p)
Convert fs::perms to symbolic string of the form 'rwxrwxrwx'.
Definition: fs_helpers.cpp:269
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
Definition: fs_helpers.cpp:103
void UnlockDirectory(const fs::path &directory, const fs::path &lockfile_name)
Definition: fs_helpers.cpp:76
LockResult
Definition: fs_helpers.h:58
LockResult LockDirectory(const fs::path &directory, const fs::path &lockfile_name, bool probe_only)
Definition: fs_helpers.cpp:48