2019-10-01 18:51:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2019-11-27 09:39:44 +00:00
|
|
|
#include <Common/Exception.h>
|
2019-10-01 18:51:33 +00:00
|
|
|
|
2019-11-27 09:39:44 +00:00
|
|
|
#include <filesystem>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <sys/statvfs.h>
|
2019-10-01 18:51:33 +00:00
|
|
|
#include <Poco/TemporaryFile.h>
|
|
|
|
|
2019-11-27 09:39:44 +00:00
|
|
|
|
2019-10-01 18:51:33 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
using TemporaryFile = Poco::TemporaryFile;
|
|
|
|
|
2019-10-02 12:06:34 +00:00
|
|
|
bool enoughSpaceInDirectory(const std::string & path, size_t data_size);
|
2019-10-01 18:51:33 +00:00
|
|
|
std::unique_ptr<TemporaryFile> createTemporaryFile(const std::string & path);
|
|
|
|
|
2022-02-15 09:56:21 +00:00
|
|
|
// Determine what block device is responsible for specified path
|
2022-02-13 16:58:38 +00:00
|
|
|
#if !defined(__linux__)
|
|
|
|
[[noreturn]]
|
|
|
|
#endif
|
2022-02-15 10:39:45 +00:00
|
|
|
String getBlockDeviceId([[maybe_unused]] const String & path);
|
2022-02-13 16:58:38 +00:00
|
|
|
|
|
|
|
enum class BlockDeviceType {
|
2022-02-15 09:56:21 +00:00
|
|
|
UNKNOWN = 0, // we were unable to determine device type
|
|
|
|
NONROT = 1, // not a rotational device (SSD, NVME, etc)
|
|
|
|
ROT = 2 // rotational device (HDD)
|
2022-02-13 16:58:38 +00:00
|
|
|
};
|
|
|
|
|
2022-02-15 09:56:21 +00:00
|
|
|
// Try to determine block device type
|
2022-02-13 16:58:38 +00:00
|
|
|
#if !defined(__linux__)
|
|
|
|
[[noreturn]]
|
|
|
|
#endif
|
2022-02-15 10:39:45 +00:00
|
|
|
BlockDeviceType getBlockDeviceType([[maybe_unused]] const String & deviceId);
|
2022-02-13 16:58:38 +00:00
|
|
|
|
2022-02-15 09:56:21 +00:00
|
|
|
// Get size of read-ahead in bytes for specified block device
|
2022-02-13 16:58:38 +00:00
|
|
|
#if !defined(__linux__)
|
|
|
|
[[noreturn]]
|
|
|
|
#endif
|
2022-02-15 10:39:45 +00:00
|
|
|
UInt64 getBlockDeviceReadAheadBytes([[maybe_unused]] const String & deviceId);
|
2022-02-13 16:58:38 +00:00
|
|
|
|
2020-06-27 19:05:00 +00:00
|
|
|
/// Returns mount point of filesystem where absolute_path (must exist) is located
|
2019-11-27 09:39:44 +00:00
|
|
|
std::filesystem::path getMountPoint(std::filesystem::path absolute_path);
|
|
|
|
|
|
|
|
/// Returns name of filesystem mounted to mount_point
|
|
|
|
#if !defined(__linux__)
|
|
|
|
[[noreturn]]
|
|
|
|
#endif
|
2019-12-03 13:37:40 +00:00
|
|
|
String getFilesystemName([[maybe_unused]] const String & mount_point);
|
2019-11-27 09:39:44 +00:00
|
|
|
|
2020-10-03 00:02:47 +00:00
|
|
|
struct statvfs getStatVFS(const String & path);
|
2019-11-27 09:39:44 +00:00
|
|
|
|
2021-05-24 21:27:24 +00:00
|
|
|
/// Returns true if path starts with prefix path
|
|
|
|
bool pathStartsWith(const std::filesystem::path & path, const std::filesystem::path & prefix_path);
|
|
|
|
|
|
|
|
/// Returns true if path starts with prefix path
|
|
|
|
bool pathStartsWith(const String & path, const String & prefix_path);
|
|
|
|
|
2021-10-17 10:13:47 +00:00
|
|
|
/// Same as pathStartsWith, but without canonization, i.e. allowed to check symlinks.
|
2021-10-17 10:45:32 +00:00
|
|
|
/// (Path is made absolute and normalized.)
|
2021-10-17 08:42:36 +00:00
|
|
|
bool fileOrSymlinkPathStartsWith(const String & path, const String & prefix_path);
|
2021-08-18 11:28:22 +00:00
|
|
|
|
2019-10-01 18:51:33 +00:00
|
|
|
}
|
2021-05-28 21:57:53 +00:00
|
|
|
|
|
|
|
namespace FS
|
|
|
|
{
|
|
|
|
bool createFile(const std::string & path);
|
|
|
|
|
|
|
|
bool canRead(const std::string & path);
|
|
|
|
bool canWrite(const std::string & path);
|
|
|
|
|
|
|
|
time_t getModificationTime(const std::string & path);
|
|
|
|
Poco::Timestamp getModificationTimestamp(const std::string & path);
|
|
|
|
void setModificationTime(const std::string & path, time_t time);
|
|
|
|
}
|