File tree Expand file tree Collapse file tree 5 files changed +37
-0
lines changed
Expand file tree Collapse file tree 5 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -487,6 +487,7 @@ public:
487487 return file_accessible (pathname, access_flags::exists);
488488 }
489489 future<fs_type> file_system_at (std::string_view pathname) noexcept ;
490+ future<std::filesystem::space_info> file_system_space (std::string_view pathname) noexcept ;
490491 future<struct statvfs > statvfs (std::string_view pathname) noexcept ;
491492 future<> remove_file (std::string_view pathname) noexcept ;
492493 future<> rename_file (std::string_view old_pathname, std::string_view new_pathname) noexcept ;
Original file line number Diff line number Diff line change @@ -445,6 +445,11 @@ future<uint64_t> fs_avail(std::string_view name) noexcept;
445445future<uint64_t > fs_free (std::string_view name) noexcept ;
446446// / @}
447447
448+ // / Return filesystem-wide space_info where a file is located.
449+ // /
450+ // / \param name name of the file in the filesystem to inspect
451+ future<std::filesystem::space_info> file_system_space (std::string_view name) noexcept ;
452+
448453namespace experimental {
449454// / \defgroup interprocess-module Interprocess Communication
450455// /
Original file line number Diff line number Diff line change @@ -2263,6 +2263,17 @@ reactor::fstatfs(int fd) noexcept {
22632263 });
22642264}
22652265
2266+ future<std::filesystem::space_info>
2267+ reactor::file_system_space (std::string_view pathname) noexcept {
2268+ auto sr = co_await _thread_pool->submit <syscall_result_extra<std::filesystem::space_info>>([path = std::filesystem::path (pathname)] {
2269+ std::error_code ec;
2270+ auto si = std::filesystem::space (path, ec);
2271+ return wrap_syscall (ec.value (), si);
2272+ });
2273+ sr.throw_fs_exception_if_error (" std::filesystem::space failed" , sstring (pathname));
2274+ co_return sr.extra ;
2275+ }
2276+
22662277future<struct statvfs >
22672278reactor::statvfs (std::string_view pathname) noexcept {
22682279 // Allocating memory for a sstring can throw, hence the futurize_invoke
Original file line number Diff line number Diff line change @@ -128,6 +128,10 @@ future<uint64_t> fs_free(std::string_view name) noexcept {
128128 });
129129}
130130
131+ future<std::filesystem::space_info> file_system_space (std::string_view name) noexcept {
132+ return engine ().file_system_space (name);
133+ }
134+
131135future<stat_data> file_stat (std::string_view name, follow_symlink follow) noexcept {
132136 return engine ().file_stat (name, follow);
133137}
Original file line number Diff line number Diff line change 1919 * Copyright (C) 2014-2015 Cloudius Systems, Ltd.
2020 */
2121
22+ #include < filesystem>
23+
2224#include < seastar/testing/random.hh>
2325#include < seastar/testing/test_case.hh>
2426#include < seastar/testing/thread_test_case.hh>
2527#include < seastar/testing/test_runner.hh>
2628
29+ #include < seastar/core/reactor.hh>
2730#include < seastar/core/seastar.hh>
2831#include < seastar/core/semaphore.hh>
2932#include < seastar/core/condition-variable.hh>
@@ -947,3 +950,16 @@ SEASTAR_TEST_CASE(test_oversized_io_works) {
947950 BOOST_REQUIRE ((size_t )std::count_if (buf.get (), buf.get () + buf_size, [](auto x) { return x == ' a' ; }) == buf_size);
948951 });
949952}
953+
954+ SEASTAR_TEST_CASE (test_file_system_space) {
955+ return tmp_dir::do_with_thread ([] (tmp_dir& t) {
956+ const auto & name = t.get_path ().native ();
957+ auto st = engine ().statvfs (name).get ();
958+ auto si = file_system_space (name).get ();
959+
960+ BOOST_REQUIRE_EQUAL (st.f_blocks * st.f_frsize , si.capacity );
961+ BOOST_REQUIRE_LT (si.free , si.capacity );
962+ BOOST_REQUIRE_LT (si.available , si.capacity );
963+ BOOST_REQUIRE_LE (si.available , si.free );
964+ });
965+ }
You can’t perform that action at this time.
0 commit comments