0
0
Fork 0
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:
Jason Volk 2018-12-03 12:58:42 -08:00
parent 47d6fbb35f
commit 24e423c714
2 changed files with 37 additions and 0 deletions

View file

@ -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);
}

View file

@ -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