Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
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 <ios>
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, uint64_t length);
48
55inline int FileSeek64(FILE* file, int64_t offset, int origin)
56{
57#if defined(WIN32)
58 return _fseeki64(file, offset, origin);
59#else
60 return std::fseek(file, offset, origin);
61#endif
62}
63
70inline int64_t FileTell64(FILE* file)
71{
72#if defined(WIN32)
73 return _ftelli64(file);
74#else
75 return std::ftell(file);
76#endif
77}
78
88int RaiseFileDescriptorLimit(int min_fd);
89
90void AllocateFileRange(FILE* file, uint64_t offset, unsigned int length);
91
96[[nodiscard]] bool RenameOver(fs::path src, fs::path dest);
97
98namespace util {
104[[nodiscard]] LockResult LockDirectory(const fs::path& directory, const fs::path& lockfile_name, bool probe_only = false);
105} // namespace util
106void UnlockDirectory(const fs::path& directory, const fs::path& lockfile_name);
107bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes = 0);
108
115std::streampos GetFileSize(const char* path, std::streamsize max = std::numeric_limits<std::streamsize>::max());
116
121
122bool TryCreateDirectories(const fs::path& p);
123fs::path GetDefaultDataDir();
124
130std::string PermsToSymbolicString(fs::perms p);
136std::optional<fs::perms> InterpretPermString(const std::string& s);
137
144bool IsDirWritable(const fs::path& dir_path);
145
146#ifdef WIN32
147fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
148#endif
149
150#endif // BITCOIN_UTIL_FS_HELPERS_H
fs::path GetDefaultDataDir()
Definition args.cpp:859
bool TruncateFile(FILE *file, uint64_t length)
bool RenameOver(fs::path src, fs::path dest)
Rename src to dest.
std::streampos GetFileSize(const char *path, std::streamsize max)
Get the size of a file by scanning it.
void DirectoryCommit(const fs::path &dirname)
Sync directory contents.
int RaiseFileDescriptorLimit(int min_fd)
Try to raise the file descriptor limit to the requested number.
void ReleaseDirectoryLocks()
Release all directory locks.
bool IsDirWritable(const fs::path &dir_path)
Check if a directory is writable by creating a temporary file on it.
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by create_directories if the requested directory exists.
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes)
std::optional< fs::perms > InterpretPermString(const std::string &s)
Interpret a custom permissions level string as fs::perms.
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 i...
std::string PermsToSymbolicString(fs::perms p)
Convert fs::perms to symbolic string of the form 'rwxrwxrwx'.
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
void UnlockDirectory(const fs::path &directory, const fs::path &lockfile_name)
int64_t FileTell64(FILE *file)
64-bit-clean file positioning.
Definition fs_helpers.h:70
int FileSeek64(FILE *file, int64_t offset, int origin)
64-bit-clean file positioning.
Definition fs_helpers.h:55
LockResult
Definition fs_helpers.h:99
LockResult LockDirectory(const fs::path &directory, const fs::path &lockfile_name, bool probe_only)