Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ned14/llfio.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com>2022-04-16 02:21:55 +0300
committerNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com>2022-04-16 02:21:55 +0300
commit07abc401301fb4b538a152772c94437c3c5d205e (patch)
tree7dd195e5bb19b52a3e90ec352bc8ab0017502f2a
parent5c6f7f3933de89fb4e4a9aa7df69da933a8f09aa (diff)
parentc2b5e6abe44614341e563353c907126683548346 (diff)
Merge branch 'develop' into networking
-rw-r--r--include/llfio/revision.hpp6
-rw-r--r--include/llfio/v2.0/algorithm/handle_adapter/combining.hpp66
-rw-r--r--include/llfio/v2.0/byte_io_handle.hpp4
-rw-r--r--include/llfio/v2.0/byte_socket_handle.hpp8
-rw-r--r--include/llfio/v2.0/detail/impl/posix/byte_socket_handle.ipp6
-rw-r--r--include/llfio/v2.0/detail/impl/posix/directory_handle.ipp6
-rw-r--r--include/llfio/v2.0/detail/impl/posix/file_handle.ipp6
-rw-r--r--include/llfio/v2.0/detail/impl/posix/handle.ipp4
-rw-r--r--include/llfio/v2.0/detail/impl/posix/import.hpp104
-rw-r--r--include/llfio/v2.0/detail/impl/posix/pipe_handle.ipp4
-rw-r--r--include/llfio/v2.0/detail/impl/posix/process_handle.ipp28
-rw-r--r--include/llfio/v2.0/detail/impl/windows/byte_socket_handle.ipp6
-rw-r--r--include/llfio/v2.0/detail/impl/windows/directory_handle.ipp10
-rw-r--r--include/llfio/v2.0/detail/impl/windows/file_handle.ipp6
-rw-r--r--include/llfio/v2.0/detail/impl/windows/fs_handle.ipp2
-rw-r--r--include/llfio/v2.0/detail/impl/windows/handle.ipp4
-rw-r--r--include/llfio/v2.0/detail/impl/windows/import.hpp39
-rw-r--r--include/llfio/v2.0/detail/impl/windows/path_handle.ipp2
-rw-r--r--include/llfio/v2.0/detail/impl/windows/pipe_handle.ipp4
-rw-r--r--include/llfio/v2.0/detail/impl/windows/process_handle.ipp21
-rw-r--r--include/llfio/v2.0/directory_handle.hpp8
-rw-r--r--include/llfio/v2.0/file_handle.hpp8
-rw-r--r--include/llfio/v2.0/handle.hpp42
-rw-r--r--include/llfio/v2.0/lockable_byte_io_handle.hpp4
-rw-r--r--include/llfio/v2.0/map_handle.hpp2
-rw-r--r--include/llfio/v2.0/native_handle_type.hpp4
-rw-r--r--include/llfio/v2.0/path_handle.hpp4
-rw-r--r--include/llfio/v2.0/pipe_handle.hpp8
-rw-r--r--include/llfio/v2.0/symlink_handle.hpp2
-rw-r--r--include/llfio/v2.0/tls_socket_handle.hpp2
30 files changed, 225 insertions, 195 deletions
diff --git a/include/llfio/revision.hpp b/include/llfio/revision.hpp
index 98d2c016..aac0b15c 100644
--- a/include/llfio/revision.hpp
+++ b/include/llfio/revision.hpp
@@ -1,4 +1,4 @@
// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
-#define LLFIO_PREVIOUS_COMMIT_REF 669fa32e84aee81710740a6f17edf010b60fe3ab
-#define LLFIO_PREVIOUS_COMMIT_DATE "2022-04-13 09:36:54 +00:00"
-#define LLFIO_PREVIOUS_COMMIT_UNIQUE 669fa32e
+#define LLFIO_PREVIOUS_COMMIT_REF 5c6f7f3933de89fb4e4a9aa7df69da933a8f09aa
+#define LLFIO_PREVIOUS_COMMIT_DATE "2022-04-15 23:08:23 +00:00"
+#define LLFIO_PREVIOUS_COMMIT_UNIQUE 5c6f7f39
diff --git a/include/llfio/v2.0/algorithm/handle_adapter/combining.hpp b/include/llfio/v2.0/algorithm/handle_adapter/combining.hpp
index 538cc59e..444c30af 100644
--- a/include/llfio/v2.0/algorithm/handle_adapter/combining.hpp
+++ b/include/llfio/v2.0/algorithm/handle_adapter/combining.hpp
@@ -40,8 +40,8 @@ namespace algorithm
{
file_handle_wrapper() = default;
using file_handle::file_handle;
- file_handle_wrapper(native_handle_type nativeh, byte_io_handle::caching _caching, byte_io_handle::flag flags, byte_io_multiplexer *ctx)
- : file_handle(nativeh, 0, 0, _caching, flags, ctx)
+ file_handle_wrapper(native_handle_type nativeh, byte_io_handle::flag flags, byte_io_multiplexer *ctx)
+ : file_handle(nativeh, 0, 0, flags, ctx)
{
}
};
@@ -49,17 +49,20 @@ namespace algorithm
using combining_handle_adapter_choose_base = std::conditional_t< //
std::is_base_of<file_handle, Target>::value && (std::is_void<Source>::value || std::is_base_of<file_handle, Source>::value), //
file_handle_wrapper, //
- byte_io_handle //
+ byte_io_handle //
>;
template <class A, class B> struct is_void_or_io_request_compatible
{
- static constexpr bool value = std::is_same<typename A::template io_request<typename A::buffers_type>, typename B::template io_request<typename B::buffers_type>>::value;
+ static constexpr bool value =
+ std::is_same<typename A::template io_request<typename A::buffers_type>, typename B::template io_request<typename B::buffers_type>>::value;
};
template <class T> struct is_void_or_io_request_compatible<T, void> : std::true_type
{
};
- template <template <class, class> class Op, class Target, class Source, class Base, bool with_file_handle_base = std::is_same<Base, file_handle_wrapper>::value> class combining_handle_adapter_base : public Base
+ template <template <class, class> class Op, class Target, class Source, class Base,
+ bool with_file_handle_base = std::is_same<Base, file_handle_wrapper>::value>
+ class combining_handle_adapter_base : public Base
{
static_assert(is_void_or_io_request_compatible<Target, Source>::value, "Combined handle types do not share io_request<buffers_type>");
@@ -89,7 +92,7 @@ namespace algorithm
_source_handle_type *_source{nullptr};
private:
- static constexpr native_handle_type _native_handle(mode _mode)
+ static constexpr native_handle_type _native_handle(mode _mode, native_handle_type::disposition a, native_handle_type::disposition b)
{
native_handle_type nativeh;
nativeh.behaviour |= native_handle_type::disposition::file;
@@ -98,31 +101,21 @@ namespace algorithm
{
nativeh.behaviour |= native_handle_type::disposition::writable;
}
+ nativeh.behaviour |= ((a & native_handle_type::disposition::_cache_bits) & (b & native_handle_type::disposition::_cache_bits));
+ // safety_barriers is on only if it was on in both, is that wise?
return nativeh;
}
- static constexpr caching _combine_caching(target_handle_type *a, _source_handle_type *b)
- {
- caching _a = a->kernel_caching();
- caching _b = b->kernel_caching();
- caching least = caching::none;
- if(_a < _b)
- least = _a;
- else
- least = _b;
- // TODO: Bit 0 set means safety fsyncs on, should I reflect this?
- return least;
- }
protected:
combining_handle_adapter_base() = default;
constexpr combining_handle_adapter_base(target_handle_type *a, _source_handle_type *b, mode _mode, flag flags, byte_io_multiplexer *ctx)
- : Base(_native_handle(_mode), _combine_caching(a, b), flags, ctx)
+ : Base(_native_handle(_mode, a->native_handle().behaviour, b->native_handle().behaviour), flags, ctx)
, _target(a)
, _source(b)
{
}
combining_handle_adapter_base(target_handle_type *a, void *b, mode _mode, flag flags, byte_io_multiplexer *ctx)
- : Base(_native_handle(_mode), a->caching(), flags, ctx)
+ : Base(_native_handle(_mode, a->native_handle().behaviour, ~native_handle_type::disposition::invalid), flags, ctx)
, _target(a)
, _source(reinterpret_cast<_source_handle_type *>(b))
{
@@ -144,8 +137,7 @@ namespace algorithm
return success();
}
- protected:
-
+ protected:
//! \brief Return the lowest of the two handles' maximum buffers
LLFIO_HEADERS_ONLY_VIRTUAL_SPEC size_t _do_max_buffers() const noexcept override
{
@@ -173,7 +165,8 @@ namespace algorithm
bytes += b.size();
}
// If less than page size, use stack, else use free pages
- buffer_type buffers[2] = {{(byte *) ((bytes <= utils::page_size()) ? alloca(bytes + 64) : nullptr), bytes}, {(byte *) ((_have_source && bytes <= utils::page_size()) ? alloca(bytes + 64) : nullptr), bytes}};
+ buffer_type buffers[2] = {{(byte *) ((bytes <= utils::page_size()) ? alloca(bytes + 64) : nullptr), bytes},
+ {(byte *) ((_have_source && bytes <= utils::page_size()) ? alloca(bytes + 64) : nullptr), bytes}};
map_handle buffersh;
if(buffers[0].data() != nullptr)
{
@@ -250,7 +243,8 @@ namespace algorithm
bytes += b.size();
}
// If less than page size, use stack, else use free pages
- buffer_type buffers[2] = {{(byte *) ((bytes <= utils::page_size()) ? alloca(bytes + 64) : nullptr), bytes}, {(byte *) ((_have_source && bytes <= utils::page_size()) ? alloca(bytes + 64) : nullptr), bytes}};
+ buffer_type buffers[2] = {{(byte *) ((bytes <= utils::page_size()) ? alloca(bytes + 64) : nullptr), bytes},
+ {(byte *) ((_have_source && bytes <= utils::page_size()) ? alloca(bytes + 64) : nullptr), bytes}};
map_handle buffersh;
if(buffers[0].data() != nullptr)
{
@@ -307,7 +301,9 @@ namespace algorithm
public:
};
- template <template <class, class> class Op, class Target, class Source> class combining_handle_adapter_base<Op, Target, Source, file_handle_wrapper, true> : public combining_handle_adapter_base<Op, Target, Source, file_handle_wrapper, false>
+ template <template <class, class> class Op, class Target, class Source>
+ class combining_handle_adapter_base<Op, Target, Source, file_handle_wrapper, true>
+ : public combining_handle_adapter_base<Op, Target, Source, file_handle_wrapper, false>
{
using _base = combining_handle_adapter_base<Op, Target, Source, file_handle_wrapper, false>;
@@ -347,7 +343,8 @@ namespace algorithm
public:
//! \brief Lock the given extent in one or both of the attached handles. Any second handle is always locked for shared.
- LLFIO_HEADERS_ONLY_VIRTUAL_SPEC result<extent_guard> lock_file_range(extent_type offset, extent_type bytes, lock_kind kind, deadline d = deadline()) noexcept override
+ LLFIO_HEADERS_ONLY_VIRTUAL_SPEC result<extent_guard> lock_file_range(extent_type offset, extent_type bytes, lock_kind kind,
+ deadline d = deadline()) noexcept override
{
optional<result<extent_guard>> _locks[2];
#if !defined(LLFIO_DISABLE_OPENMP) && defined(_OPENMP)
@@ -470,7 +467,7 @@ namespace algorithm
return ret;
}
};
- }
+ } // namespace detail
/*! \class combining_handle_adapter
\brief A handle combining the data from one or two other handles.
@@ -536,9 +533,12 @@ namespace algorithm
\todo I have been lazy and used public inheritance from `byte_io_handle` and `file_handle`.
I should use protected inheritance to prevent slicing, and expose all the public functions by hand.
*/
- template <template <class, class> class Op, class Target, class Source> class combining_handle_adapter : public Op<Target, Source>::template override_<detail::combining_handle_adapter_base<Op, Target, Source, detail::combining_handle_adapter_choose_base<Target, Source>>>
+ template <template <class, class> class Op, class Target, class Source>
+ class combining_handle_adapter : public Op<Target, Source>::template override_<
+ detail::combining_handle_adapter_base<Op, Target, Source, detail::combining_handle_adapter_choose_base<Target, Source>>>
{
- using _base = typename Op<Target, Source>::template override_<detail::combining_handle_adapter_base<Op, Target, Source, detail::combining_handle_adapter_choose_base<Target, Source>>>;
+ using _base = typename Op<Target, Source>::template override_<
+ detail::combining_handle_adapter_base<Op, Target, Source, detail::combining_handle_adapter_choose_base<Target, Source>>>;
public:
using path_type = byte_io_handle::path_type;
@@ -563,13 +563,17 @@ namespace algorithm
combining_handle_adapter() = default;
//! Constructor, passing any extra arguments to `Op::override`.
template <class... Args>
- combining_handle_adapter(target_handle_type *a, source_handle_type *b, mode _mode = mode::write, flag flags = flag::none, byte_io_multiplexer *ctx = nullptr, Args &&... args)
+ combining_handle_adapter(target_handle_type *a, source_handle_type *b, mode _mode = mode::write, flag flags = flag::none,
+ byte_io_multiplexer *ctx = nullptr, Args &&...args)
: _base(a, b, _mode, flags, ctx, std::forward<Args>(args)...)
{
}
//! Implicit move construction of combining_handle_adapter permitted
- combining_handle_adapter(combining_handle_adapter &&o) noexcept : _base(std::move(o)) {}
+ combining_handle_adapter(combining_handle_adapter &&o) noexcept
+ : _base(std::move(o))
+ {
+ }
//! No copy construction (use `clone()`)
combining_handle_adapter(const combining_handle_adapter &) = delete;
//! Move assignment of combining_handle_adapter permitted
diff --git a/include/llfio/v2.0/byte_io_handle.hpp b/include/llfio/v2.0/byte_io_handle.hpp
index 43c27b34..c60396f2 100644
--- a/include/llfio/v2.0/byte_io_handle.hpp
+++ b/include/llfio/v2.0/byte_io_handle.hpp
@@ -69,8 +69,8 @@ public:
constexpr byte_io_handle() {} // NOLINT
~byte_io_handle() = default;
//! Construct a handle from a supplied native handle
- constexpr explicit byte_io_handle(native_handle_type h, caching caching, flag flags, byte_io_multiplexer *ctx)
- : handle(h, caching, flags)
+ constexpr explicit byte_io_handle(native_handle_type h, flag flags, byte_io_multiplexer *ctx)
+ : handle(h, flags)
, _ctx(ctx)
{
}
diff --git a/include/llfio/v2.0/byte_socket_handle.hpp b/include/llfio/v2.0/byte_socket_handle.hpp
index f9c215a8..3615c5b4 100644
--- a/include/llfio/v2.0/byte_socket_handle.hpp
+++ b/include/llfio/v2.0/byte_socket_handle.hpp
@@ -451,8 +451,8 @@ public:
//! Default constructor
constexpr byte_socket_handle() {} // NOLINT
//! Construct a handle from a supplied native handle
- constexpr byte_socket_handle(native_handle_type h, caching caching, flag flags, byte_io_multiplexer *ctx)
- : byte_io_handle(std::move(h), caching, flags, ctx)
+ constexpr byte_socket_handle(native_handle_type h, flag flags, byte_io_multiplexer *ctx)
+ : byte_io_handle(std::move(h), flags, ctx)
{
#ifdef _WIN32
if(_v)
@@ -880,8 +880,8 @@ public:
//! Default constructor
constexpr listening_byte_socket_handle() {} // NOLINT
//! Construct a handle from a supplied native handle
- constexpr listening_byte_socket_handle(native_handle_type h, caching caching, flag flags, byte_io_multiplexer *ctx)
- : _base(std::move(h), caching, flags)
+ constexpr listening_byte_socket_handle(native_handle_type h, flag flags, byte_io_multiplexer *ctx)
+ : _base(std::move(h), flags)
, _ctx(ctx)
{
#ifdef _WIN32
diff --git a/include/llfio/v2.0/detail/impl/posix/byte_socket_handle.ipp b/include/llfio/v2.0/detail/impl/posix/byte_socket_handle.ipp
index 0dc70f73..d0cd604f 100644
--- a/include/llfio/v2.0/detail/impl/posix/byte_socket_handle.ipp
+++ b/include/llfio/v2.0/detail/impl/posix/byte_socket_handle.ipp
@@ -647,7 +647,7 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<void> byte_socket_handle::_do_connect(con
LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<byte_socket_handle> byte_socket_handle::byte_socket(ip::family family, mode _mode, caching _caching, flag flags) noexcept
{
- result<byte_socket_handle> ret(byte_socket_handle(native_handle_type(), _caching, flags, nullptr));
+ result<byte_socket_handle> ret(byte_socket_handle(native_handle_type(), flags, nullptr));
native_handle_type &nativeh = ret.value()._v;
LLFIO_LOG_FUNCTION_CALL(&ret);
OUTCOME_TRY(detail::create_socket(nativeh, family, _mode, _caching, flags));
@@ -728,7 +728,7 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<void> listening_byte_socket_handle::bind(
LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<listening_byte_socket_handle> listening_byte_socket_handle::listening_byte_socket(ip::family family, mode _mode, caching _caching,
flag flags) noexcept
{
- result<listening_byte_socket_handle> ret(listening_byte_socket_handle(native_handle_type(), _caching, flags, nullptr));
+ result<listening_byte_socket_handle> ret(listening_byte_socket_handle(native_handle_type(), flags, nullptr));
native_handle_type &nativeh = ret.value()._v;
OUTCOME_TRY(detail::create_socket(nativeh, family, _mode, _caching, flags));
return ret;
@@ -826,7 +826,7 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<listening_byte_socket_handle::buffers_typ
}
}
}
- b.first = byte_socket_handle(nativeh, _caching, _.flags, _ctx);
+ b.first = byte_socket_handle(nativeh, _.flags, _ctx);
if(_mode == mode::read)
{
OUTCOME_TRY(b.first.shutdown(byte_socket_handle::shutdown_write));
diff --git a/include/llfio/v2.0/detail/impl/posix/directory_handle.ipp b/include/llfio/v2.0/detail/impl/posix/directory_handle.ipp
index 8ab06ebc..f8483b3b 100644
--- a/include/llfio/v2.0/detail/impl/posix/directory_handle.ipp
+++ b/include/llfio/v2.0/detail/impl/posix/directory_handle.ipp
@@ -46,7 +46,7 @@ result<directory_handle> directory_handle::directory(const path_handle &base, pa
{
return errc::invalid_argument;
}
- result<directory_handle> ret(directory_handle(native_handle_type(), 0, 0, _caching, flags));
+ result<directory_handle> ret(directory_handle(native_handle_type(), 0, 0, flags));
native_handle_type &nativeh = ret.value()._v;
LLFIO_LOG_FUNCTION_CALL(&ret);
nativeh.behaviour |= native_handle_type::disposition::directory | native_handle_type::disposition::path | native_handle_type::disposition::kernel_handle;
@@ -182,7 +182,7 @@ result<directory_handle> directory_handle::reopen(mode mode_, caching caching_,
// Fast path
if(mode_ == mode::unchanged && caching_ == caching::unchanged)
{
- result<directory_handle> ret(directory_handle(native_handle_type(), _devid, _inode, kernel_caching(), _.flags));
+ result<directory_handle> ret(directory_handle(native_handle(), _devid, _inode, _.flags));
ret.value()._v.behaviour = _v.behaviour;
ret.value()._v.fd = ::fcntl(_v.fd, F_DUPFD_CLOEXEC, 0);
if(-1 == ret.value()._v.fd)
@@ -249,7 +249,7 @@ result<directory_handle> directory_handle::reopen(mode mode_, caching caching_,
LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<path_handle> directory_handle::clone_to_path_handle() const noexcept
{
LLFIO_LOG_FUNCTION_CALL(this);
- result<path_handle> ret(path_handle(native_handle_type(), kernel_caching(), _.flags));
+ result<path_handle> ret(path_handle(native_handle(), _.flags));
ret.value()._v.behaviour = _v.behaviour;
ret.value()._v.fd = ::fcntl(_v.fd, F_DUPFD_CLOEXEC, 0);
if(-1 == ret.value()._v.fd)
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 035ca4e1..e25c2e47 100644
--- a/include/llfio/v2.0/detail/impl/posix/file_handle.ipp
+++ b/include/llfio/v2.0/detail/impl/posix/file_handle.ipp
@@ -44,7 +44,7 @@ LLFIO_V2_NAMESPACE_BEGIN
result<file_handle> file_handle::file(const path_handle &base, file_handle::path_view_type path, file_handle::mode _mode, file_handle::creation _creation,
file_handle::caching _caching, file_handle::flag flags) noexcept
{
- result<file_handle> ret(file_handle(native_handle_type(), 0, 0, _caching, flags, nullptr));
+ result<file_handle> ret(file_handle(native_handle_type(), 0, 0, flags, nullptr));
native_handle_type &nativeh = ret.value()._v;
LLFIO_LOG_FUNCTION_CALL(&ret);
nativeh.behaviour |= native_handle_type::disposition::file | native_handle_type::disposition::kernel_handle;
@@ -118,7 +118,7 @@ result<file_handle> file_handle::temp_inode(const path_handle &dirh, mode _mode,
caching _caching = caching::temporary;
// No need to check inode before unlink
flags |= flag::unlink_on_first_close | flag::disable_safety_unlinks;
- result<file_handle> ret(file_handle(native_handle_type(), 0, 0, _caching, flags, nullptr));
+ result<file_handle> ret(file_handle(native_handle_type(), 0, 0, flags, nullptr));
native_handle_type &nativeh = ret.value()._v;
LLFIO_LOG_FUNCTION_CALL(&ret);
nativeh.behaviour |= native_handle_type::disposition::file | native_handle_type::disposition::kernel_handle;
@@ -178,7 +178,7 @@ result<file_handle> file_handle::reopen(mode mode_, caching caching_, deadline d
// Fast path
if(mode_ == mode::unchanged)
{
- result<file_handle> ret(file_handle(native_handle_type(), _devid, _inode, caching_, _.flags, _ctx));
+ result<file_handle> ret(file_handle(native_handle(), _devid, _inode, _.flags, _ctx));
ret.value()._v.behaviour = _v.behaviour;
ret.value()._v.fd = ::fcntl(_v.fd, F_DUPFD_CLOEXEC, 0);
if(-1 == ret.value()._v.fd)
diff --git a/include/llfio/v2.0/detail/impl/posix/handle.ipp b/include/llfio/v2.0/detail/impl/posix/handle.ipp
index 1a197ddf..3cadd4d4 100644
--- a/include/llfio/v2.0/detail/impl/posix/handle.ipp
+++ b/include/llfio/v2.0/detail/impl/posix/handle.ipp
@@ -1,5 +1,5 @@
/* A handle to something
-(C) 2015-2017 Niall Douglas <http://www.nedproductions.biz/> (11 commits)
+(C) 2015-2022 Niall Douglas <http://www.nedproductions.biz/> (11 commits)
File Created: Dec 2015
@@ -161,7 +161,7 @@ result<void> handle::close() noexcept
result<handle> handle::clone() const noexcept
{
LLFIO_LOG_FUNCTION_CALL(this);
- result<handle> ret(handle(native_handle_type(), kernel_caching(), _.flags));
+ result<handle> ret(handle(native_handle_type(), _.flags));
ret.value()._v.behaviour = _v.behaviour;
ret.value()._v.fd = ::fcntl(_v.fd, F_DUPFD_CLOEXEC, 0);
if(-1 == ret.value()._v.fd)
diff --git a/include/llfio/v2.0/detail/impl/posix/import.hpp b/include/llfio/v2.0/detail/impl/posix/import.hpp
index 753589b9..1d21a765 100644
--- a/include/llfio/v2.0/detail/impl/posix/import.hpp
+++ b/include/llfio/v2.0/detail/impl/posix/import.hpp
@@ -36,7 +36,8 @@ Distributed under the Boost Software License, Version 1.0.
LLFIO_V2_NAMESPACE_BEGIN
-inline result<int> attribs_from_handle_mode_caching_and_flags(native_handle_type &nativeh, handle::mode _mode, handle::creation _creation, handle::caching _caching, handle::flag flags) noexcept
+inline result<int> attribs_from_handle_mode_caching_and_flags(native_handle_type &nativeh, handle::mode _mode, handle::creation _creation,
+ handle::caching _caching, handle::flag flags) noexcept
{
int attribs = O_CLOEXEC;
switch(_mode)
@@ -88,16 +89,17 @@ inline result<int> attribs_from_handle_mode_caching_and_flags(native_handle_type
#else
;
#endif
- nativeh.behaviour |= native_handle_type::disposition::aligned_io;
+ nativeh.behaviour |= native_handle_type::disposition::aligned_io | native_handle_type::disposition::safety_barriers;
break;
case handle::caching::only_metadata:
#ifdef O_DIRECT
attribs |= O_DIRECT;
#endif
- nativeh.behaviour |= native_handle_type::disposition::aligned_io;
+ nativeh.behaviour |= native_handle_type::disposition::aligned_io | native_handle_type::disposition::cache_metadata;
break;
case handle::caching::reads:
attribs |= O_SYNC;
+ nativeh.behaviour |= native_handle_type::disposition::cache_reads | native_handle_type::disposition::safety_barriers;
break;
case handle::caching::reads_and_metadata:
#ifdef O_DSYNC
@@ -105,10 +107,20 @@ inline result<int> attribs_from_handle_mode_caching_and_flags(native_handle_type
#else
attribs |= O_SYNC;
#endif
+ nativeh.behaviour |=
+ native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_metadata | native_handle_type::disposition::safety_barriers;
break;
case handle::caching::all:
+ nativeh.behaviour |=
+ native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes | native_handle_type::disposition::cache_metadata;
+ break;
case handle::caching::safety_barriers:
+ nativeh.behaviour |= native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes |
+ native_handle_type::disposition::cache_metadata | native_handle_type::disposition::safety_barriers;
+ break;
case handle::caching::temporary:
+ nativeh.behaviour |= native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes |
+ native_handle_type::disposition::cache_metadata | native_handle_type::disposition::cache_temporary;
break;
}
if(!!(flags & handle::flag::multiplexable))
@@ -125,55 +137,55 @@ inline result<int> attribs_from_handle_mode_caching_and_flags(native_handle_type
- sleep_interval: Set to the number of steady milliseconds until the sleep must end
- sleep_object: Set to a primed deadline timer HANDLE which will signal when the system clock reaches the deadline
*/
-#define LLFIO_POSIX_DEADLINE_TO_SLEEP_INIT(d) \
- std::chrono::steady_clock::time_point began_steady; \
- struct timespec _timeout \
- { \
- }; \
- memset(&_timeout, 0, sizeof(_timeout)); \
- struct timespec *timeout = nullptr; \
- if(d) \
- { \
- if((d).steady) \
- { \
- began_steady = std::chrono::steady_clock::now(); \
- timeout = &_timeout; \
- } \
- else \
- timeout = &(d).utc; \
+#define LLFIO_POSIX_DEADLINE_TO_SLEEP_INIT(d) \
+ std::chrono::steady_clock::time_point began_steady; \
+ struct timespec _timeout \
+ { \
+ }; \
+ memset(&_timeout, 0, sizeof(_timeout)); \
+ struct timespec *timeout = nullptr; \
+ if(d) \
+ { \
+ if((d).steady) \
+ { \
+ began_steady = std::chrono::steady_clock::now(); \
+ timeout = &_timeout; \
+ } \
+ else \
+ timeout = &(d).utc; \
}
-#define LLFIO_POSIX_DEADLINE_TO_SLEEP_LOOP(d) \
- if((d) && (d).steady) \
- { \
- std::chrono::nanoseconds ns; \
- ns = std::chrono::duration_cast<std::chrono::nanoseconds>((began_steady + std::chrono::nanoseconds((d).nsecs)) - std::chrono::steady_clock::now()); \
- if(ns.count() < 0) \
- { \
- _timeout.tv_sec = 0; \
- _timeout.tv_nsec = 0; \
- } \
- else \
- { \
- _timeout.tv_sec = ns.count() / 1000000000ULL; \
- _timeout.tv_nsec = ns.count() % 1000000000ULL; \
- } \
+#define LLFIO_POSIX_DEADLINE_TO_SLEEP_LOOP(d) \
+ if((d) && (d).steady) \
+ { \
+ std::chrono::nanoseconds ns; \
+ ns = std::chrono::duration_cast<std::chrono::nanoseconds>((began_steady + std::chrono::nanoseconds((d).nsecs)) - std::chrono::steady_clock::now()); \
+ if(ns.count() < 0) \
+ { \
+ _timeout.tv_sec = 0; \
+ _timeout.tv_nsec = 0; \
+ } \
+ else \
+ { \
+ _timeout.tv_sec = ns.count() / 1000000000ULL; \
+ _timeout.tv_nsec = ns.count() % 1000000000ULL; \
+ } \
}
-#define LLFIO_POSIX_DEADLINE_TO_TIMEOUT_LOOP(d) \
- if(d) \
- { \
- if((d).steady) \
- { \
- if(std::chrono::steady_clock::now() >= (began_steady + std::chrono::nanoseconds((d).nsecs))) \
+#define LLFIO_POSIX_DEADLINE_TO_TIMEOUT_LOOP(d) \
+ if(d) \
+ { \
+ if((d).steady) \
+ { \
+ if(std::chrono::steady_clock::now() >= (began_steady + std::chrono::nanoseconds((d).nsecs))) \
return LLFIO_V2_NAMESPACE::failure(LLFIO_V2_NAMESPACE::errc::timed_out); \
- } \
- else \
- { \
- deadline now(std::chrono::system_clock::now()); \
- if(now.utc.tv_sec > (d).utc.tv_sec || (now.utc.tv_sec == (d).utc.tv_sec && now.utc.tv_nsec >= (d).utc.tv_nsec)) \
+ } \
+ else \
+ { \
+ deadline now(std::chrono::system_clock::now()); \
+ if(now.utc.tv_sec > (d).utc.tv_sec || (now.utc.tv_sec == (d).utc.tv_sec && now.utc.tv_nsec >= (d).utc.tv_nsec)) \
return LLFIO_V2_NAMESPACE::failure(LLFIO_V2_NAMESPACE::errc::timed_out); \
- } \
+ } \
}
LLFIO_V2_NAMESPACE_END
diff --git a/include/llfio/v2.0/detail/impl/posix/pipe_handle.ipp b/include/llfio/v2.0/detail/impl/posix/pipe_handle.ipp
index a805cde9..89c882ef 100644
--- a/include/llfio/v2.0/detail/impl/posix/pipe_handle.ipp
+++ b/include/llfio/v2.0/detail/impl/posix/pipe_handle.ipp
@@ -29,7 +29,7 @@ LLFIO_V2_NAMESPACE_BEGIN
result<pipe_handle> pipe_handle::pipe(pipe_handle::path_view_type path, pipe_handle::mode _mode, pipe_handle::creation _creation, pipe_handle::caching _caching, pipe_handle::flag flags, const path_handle &base) noexcept
{
- result<pipe_handle> ret(pipe_handle(native_handle_type(), 0, 0, _caching, flags, nullptr));
+ result<pipe_handle> ret(pipe_handle(native_handle_type(), 0, 0, flags, nullptr));
native_handle_type &nativeh = ret.value()._v;
LLFIO_LOG_FUNCTION_CALL(&ret);
nativeh.behaviour |= native_handle_type::disposition::pipe | native_handle_type::disposition::kernel_handle;
@@ -129,7 +129,7 @@ result<pipe_handle> pipe_handle::pipe(pipe_handle::path_view_type path, pipe_han
result<std::pair<pipe_handle, pipe_handle>> pipe_handle::anonymous_pipe(caching _caching, flag flags) noexcept
{
- result<std::pair<pipe_handle, pipe_handle>> ret(pipe_handle(native_handle_type(), 0, 0, _caching, flags, nullptr), pipe_handle(native_handle_type(), 0, 0, _caching, flags, nullptr));
+ result<std::pair<pipe_handle, pipe_handle>> ret(pipe_handle(native_handle_type(), 0, 0, flags, nullptr), pipe_handle(native_handle_type(), 0, 0, flags, nullptr));
native_handle_type &readnativeh = ret.value().first._v, &writenativeh = ret.value().second._v;
LLFIO_LOG_FUNCTION_CALL(&ret);
OUTCOME_TRY(auto &&readattribs, attribs_from_handle_mode_caching_and_flags(readnativeh, mode::read, creation::open_existing, _caching, flags));
diff --git a/include/llfio/v2.0/detail/impl/posix/process_handle.ipp b/include/llfio/v2.0/detail/impl/posix/process_handle.ipp
index 396aef8a..b6d063c2 100644
--- a/include/llfio/v2.0/detail/impl/posix/process_handle.ipp
+++ b/include/llfio/v2.0/detail/impl/posix/process_handle.ipp
@@ -188,15 +188,28 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC const process_handle &process_handle::current()
{
static process_handle self = []() -> process_handle {
process_handle ret(native_handle_type(native_handle_type::disposition::process, getpid()), flag::release_pipes_on_close);
- ret._in_pipe = pipe_handle(native_handle_type(native_handle_type::disposition::pipe | native_handle_type::disposition::readable, STDIN_FILENO), pipe_handle::caching::all, pipe_handle::flag::none, nullptr);
- ret._out_pipe = pipe_handle(native_handle_type(native_handle_type::disposition::pipe | native_handle_type::disposition::writable, STDOUT_FILENO), pipe_handle::caching::all, pipe_handle::flag::none, nullptr);
- ret._error_pipe = pipe_handle(native_handle_type(native_handle_type::disposition::pipe | native_handle_type::disposition::writable, STDERR_FILENO), pipe_handle::caching::all, pipe_handle::flag::none, nullptr);
+ ret._in_pipe = pipe_handle(native_handle_type(native_handle_type::disposition::pipe | native_handle_type::disposition::readable |
+ native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes |
+ native_handle_type::disposition::cache_metadata,
+ STDIN_FILENO),
+ pipe_handle::flag::none, nullptr);
+ ret._out_pipe = pipe_handle(native_handle_type(native_handle_type::disposition::pipe | native_handle_type::disposition::writable |
+ native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes |
+ native_handle_type::disposition::cache_metadata,
+ STDOUT_FILENO),
+ pipe_handle::flag::none, nullptr);
+ ret._error_pipe = pipe_handle(native_handle_type(native_handle_type::disposition::pipe | native_handle_type::disposition::writable |
+ native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes |
+ native_handle_type::disposition::cache_metadata,
+ STDERR_FILENO),
+ pipe_handle::flag::none, nullptr);
return ret;
}();
return self;
}
-LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<process_handle> process_handle::launch_process(path_view path, span<path_view_component> args, span<path_view_component> env, flag flags) noexcept
+LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<process_handle> process_handle::launch_process(path_view path, span<path_view_component> args,
+ span<path_view_component> env, flag flags) noexcept
{
try
{
@@ -243,7 +256,8 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<process_handle> process_handle::launch_pr
return posix_error();
}
- using small_path_view_c_str = path_view::zero_terminated_rendered_path<filesystem::path::value_type, std::default_delete<filesystem::path::value_type[]>, 1>;
+ using small_path_view_c_str =
+ path_view::zero_terminated_rendered_path<filesystem::path::value_type, std::default_delete<filesystem::path::value_type[]>, 1>;
std::vector<const char *> argptrs(args.size() + 2);
std::vector<small_path_view_c_str> _args;
_args.reserve(args.size() + 1);
@@ -333,7 +347,9 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<process_handle> process_handle::launch_pr
return posix_error(err);
}
}
- int err = ::posix_spawn(&nativeh.pid, argptrs[0], (childinpipe.is_valid() || childoutpipe.is_valid() || childerrorpipe.is_valid()) ? &child_fd_actions : nullptr, nullptr, (char **) argptrs.data(), (char **) envptrs.data());
+ int err =
+ ::posix_spawn(&nativeh.pid, argptrs[0], (childinpipe.is_valid() || childoutpipe.is_valid() || childerrorpipe.is_valid()) ? &child_fd_actions : nullptr,
+ nullptr, (char **) argptrs.data(), (char **) envptrs.data());
if(err)
return posix_error(err);
if(childinpipe.is_valid() || childoutpipe.is_valid() || childerrorpipe.is_valid())
diff --git a/include/llfio/v2.0/detail/impl/windows/byte_socket_handle.ipp b/include/llfio/v2.0/detail/impl/windows/byte_socket_handle.ipp
index e1ba6b22..ca73bdad 100644
--- a/include/llfio/v2.0/detail/impl/windows/byte_socket_handle.ipp
+++ b/include/llfio/v2.0/detail/impl/windows/byte_socket_handle.ipp
@@ -570,7 +570,7 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<void> byte_socket_handle::_do_connect(con
LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<byte_socket_handle> byte_socket_handle::byte_socket(ip::family _family, mode _mode, caching _caching,
flag flags) noexcept
{
- result<byte_socket_handle> ret(byte_socket_handle(native_handle_type(), _caching, flags, nullptr));
+ result<byte_socket_handle> ret(byte_socket_handle(native_handle_type(), flags, nullptr));
native_handle_type &nativeh = ret.value()._v;
LLFIO_LOG_FUNCTION_CALL(&ret);
OUTCOME_TRY(detail::create_socket(&ret.value(), nativeh, _family, _mode, _caching, flags));
@@ -652,7 +652,7 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<void> listening_byte_socket_handle::bind(
LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<listening_byte_socket_handle> listening_byte_socket_handle::listening_byte_socket(ip::family family, mode _mode, caching _caching,
flag flags) noexcept
{
- result<listening_byte_socket_handle> ret(listening_byte_socket_handle(native_handle_type(), _caching, flags, nullptr));
+ result<listening_byte_socket_handle> ret(listening_byte_socket_handle(native_handle_type(), flags, nullptr));
native_handle_type &nativeh = ret.value()._v;
OUTCOME_TRY(detail::create_socket(&ret.value(), nativeh, family, _mode, _caching, flags));
return ret;
@@ -746,7 +746,7 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<listening_byte_socket_handle::buffers_typ
}
}
}
- b.first = byte_socket_handle(nativeh, _caching, _.flags, _ctx);
+ b.first = byte_socket_handle(nativeh, _.flags, _ctx);
if(_mode == mode::read)
{
OUTCOME_TRY(b.first.shutdown(byte_socket_handle::shutdown_write));
diff --git a/include/llfio/v2.0/detail/impl/windows/directory_handle.ipp b/include/llfio/v2.0/detail/impl/windows/directory_handle.ipp
index 21b8222f..dc69a677 100644
--- a/include/llfio/v2.0/detail/impl/windows/directory_handle.ipp
+++ b/include/llfio/v2.0/detail/impl/windows/directory_handle.ipp
@@ -40,7 +40,7 @@ result<directory_handle> directory_handle::directory(const path_handle &base, pa
{
return errc::invalid_argument;
}
- result<directory_handle> ret(directory_handle(native_handle_type(), 0, 0, _caching, flags));
+ result<directory_handle> ret(directory_handle(native_handle_type(), 0, 0, flags));
native_handle_type &nativeh = ret.value()._v;
LLFIO_LOG_FUNCTION_CALL(&ret);
nativeh.behaviour |= native_handle_type::disposition::directory | native_handle_type::disposition::path | native_handle_type::disposition::kernel_handle;
@@ -211,7 +211,7 @@ result<directory_handle> directory_handle::directory(const path_handle &base, pa
result<directory_handle> directory_handle::reopen(mode mode_, caching caching_, deadline /* unused */) const noexcept
{
LLFIO_LOG_FUNCTION_CALL(this);
- result<directory_handle> ret(directory_handle(native_handle_type(), _devid, _inode, kernel_caching(), _.flags));
+ result<directory_handle> ret(directory_handle(native_handle_type(), _devid, _inode, _.flags));
OUTCOME_TRY(do_clone_handle(ret.value()._v, _v, mode_, caching_, _.flags, true));
return ret;
}
@@ -219,8 +219,8 @@ result<directory_handle> directory_handle::reopen(mode mode_, caching caching_,
LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<path_handle> directory_handle::clone_to_path_handle() const noexcept
{
LLFIO_LOG_FUNCTION_CALL(this);
- result<path_handle> ret(path_handle(native_handle_type(), kernel_caching(), _.flags));
- ret.value()._v.behaviour = _v.behaviour;
+ result<path_handle> ret(path_handle(native_handle(), _.flags));
+ ret.value()._v.h = INVALID_HANDLE_VALUE;
if(DuplicateHandle(GetCurrentProcess(), _v.h, GetCurrentProcess(), &ret.value()._v.h, 0, 0, DUPLICATE_SAME_ACCESS) == 0)
{
return win32_error();
@@ -255,7 +255,7 @@ namespace detail
return ntkernel_error(ntstat);
}
// Return as a file handle so the direct relink and unlink are used
- return file_handle(nativeh, 0, 0, file_handle::caching::all, file_handle::flag::none, nullptr);
+ return file_handle(nativeh, 0, 0, file_handle::flag::none, nullptr);
}
} // namespace detail
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 8396317f..a26cdc76 100644
--- a/include/llfio/v2.0/detail/impl/windows/file_handle.ipp
+++ b/include/llfio/v2.0/detail/impl/windows/file_handle.ipp
@@ -37,7 +37,7 @@ result<file_handle> file_handle::file(const path_handle &base, file_handle::path
{
windows_nt_kernel::init();
using namespace windows_nt_kernel;
- result<file_handle> ret(in_place_type<file_handle>, native_handle_type(), _caching, flags, nullptr);
+ result<file_handle> ret(in_place_type<file_handle>, native_handle_type(), flags, nullptr);
native_handle_type &nativeh = ret.value()._v;
LLFIO_LOG_FUNCTION_CALL(&ret);
nativeh.behaviour |= native_handle_type::disposition::file | native_handle_type::disposition::kernel_handle;
@@ -193,7 +193,7 @@ result<file_handle> file_handle::temp_inode(const path_handle &dirh, mode _mode,
caching _caching = caching::temporary;
// No need to rename to random on unlink or check inode before unlink
flags |= flag::disable_safety_unlinks | flag::win_disable_unlink_emulation;
- result<file_handle> ret(in_place_type<file_handle>, native_handle_type(), _caching, flags, nullptr);
+ result<file_handle> ret(in_place_type<file_handle>, native_handle_type(), flags, nullptr);
native_handle_type &nativeh = ret.value()._v;
LLFIO_LOG_FUNCTION_CALL(&ret);
nativeh.behaviour |= native_handle_type::disposition::file | native_handle_type::disposition::kernel_handle;
@@ -322,7 +322,7 @@ result<file_handle> file_handle::temp_inode(const path_handle &dirh, mode _mode,
result<file_handle> file_handle::reopen(mode mode_, caching caching_, deadline /*unused*/) const noexcept
{
LLFIO_LOG_FUNCTION_CALL(this);
- result<file_handle> ret(in_place_type<file_handle>, native_handle_type(), caching_, _.flags, nullptr);
+ result<file_handle> ret(in_place_type<file_handle>, native_handle_type(), _.flags, nullptr);
ret.value()._ctx = _ctx;
OUTCOME_TRY(do_clone_handle(ret.value()._v, _v, mode_, caching_, _.flags));
return ret;
diff --git a/include/llfio/v2.0/detail/impl/windows/fs_handle.ipp b/include/llfio/v2.0/detail/impl/windows/fs_handle.ipp
index 7896aacf..04c66d8d 100644
--- a/include/llfio/v2.0/detail/impl/windows/fs_handle.ipp
+++ b/include/llfio/v2.0/detail/impl/windows/fs_handle.ipp
@@ -470,7 +470,7 @@ namespace detail
{
return ntkernel_error(ntstat);
}
- return handle(nativeh, _caching, flags);
+ return handle(nativeh, flags);
}
} // namespace detail
diff --git a/include/llfio/v2.0/detail/impl/windows/handle.ipp b/include/llfio/v2.0/detail/impl/windows/handle.ipp
index cef78197..fe56fb31 100644
--- a/include/llfio/v2.0/detail/impl/windows/handle.ipp
+++ b/include/llfio/v2.0/detail/impl/windows/handle.ipp
@@ -111,8 +111,8 @@ result<void> handle::close() noexcept
result<handle> handle::clone() const noexcept
{
LLFIO_LOG_FUNCTION_CALL(this);
- result<handle> ret(handle(native_handle_type(), kernel_caching(), _.flags));
- ret.value()._v.behaviour = _v.behaviour;
+ result<handle> ret(handle(native_handle(), _.flags));
+ ret.value()._v.h = INVALID_HANDLE_VALUE;
if(DuplicateHandle(GetCurrentProcess(), _v.h, GetCurrentProcess(), &ret.value()._v.h, 0, 0, DUPLICATE_SAME_ACCESS) == 0)
{
return win32_error();
diff --git a/include/llfio/v2.0/detail/impl/windows/import.hpp b/include/llfio/v2.0/detail/impl/windows/import.hpp
index d7dbbcc3..d0af7d68 100644
--- a/include/llfio/v2.0/detail/impl/windows/import.hpp
+++ b/include/llfio/v2.0/detail/impl/windows/import.hpp
@@ -1,5 +1,5 @@
/* Declarations for Microsoft Windows system APIs
-(C) 2015-2021 Niall Douglas <http://www.nedproductions.biz/> (14 commits)
+(C) 2015-2022 Niall Douglas <http://www.nedproductions.biz/> (14 commits)
File Created: Dec 2015
@@ -1841,21 +1841,33 @@ inline result<DWORD> attributes_from_handle_caching_and_flags(native_handle_type
break; // can be called by reopen()
case handle::caching::none:
attribs |= FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH;
- nativeh.behaviour |= native_handle_type::disposition::aligned_io;
+ nativeh.behaviour |= native_handle_type::disposition::aligned_io | native_handle_type::disposition::safety_barriers;
break;
case handle::caching::only_metadata:
attribs |= FILE_FLAG_NO_BUFFERING;
- nativeh.behaviour |= native_handle_type::disposition::aligned_io;
+ nativeh.behaviour |= native_handle_type::disposition::aligned_io | native_handle_type::disposition::cache_metadata;
break;
case handle::caching::reads:
+ attribs |= FILE_FLAG_WRITE_THROUGH;
+ nativeh.behaviour |= native_handle_type::disposition::cache_reads | native_handle_type::disposition::safety_barriers;
+ break;
case handle::caching::reads_and_metadata:
attribs |= FILE_FLAG_WRITE_THROUGH;
+ nativeh.behaviour |=
+ native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_metadata | native_handle_type::disposition::safety_barriers;
break;
case handle::caching::all:
+ nativeh.behaviour |=
+ native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes | native_handle_type::disposition::cache_metadata;
+ break;
case handle::caching::safety_barriers:
+ nativeh.behaviour |= native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes |
+ native_handle_type::disposition::cache_metadata | native_handle_type::disposition::safety_barriers;
break;
case handle::caching::temporary:
attribs |= FILE_ATTRIBUTE_TEMPORARY;
+ nativeh.behaviour |= native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes |
+ native_handle_type::disposition::cache_metadata | native_handle_type::disposition::cache_temporary;
break;
}
if(flags & handle::flag::unlink_on_first_close)
@@ -1889,21 +1901,32 @@ inline result<DWORD> ntflags_from_handle_caching_and_flags(native_handle_type &n
break; // can be called by reopen()
case handle::caching::none:
ntflags |= 0x00000008 /*FILE_NO_INTERMEDIATE_BUFFERING*/ | 0x00000002 /*FILE_WRITE_THROUGH*/;
- nativeh.behaviour |= native_handle_type::disposition::aligned_io;
+ nativeh.behaviour |= native_handle_type::disposition::aligned_io | native_handle_type::disposition::safety_barriers;
break;
case handle::caching::only_metadata:
ntflags |= 0x00000008 /*FILE_NO_INTERMEDIATE_BUFFERING*/;
- nativeh.behaviour |= native_handle_type::disposition::aligned_io;
+ nativeh.behaviour |= native_handle_type::disposition::aligned_io | native_handle_type::disposition::safety_barriers;
break;
case handle::caching::reads:
+ ntflags |= 0x00000002 /*FILE_WRITE_THROUGH*/;
+ nativeh.behaviour |= native_handle_type::disposition::cache_reads | native_handle_type::disposition::safety_barriers;
+ break;
case handle::caching::reads_and_metadata:
ntflags |= 0x00000002 /*FILE_WRITE_THROUGH*/;
+ nativeh.behaviour |=
+ native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_metadata | native_handle_type::disposition::safety_barriers;
break;
case handle::caching::all:
+ nativeh.behaviour |=
+ native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes | native_handle_type::disposition::cache_metadata;
+ break;
case handle::caching::safety_barriers:
+ nativeh.behaviour |= native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes |
+ native_handle_type::disposition::cache_metadata | native_handle_type::disposition::safety_barriers;
break;
case handle::caching::temporary:
- // should be handled by attributes_from_handle_caching_and_flags
+ nativeh.behaviour |= native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes |
+ native_handle_type::disposition::cache_metadata | native_handle_type::disposition::cache_temporary;
break;
}
if(flags & handle::flag::unlink_on_first_close)
@@ -2170,9 +2193,7 @@ inline HANDLE CreateFileW_(_In_ LPCWSTR lpFileName, _In_ DWORD dwDesiredAccess,
SetLastError(ERROR_FILE_NOT_FOUND);
return INVALID_HANDLE_VALUE; // NOLINT
}
- auto unntpath = make_scope_exit(
- [&NtPath]() noexcept
- {
+ auto unntpath = make_scope_exit([&NtPath]() noexcept {
if(HeapFree(GetProcessHeap(), 0, NtPath.Buffer) == 0)
{
abort();
diff --git a/include/llfio/v2.0/detail/impl/windows/path_handle.ipp b/include/llfio/v2.0/detail/impl/windows/path_handle.ipp
index 616322e9..94a79c82 100644
--- a/include/llfio/v2.0/detail/impl/windows/path_handle.ipp
+++ b/include/llfio/v2.0/detail/impl/windows/path_handle.ipp
@@ -78,7 +78,7 @@ result<path_handle> path_handle::path(const path_handle &base, path_handle::path
{
windows_nt_kernel::init();
using namespace windows_nt_kernel;
- result<path_handle> ret{path_handle(native_handle_type(), caching::none, flag::none)};
+ result<path_handle> ret{path_handle(native_handle_type(), flag::none)};
native_handle_type &nativeh = ret.value()._v;
LLFIO_LOG_FUNCTION_CALL(&ret);
nativeh.behaviour |= native_handle_type::disposition::path | native_handle_type::disposition::kernel_handle;
diff --git a/include/llfio/v2.0/detail/impl/windows/pipe_handle.ipp b/include/llfio/v2.0/detail/impl/windows/pipe_handle.ipp
index 572e38b2..b0f638fb 100644
--- a/include/llfio/v2.0/detail/impl/windows/pipe_handle.ipp
+++ b/include/llfio/v2.0/detail/impl/windows/pipe_handle.ipp
@@ -32,7 +32,7 @@ result<pipe_handle> pipe_handle::pipe(pipe_handle::path_view_type path, pipe_han
windows_nt_kernel::init();
using namespace windows_nt_kernel;
flags &= ~flag(flag::unlink_on_first_close);
- result<pipe_handle> ret(pipe_handle(native_handle_type(), 0, 0, _caching, flags, nullptr));
+ result<pipe_handle> ret(pipe_handle(native_handle_type(), 0, 0, flags, nullptr));
native_handle_type &nativeh = ret.value()._v;
LLFIO_LOG_FUNCTION_CALL(&ret);
nativeh.behaviour |= native_handle_type::disposition::pipe | native_handle_type::disposition::kernel_handle;
@@ -170,7 +170,7 @@ result<std::pair<pipe_handle, pipe_handle>> pipe_handle::anonymous_pipe(caching
// Create an unnamed new pipe
flags &= ~flag(flag::unlink_on_first_close);
OUTCOME_TRY(auto &&anonpipe, pipe({}, mode::read, creation::only_if_not_exist, _caching, flags));
- std::pair<pipe_handle, pipe_handle> ret(std::move(anonpipe), pipe_handle(native_handle_type(), 0, 0, _caching, flags, nullptr));
+ std::pair<pipe_handle, pipe_handle> ret(std::move(anonpipe), pipe_handle(native_handle_type(), 0, 0, flags, nullptr));
native_handle_type &readnativeh = ret.first._v, &writenativeh = ret.second._v;
DWORD fileshare = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
OUTCOME_TRY(auto &&access, access_mask_from_handle_mode(writenativeh, mode::append, flags));
diff --git a/include/llfio/v2.0/detail/impl/windows/process_handle.ipp b/include/llfio/v2.0/detail/impl/windows/process_handle.ipp
index dee3d8ca..8fc0720b 100644
--- a/include/llfio/v2.0/detail/impl/windows/process_handle.ipp
+++ b/include/llfio/v2.0/detail/impl/windows/process_handle.ipp
@@ -153,15 +153,28 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC const process_handle &process_handle::current()
{
static process_handle self = []() -> process_handle {
process_handle ret(native_handle_type(native_handle_type::disposition::process, GetCurrentProcess()), flag::release_pipes_on_close);
- ret._in_pipe = pipe_handle(native_handle_type(native_handle_type::disposition::pipe | native_handle_type::disposition::readable, GetStdHandle(STD_INPUT_HANDLE)), pipe_handle::caching::all, pipe_handle::flag::none, nullptr);
- ret._out_pipe = pipe_handle(native_handle_type(native_handle_type::disposition::pipe | native_handle_type::disposition::writable, GetStdHandle(STD_OUTPUT_HANDLE)), pipe_handle::caching::all, pipe_handle::flag::none, nullptr);
- ret._error_pipe = pipe_handle(native_handle_type(native_handle_type::disposition::pipe | native_handle_type::disposition::writable, GetStdHandle(STD_ERROR_HANDLE)), pipe_handle::caching::all, pipe_handle::flag::none, nullptr);
+ ret._in_pipe = pipe_handle(native_handle_type(native_handle_type::disposition::pipe | native_handle_type::disposition::readable |
+ native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes |
+ native_handle_type::disposition::cache_metadata,
+ GetStdHandle(STD_INPUT_HANDLE)),
+ pipe_handle::flag::none, nullptr);
+ ret._out_pipe = pipe_handle(native_handle_type(native_handle_type::disposition::pipe | native_handle_type::disposition::writable |
+ native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes |
+ native_handle_type::disposition::cache_metadata,
+ GetStdHandle(STD_OUTPUT_HANDLE)),
+ pipe_handle::flag::none, nullptr);
+ ret._error_pipe = pipe_handle(native_handle_type(native_handle_type::disposition::pipe | native_handle_type::disposition::writable |
+ native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes |
+ native_handle_type::disposition::cache_metadata,
+ GetStdHandle(STD_ERROR_HANDLE)),
+ pipe_handle::flag::none, nullptr);
return ret;
}();
return self;
}
-LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<process_handle> process_handle::launch_process(path_view path, span<path_view_component> args, span<path_view_component> env, flag flags) noexcept
+LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<process_handle> process_handle::launch_process(path_view path, span<path_view_component> args,
+ span<path_view_component> env, flag flags) noexcept
{
result<process_handle> ret(in_place_type<process_handle>, native_handle_type(), flags);
native_handle_type &nativeh = ret.value()._v;
diff --git a/include/llfio/v2.0/directory_handle.hpp b/include/llfio/v2.0/directory_handle.hpp
index 72701934..f70d3106 100644
--- a/include/llfio/v2.0/directory_handle.hpp
+++ b/include/llfio/v2.0/directory_handle.hpp
@@ -199,14 +199,14 @@ public:
//! Default constructor
constexpr directory_handle() {} // NOLINT
//! Construct a directory_handle from a supplied native path_handle
- explicit constexpr directory_handle(native_handle_type h, dev_t devid, ino_t inode, caching caching, flag flags)
- : path_handle(std::move(h), caching, flags)
+ explicit constexpr directory_handle(native_handle_type h, dev_t devid, ino_t inode, flag flags)
+ : path_handle(std::move(h), flags)
, fs_handle(devid, inode)
{
}
//! Construct a directory_handle from a supplied native path_handle
- explicit constexpr directory_handle(native_handle_type h, caching caching, flag flags)
- : path_handle(std::move(h), caching, flags)
+ explicit constexpr directory_handle(native_handle_type h, flag flags)
+ : path_handle(std::move(h), flags)
{
}
//! Implicit move construction of directory_handle permitted
diff --git a/include/llfio/v2.0/file_handle.hpp b/include/llfio/v2.0/file_handle.hpp
index 857d2b0e..d7ff37b3 100644
--- a/include/llfio/v2.0/file_handle.hpp
+++ b/include/llfio/v2.0/file_handle.hpp
@@ -75,14 +75,14 @@ public:
//! Default constructor
constexpr file_handle() {} // NOLINT
//! Construct a handle from a supplied native handle
- constexpr file_handle(native_handle_type h, dev_t devid, ino_t inode, caching caching, flag flags, byte_io_multiplexer *ctx)
- : lockable_byte_io_handle(std::move(h), caching, flags, ctx)
+ constexpr file_handle(native_handle_type h, dev_t devid, ino_t inode, flag flags, byte_io_multiplexer *ctx)
+ : lockable_byte_io_handle(std::move(h), flags, ctx)
, fs_handle(devid, inode)
{
}
//! Construct a handle from a supplied native handle
- constexpr file_handle(native_handle_type h, caching caching, flag flags, byte_io_multiplexer *ctx)
- : lockable_byte_io_handle(std::move(h), caching, flags, ctx)
+ constexpr file_handle(native_handle_type h, flag flags, byte_io_multiplexer *ctx)
+ : lockable_byte_io_handle(std::move(h), flags, ctx)
{
}
//! No copy construction (use clone())
diff --git a/include/llfio/v2.0/handle.hpp b/include/llfio/v2.0/handle.hpp
index aa07e783..88bb2ce9 100644
--- a/include/llfio/v2.0/handle.hpp
+++ b/include/llfio/v2.0/handle.hpp
@@ -1,5 +1,5 @@
/* A handle to something
-(C) 2015-2021 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
+(C) 2015-2022 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
File Created: Dec 2015
@@ -218,43 +218,6 @@ protected:
} _;
};
- static constexpr void _set_caching(native_handle_type &nativeh, caching caching) noexcept
- {
- nativeh.behaviour &=
- ~(native_handle_type::disposition::safety_barriers | native_handle_type::disposition::cache_metadata | native_handle_type::disposition::cache_reads |
- native_handle_type::disposition::cache_writes | native_handle_type::disposition::cache_temporary);
- switch(caching)
- {
- case caching::unchanged:
- break;
- case caching::none:
- nativeh.behaviour |= native_handle_type::disposition::safety_barriers;
- break;
- case caching::only_metadata:
- nativeh.behaviour |= native_handle_type::disposition::cache_metadata;
- break;
- case caching::reads:
- nativeh.behaviour |= native_handle_type::disposition::cache_reads | native_handle_type::disposition::safety_barriers;
- break;
- case caching::reads_and_metadata:
- nativeh.behaviour |=
- native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_metadata | native_handle_type::disposition::safety_barriers;
- break;
- case caching::all:
- nativeh.behaviour |=
- native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes | native_handle_type::disposition::cache_metadata;
- break;
- case caching::safety_barriers:
- nativeh.behaviour |= native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes |
- native_handle_type::disposition::cache_metadata | native_handle_type::disposition::safety_barriers;
- break;
- case caching::temporary:
- nativeh.behaviour |= native_handle_type::disposition::cache_reads | native_handle_type::disposition::cache_writes |
- native_handle_type::disposition::cache_metadata | native_handle_type::disposition::cache_temporary;
- break;
- }
- }
-
public:
//! Default constructor
constexpr handle()
@@ -262,11 +225,10 @@ public:
{
} // NOLINT
//! Construct a handle from a supplied native handle
- explicit constexpr handle(native_handle_type h, caching caching = caching::none, flag flags = flag::none) noexcept
+ explicit constexpr handle(native_handle_type h, flag flags = flag::none) noexcept
: _v(std::move(h))
{
_.flags = flags;
- _set_caching(_v, caching);
}
LLFIO_HEADERS_ONLY_VIRTUAL_SPEC ~handle();
//! No copy construction (use clone())
diff --git a/include/llfio/v2.0/lockable_byte_io_handle.hpp b/include/llfio/v2.0/lockable_byte_io_handle.hpp
index 399b23a3..79658900 100644
--- a/include/llfio/v2.0/lockable_byte_io_handle.hpp
+++ b/include/llfio/v2.0/lockable_byte_io_handle.hpp
@@ -76,8 +76,8 @@ public:
constexpr lockable_byte_io_handle() {} // NOLINT
~lockable_byte_io_handle() = default;
//! Construct a handle from a supplied native handle
- constexpr explicit lockable_byte_io_handle(native_handle_type h, caching caching, flag flags, byte_io_multiplexer *ctx)
- : byte_io_handle(h, caching, flags, ctx)
+ constexpr explicit lockable_byte_io_handle(native_handle_type h, flag flags, byte_io_multiplexer *ctx)
+ : byte_io_handle(h, flags, ctx)
{
}
//! Explicit conversion from `handle` permitted
diff --git a/include/llfio/v2.0/map_handle.hpp b/include/llfio/v2.0/map_handle.hpp
index b49d771e..c11cd2ba 100644
--- a/include/llfio/v2.0/map_handle.hpp
+++ b/include/llfio/v2.0/map_handle.hpp
@@ -100,7 +100,7 @@ public:
}
//! Construct a section handle using the given native handle type for the section and the given i/o handle for the backing storage
explicit section_handle(native_handle_type sectionh, file_handle *backing, file_handle anonymous, flag __flag)
- : handle(sectionh, handle::caching::all)
+ : handle(sectionh)
, _backing(backing)
, _anonymous(std::move(anonymous))
, _flag(__flag)
diff --git a/include/llfio/v2.0/native_handle_type.hpp b/include/llfio/v2.0/native_handle_type.hpp
index 716b2557..10f60801 100644
--- a/include/llfio/v2.0/native_handle_type.hpp
+++ b/include/llfio/v2.0/native_handle_type.hpp
@@ -78,6 +78,8 @@ struct native_handle_type // NOLINT
cache_writes = 1ULL << 55U, //!< Is writing back from kernel cache rather than writing through
cache_temporary = 1ULL << 56U, //!< Writes are not flushed to storage quickly
+ _cache_bits = 0x1fULL << 52U, //!< All the bits used to store kernel caching
+
_is_connected = 1ULL << 60U, // used by pipe_handle and byte_socket_handle on Windows to store connectedness
_multiplexer_state_bit0 = 1ULL << 61U, // per-handle state bits used by an i/o multiplexer
_multiplexer_state_bit1 = 1ULL << 62U, // per-handle state bits used by an i/o multiplexer
@@ -161,7 +163,7 @@ struct native_handle_type // NOLINT
constexpr bool operator!=(const native_handle_type &o) const noexcept { return behaviour != o.behaviour || _init != o._init; }
//! True if the handle is valid
- constexpr bool is_valid() const noexcept { return _init != -1 && static_cast<uint64_t>(behaviour &~disposition::_flags_bits) != 0; }
+ constexpr bool is_valid() const noexcept { return _init != -1 && static_cast<uint64_t>(behaviour & ~disposition::_flags_bits) != 0; }
//! True if the handle is readable
constexpr bool is_readable() const noexcept { return (behaviour & disposition::readable) ? true : false; }
diff --git a/include/llfio/v2.0/path_handle.hpp b/include/llfio/v2.0/path_handle.hpp
index f246c30a..c2eba09a 100644
--- a/include/llfio/v2.0/path_handle.hpp
+++ b/include/llfio/v2.0/path_handle.hpp
@@ -65,8 +65,8 @@ public:
//! Default constructor
constexpr path_handle() {} // NOLINT
//! Construct a handle from a supplied native handle
- explicit constexpr path_handle(native_handle_type h, caching caching, flag flags)
- : handle(h, caching, flags)
+ explicit constexpr path_handle(native_handle_type h, flag flags)
+ : handle(h, flags)
{
}
//! Explicit conversion from handle permitted
diff --git a/include/llfio/v2.0/pipe_handle.hpp b/include/llfio/v2.0/pipe_handle.hpp
index 43b984e8..4755f75e 100644
--- a/include/llfio/v2.0/pipe_handle.hpp
+++ b/include/llfio/v2.0/pipe_handle.hpp
@@ -114,14 +114,14 @@ public:
//! Default constructor
constexpr pipe_handle() {} // NOLINT
//! Construct a handle from a supplied native handle
- constexpr pipe_handle(native_handle_type h, dev_t devid, ino_t inode, caching caching, flag flags, byte_io_multiplexer *ctx)
- : byte_io_handle(std::move(h), caching, flags, ctx)
+ constexpr pipe_handle(native_handle_type h, dev_t devid, ino_t inode, flag flags, byte_io_multiplexer *ctx)
+ : byte_io_handle(std::move(h), flags, ctx)
, fs_handle(devid, inode)
{
}
//! Construct a handle from a supplied native handle
- constexpr pipe_handle(native_handle_type h, caching caching, flag flags, byte_io_multiplexer *ctx)
- : byte_io_handle(std::move(h), caching, flags, ctx)
+ constexpr pipe_handle(native_handle_type h, flag flags, byte_io_multiplexer *ctx)
+ : byte_io_handle(std::move(h), flags, ctx)
{
}
//! No copy construction (use clone())
diff --git a/include/llfio/v2.0/symlink_handle.hpp b/include/llfio/v2.0/symlink_handle.hpp
index 18ddf226..7922d340 100644
--- a/include/llfio/v2.0/symlink_handle.hpp
+++ b/include/llfio/v2.0/symlink_handle.hpp
@@ -330,7 +330,7 @@ public:
constexpr
#endif
explicit symlink_handle(native_handle_type h, dev_t devid, ino_t inode, flag flags = flag::none)
- : handle(std::move(h), caching::all, flags)
+ : handle(std::move(h), flags)
, fs_handle(devid, inode)
{
}
diff --git a/include/llfio/v2.0/tls_socket_handle.hpp b/include/llfio/v2.0/tls_socket_handle.hpp
index fdb61179..474b9aec 100644
--- a/include/llfio/v2.0/tls_socket_handle.hpp
+++ b/include/llfio/v2.0/tls_socket_handle.hpp
@@ -203,7 +203,7 @@ class LLFIO_DECL listening_tls_socket_handle : public listening_socket_handle_bu
protected:
constexpr listening_tls_socket_handle() {}
explicit listening_tls_socket_handle(listening_byte_socket_handle &&sock)
- : _base(sock.release(), sock.kernel_caching(), sock.flags(), sock.multiplexer())
+ : _base(sock.release(), sock.flags(), sock.multiplexer())
{
this->_v.behaviour |= native_handle_type::disposition::tls_socket;
}