mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::fs: Add support test for fallocate().
This commit is contained in:
parent
47d6fbb35f
commit
24e423c714
2 changed files with 37 additions and 0 deletions
|
@ -20,4 +20,7 @@ namespace ircd::fs::support
|
|||
|
||||
// Test if O_DIRECT supported at target path
|
||||
bool direct_io(const string_view &path);
|
||||
|
||||
// Test if fallocate() is supported at target path
|
||||
bool fallocate(const string_view &path, const write_opts &wopts = write_opts_default);
|
||||
}
|
||||
|
|
34
ircd/fs.cc
34
ircd/fs.cc
|
@ -313,6 +313,40 @@ ircd::fs::path(std::string s)
|
|||
// fs/support.h
|
||||
//
|
||||
|
||||
bool
|
||||
ircd::fs::support::fallocate(const string_view &path,
|
||||
const write_opts &wopts)
|
||||
try
|
||||
{
|
||||
const fd::opts opts
|
||||
{
|
||||
std::ios::out
|
||||
};
|
||||
|
||||
fs::fd fd
|
||||
{
|
||||
path, opts
|
||||
};
|
||||
|
||||
fs::allocate(fd, info::page_size, wopts);
|
||||
return true;
|
||||
}
|
||||
catch(const std::system_error &e)
|
||||
{
|
||||
const auto &ec(e.code());
|
||||
if(system_category(ec)) switch(ec.value())
|
||||
{
|
||||
case int(std::errc::invalid_argument):
|
||||
case int(std::errc::operation_not_supported):
|
||||
return false;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::fs::support::direct_io(const string_view &path)
|
||||
try
|
||||
|
|
Loading…
Reference in a new issue