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-06-10 08:22:31 +00:00
|
|
|
#if !defined(OS_LINUX)
|
2022-02-13 16:58:38 +00:00
|
|
|
[[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
|
|
|
|
2022-03-23 18:15:01 +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-06-10 08:22:31 +00:00
|
|
|
#if !defined(OS_LINUX)
|
2022-02-13 16:58:38 +00:00
|
|
|
[[noreturn]]
|
|
|
|
#endif
|
2022-03-24 14:30:10 +00:00
|
|
|
BlockDeviceType getBlockDeviceType([[maybe_unused]] const String & device_id);
|
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-06-10 08:22:31 +00:00
|
|
|
#if !defined(OS_LINUX)
|
2022-02-13 16:58:38 +00:00
|
|
|
[[noreturn]]
|
|
|
|
#endif
|
2022-03-24 14:30:10 +00:00
|
|
|
UInt64 getBlockDeviceReadAheadBytes([[maybe_unused]] const String & device_id);
|
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
|
2022-06-10 08:22:31 +00:00
|
|
|
#if !defined(OS_LINUX)
|
2019-11-27 09:39:44 +00:00
|
|
|
[[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
|
|
|
|
2022-05-25 14:49:40 +00:00
|
|
|
size_t getSizeFromFileDescriptor(int fd, const String & file_name = "");
|
|
|
|
|
2022-07-09 17:35:07 +00:00
|
|
|
std::optional<size_t> tryGetSizeFromFilePath(const String & path);
|
|
|
|
|
|
|
|
/// Get inode number for a file path.
|
|
|
|
/// Will not work correctly if filesystem does not support inodes.
|
2022-07-05 13:52:39 +00:00
|
|
|
int getINodeNumberFromPath(const String & path);
|
|
|
|
|
2019-10-01 18:51:33 +00:00
|
|
|
}
|
2021-05-28 21:57:53 +00:00
|
|
|
|
|
|
|
namespace FS
|
|
|
|
{
|
|
|
|
bool createFile(const std::string & path);
|
|
|
|
|
2022-04-04 12:23:34 +00:00
|
|
|
bool exists(const std::string & path);
|
2021-05-28 21:57:53 +00:00
|
|
|
bool canRead(const std::string & path);
|
|
|
|
bool canWrite(const std::string & path);
|
2022-04-04 12:23:34 +00:00
|
|
|
bool canExecute(const std::string & path);
|
2021-05-28 21:57:53 +00:00
|
|
|
|
2022-06-09 14:59:12 +00:00
|
|
|
/// st_mtime
|
2021-05-28 21:57:53 +00:00
|
|
|
time_t getModificationTime(const std::string & path);
|
|
|
|
Poco::Timestamp getModificationTimestamp(const std::string & path);
|
|
|
|
void setModificationTime(const std::string & path, time_t time);
|
2022-06-09 14:59:12 +00:00
|
|
|
/// st_ctime
|
|
|
|
time_t getChangeTime(const std::string & path);
|
2021-05-28 21:57:53 +00:00
|
|
|
}
|