diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2020-01-08 13:21:32 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2020-01-08 13:21:32 +0300 |
commit | 0b2f33b4855daa733f83a44382603eebbca54d10 (patch) | |
tree | a825917578d7d2d3a2307e7384125326d6e74437 | |
parent | cb9e8e4a5d607cb8157645c87b6a8f423b6b8eff (diff) |
extents() now returns an extent_pair, as per LEWG-I guidance.
-rw-r--r-- | example/use_cases.cpp | 6 | ||||
-rw-r--r-- | include/llfio/v2.0/algorithm/handle_adapter/combining.hpp | 2 | ||||
-rw-r--r-- | include/llfio/v2.0/detail/impl/posix/file_handle.ipp | 4 | ||||
-rw-r--r-- | include/llfio/v2.0/detail/impl/windows/file_handle.ipp | 6 | ||||
-rw-r--r-- | include/llfio/v2.0/fast_random_file_handle.hpp | 2 | ||||
-rw-r--r-- | include/llfio/v2.0/file_handle.hpp | 18 |
6 files changed, 26 insertions, 12 deletions
diff --git a/example/use_cases.cpp b/example/use_cases.cpp index ac632333..62ab7d23 100644 --- a/example/use_cases.cpp +++ b/example/use_cases.cpp @@ -86,7 +86,7 @@ void read_entire_file2() // Get the valid extents of the file. const std::vector< - std::pair<llfio::file_handle::extent_type, llfio::file_handle::extent_type> + llfio::file_handle::extent_pair > valid_extents = fh.extents().value(); // Schedule asynchronous reads for every valid extent @@ -94,13 +94,13 @@ void read_entire_file2() for (size_t n = 0; n < valid_extents.size(); n++) { // Set up the scatter buffer - buffers[n].first.resize(valid_extents[n].second); + buffers[n].first.resize(valid_extents[n].length); for(;;) { llfio::async_file_handle::buffer_type scatter_req{ buffers[n].first.data(), buffers[n].first.size() }; // buffer to fill auto ret = llfio::async_read( // fh, // handle to read from - { { scatter_req }, valid_extents[n].first }, // The scatter request buffers + offset + { { scatter_req }, valid_extents[n].offset }, // The scatter request buffers + offset []( // The completion handler llfio::async_file_handle *, // The parent handle llfio::async_file_handle::io_result<llfio::async_file_handle::buffers_type> && // Result of the i/o diff --git a/include/llfio/v2.0/algorithm/handle_adapter/combining.hpp b/include/llfio/v2.0/algorithm/handle_adapter/combining.hpp index 73b935ec..6f18ffc1 100644 --- a/include/llfio/v2.0/algorithm/handle_adapter/combining.hpp +++ b/include/llfio/v2.0/algorithm/handle_adapter/combining.hpp @@ -434,7 +434,7 @@ namespace algorithm return ret; } //! \brief Always returns a failed matching `errc::operation_not_supported` as the meaning of combined valid extents is hard to discern here. - LLFIO_HEADERS_ONLY_VIRTUAL_SPEC result<std::vector<std::pair<extent_type, extent_type>>> extents() const noexcept override { return errc::operation_not_supported; } + LLFIO_HEADERS_ONLY_VIRTUAL_SPEC result<std::vector<file_handle::extent_pair>> extents() const noexcept override { return errc::operation_not_supported; } //! \brief Punches a hole in one or both attached handles. Note that no combination operation is performed. LLFIO_HEADERS_ONLY_VIRTUAL_SPEC result<extent_type> zero(extent_type offset, extent_type bytes, deadline d = deadline()) noexcept override { diff --git a/include/llfio/v2.0/detail/impl/posix/file_handle.ipp b/include/llfio/v2.0/detail/impl/posix/file_handle.ipp index 2246a627..070fef1c 100644 --- a/include/llfio/v2.0/detail/impl/posix/file_handle.ipp +++ b/include/llfio/v2.0/detail/impl/posix/file_handle.ipp @@ -330,12 +330,12 @@ result<file_handle::extent_type> file_handle::truncate(file_handle::extent_type return newsize; } -result<std::vector<std::pair<file_handle::extent_type, file_handle::extent_type>>> file_handle::extents() const noexcept +result<std::vector<file_handle::extent_pair>> file_handle::extents() const noexcept { LLFIO_LOG_FUNCTION_CALL(this); try { - std::vector<std::pair<file_handle::extent_type, file_handle::extent_type>> out; + std::vector<file_handle::extent_pair> out; out.reserve(64); extent_type start = 0, end = 0; for(;;) diff --git a/include/llfio/v2.0/detail/impl/windows/file_handle.ipp b/include/llfio/v2.0/detail/impl/windows/file_handle.ipp index e646fcd0..ad6b0138 100644 --- a/include/llfio/v2.0/detail/impl/windows/file_handle.ipp +++ b/include/llfio/v2.0/detail/impl/windows/file_handle.ipp @@ -338,15 +338,15 @@ result<file_handle::extent_type> file_handle::truncate(file_handle::extent_type return newsize; } -result<std::vector<std::pair<file_handle::extent_type, file_handle::extent_type>>> file_handle::extents() const noexcept +result<std::vector<file_handle::extent_pair>> file_handle::extents() const noexcept { windows_nt_kernel::init(); using namespace windows_nt_kernel; LLFIO_LOG_FUNCTION_CALL(this); try { - static_assert(sizeof(std::pair<file_handle::extent_type, file_handle::extent_type>) == sizeof(FILE_ALLOCATED_RANGE_BUFFER), "FILE_ALLOCATED_RANGE_BUFFER is not equivalent to pair<extent_type, extent_type>!"); - std::vector<std::pair<file_handle::extent_type, file_handle::extent_type>> ret; + static_assert(sizeof(file_handle::extent_pair) == sizeof(FILE_ALLOCATED_RANGE_BUFFER), "FILE_ALLOCATED_RANGE_BUFFER is not equivalent to pair<extent_type, extent_type>!"); + std::vector<file_handle::extent_pair> ret; #ifdef NDEBUG ret.resize(64); #else diff --git a/include/llfio/v2.0/fast_random_file_handle.hpp b/include/llfio/v2.0/fast_random_file_handle.hpp index 2e214255..e1c2049b 100644 --- a/include/llfio/v2.0/fast_random_file_handle.hpp +++ b/include/llfio/v2.0/fast_random_file_handle.hpp @@ -225,7 +225,7 @@ public: } //! \brief Return a single extent of the maximum extent - LLFIO_HEADERS_ONLY_VIRTUAL_SPEC result<std::vector<std::pair<extent_type, extent_type>>> extents() const noexcept override { return std::vector<std::pair<extent_type, extent_type>>{{0, _length}}; } + LLFIO_HEADERS_ONLY_VIRTUAL_SPEC result<std::vector<file_handle::extent_pair>> extents() const noexcept override { return std::vector<file_handle::extent_pair>{{0, _length}}; } using file_handle::read; diff --git a/include/llfio/v2.0/file_handle.hpp b/include/llfio/v2.0/file_handle.hpp index 747fdf8a..6e37741b 100644 --- a/include/llfio/v2.0/file_handle.hpp +++ b/include/llfio/v2.0/file_handle.hpp @@ -291,13 +291,27 @@ public: LLFIO_MAKE_FREE_FUNCTION LLFIO_HEADERS_ONLY_VIRTUAL_SPEC result<extent_type> truncate(extent_type newsize) noexcept; + //! \brief A pair of valid extents + struct extent_pair + { + extent_type offset{(extent_type) -1}; //!< The offset of where the valid extent begins + extent_type length{(extent_type) -1}; //!< The number of valid bytes in the valid extent + + constexpr extent_pair() {} + constexpr extent_pair(extent_type _offset, extent_type _length) + : offset(_offset) + , length(_length) + { + } + }; + /*! \brief Returns a list of currently valid extents for this open file. WARNING: racy! \return A vector of pairs of extent offset + extent length representing the valid extents in this file. Filing systems which do not support extents return a single extent matching the length of the file rather than returning an error. */ LLFIO_MAKE_FREE_FUNCTION - LLFIO_HEADERS_ONLY_VIRTUAL_SPEC result<std::vector<std::pair<extent_type, extent_type>>> extents() const noexcept; + LLFIO_HEADERS_ONLY_VIRTUAL_SPEC result<std::vector<extent_pair>> extents() const noexcept; /*! \brief Efficiently zero, and possibly deallocate, data on storage. @@ -432,7 +446,7 @@ inline result<file_handle::extent_type> truncate(file_handle &self, file_handle: } /*! \brief Returns a list of currently valid extents for this open file. WARNING: racy! */ -inline result<std::vector<std::pair<file_handle::extent_type, file_handle::extent_type>>> extents(const file_handle &self) noexcept +inline result<std::vector<file_handle::extent_pair>> extents(const file_handle &self) noexcept { return self.extents(); } |