Skip to content

Commit 9358c2d

Browse files
committed
Merge branch 'develop' of github.com:ned14/llfio into develop
2 parents 3ab4304 + aad64ad commit 9358c2d

File tree

4 files changed

+87
-80
lines changed

4 files changed

+87
-80
lines changed

example/path_view_openat.cpp

Lines changed: 79 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -27,97 +27,102 @@ Distributed under the Boost Software License, Version 1.0.
2727
#if defined(_WIN32) && _HAS_CXX20
2828
#include "../include/llfio/v2.0/detail/impl/windows/import.hpp"
2929

30-
#include <variant>
30+
namespace path_view_openat_example
31+
{
32+
using namespace LLFIO_V2_NAMESPACE;
33+
using namespace LLFIO_V2_NAMESPACE::windows_nt_kernel;
34+
using namespace std;
3135

32-
using namespace LLFIO_V2_NAMESPACE;
33-
using namespace LLFIO_V2_NAMESPACE::windows_nt_kernel;
34-
using namespace std;
36+
using LLFIO_V2_NAMESPACE::windows_nt_kernel::IO_STATUS_BLOCK;
37+
using LLFIO_V2_NAMESPACE::windows_nt_kernel::NtCreateFile;
38+
using LLFIO_V2_NAMESPACE::windows_nt_kernel::OBJECT_ATTRIBUTES;
39+
using LLFIO_V2_NAMESPACE::windows_nt_kernel::UNICODE_STRING;
3540

36-
HANDLE openat(HANDLE base, path_view path)
37-
{
38-
static constexpr DWORD access = GENERIC_READ;
39-
static constexpr DWORD share =
40-
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
41-
static constexpr DWORD creation = OPEN_EXISTING;
42-
static constexpr DWORD flags = FILE_ATTRIBUTE_NORMAL;
43-
return visit(
44-
[&](auto sv) -> HANDLE
41+
HANDLE openat(HANDLE base, path_view path)
4542
{
46-
using type = typename decltype(sv)::value_type;
47-
if constexpr(is_same_v<type, byte>)
43+
static constexpr DWORD access = GENERIC_READ;
44+
static constexpr DWORD share =
45+
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
46+
static constexpr DWORD creation = OPEN_EXISTING;
47+
static constexpr DWORD flags = FILE_ATTRIBUTE_NORMAL;
48+
return visit(
49+
[&](auto sv) -> HANDLE
4850
{
49-
if(sv.size() == 16)
51+
using type = typename decltype(sv)::value_type;
52+
if constexpr(is_same_v<type, byte>)
5053
{
51-
FILE_ID_DESCRIPTOR fid{};
52-
fid.dwSize = sizeof(fid);
53-
fid.Type = 1;
54-
memcpy(&fid.ObjectId, sv.data(), 16);
55-
return OpenFileById(base, &fid, access, share, nullptr, flags);
54+
if(sv.size() == 16)
55+
{
56+
FILE_ID_DESCRIPTOR fid{};
57+
fid.dwSize = sizeof(fid);
58+
fid.Type = 1;
59+
memcpy(&fid.ObjectId, sv.data(), 16);
60+
return OpenFileById(base, &fid, access, share, nullptr, flags);
61+
}
62+
throw std::runtime_error("binary key must be exactly 16 bytes long");
5663
}
57-
throw std::runtime_error("binary key must be exactly 16 bytes long");
58-
}
59-
// A "\!!\" or "\??\" prefix enables direct use of the NT kernel API
60-
// or setting base, as the Win32 doesn't support paths relative to a base
61-
const bool is_ntpath =
62-
sv.size() >= 4 && sv[0] == '\\' && sv[3] == '\\' &&
63-
((sv[1] == '!' && sv[2] == '!') || (sv[1] == '?' && sv[2] == '?'));
64-
if(base != nullptr || is_ntpath)
65-
{
66-
// The NT kernel always takes the system wide encoding
67-
auto zpath = path.render_unterminated<wchar_t>(path);
68-
UNICODE_STRING _path{};
69-
_path.Buffer = const_cast<wchar_t *>(zpath.data());
70-
_path.MaximumLength =
71-
(_path.Length = static_cast<USHORT>(zpath.size() * sizeof(wchar_t))) +
72-
sizeof(wchar_t);
73-
// The "\!!\" prefix is library local and the NT kernel doesn't
74-
// understand it, so strip it off
75-
if(zpath.size() >= 4 && _path.Buffer[0] == '\\' &&
76-
_path.Buffer[1] == '!' && _path.Buffer[2] == '!' &&
77-
_path.Buffer[3] == '\\')
64+
// A "\!!\" or "\??\" prefix enables direct use of the NT kernel API
65+
// or setting base, as the Win32 API doesn't support paths relative to a
66+
// base
67+
const bool is_ntpath =
68+
sv.size() >= 4 && sv[0] == '\\' && sv[3] == '\\' &&
69+
((sv[1] == '!' && sv[2] == '!') || (sv[1] == '?' && sv[2] == '?'));
70+
if(base != nullptr || is_ntpath)
7871
{
79-
_path.Buffer += 3;
80-
_path.Length -= 3 * sizeof(wchar_t);
81-
_path.MaximumLength -= 3 * sizeof(wchar_t);
82-
}
72+
// The NT kernel always takes the system wide encoding
73+
auto zpath = path.render_unterminated<wchar_t>(path);
74+
UNICODE_STRING _path{};
75+
_path.Buffer = const_cast<wchar_t *>(zpath.data());
76+
_path.MaximumLength =
77+
(_path.Length = static_cast<USHORT>(zpath.size() * sizeof(wchar_t))) +
78+
sizeof(wchar_t);
79+
// The "\!!\" prefix is library local and the NT kernel doesn't
80+
// understand it unlike "\??\", so strip it off
81+
if(zpath.size() >= 4 && _path.Buffer[0] == '\\' &&
82+
_path.Buffer[1] == '!' && _path.Buffer[2] == '!' &&
83+
_path.Buffer[3] == '\\')
84+
{
85+
_path.Buffer += 3;
86+
_path.Length -= 3 * sizeof(wchar_t);
87+
_path.MaximumLength -= 3 * sizeof(wchar_t);
88+
}
8389

84-
OBJECT_ATTRIBUTES oa{};
85-
oa.Length = sizeof(OBJECT_ATTRIBUTES);
86-
oa.ObjectName = &_path;
87-
oa.RootDirectory = base;
88-
oa.Attributes = 0;
90+
OBJECT_ATTRIBUTES oa{};
91+
oa.Length = sizeof(OBJECT_ATTRIBUTES);
92+
oa.ObjectName = &_path;
93+
oa.RootDirectory = base;
94+
oa.Attributes = 0;
8995

90-
IO_STATUS_BLOCK isb{};
91-
LARGE_INTEGER AllocationSize{};
92-
HANDLE ret = INVALID_HANDLE_VALUE;
93-
NTSTATUS ntstat =
94-
NtCreateFile(&ret, access, &oa, &isb, &AllocationSize, 0, share,
95-
FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, nullptr, 0);
96-
if(ntstat < 0)
97-
{
98-
// Might want to call RtlNtStatusToDosError(ntstat)?
96+
IO_STATUS_BLOCK isb{};
97+
LARGE_INTEGER AllocationSize{};
98+
HANDLE ret = INVALID_HANDLE_VALUE;
99+
NTSTATUS ntstat =
100+
NtCreateFile(&ret, access, &oa, &isb, &AllocationSize, 0, share,
101+
FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, nullptr, 0);
102+
if(ntstat < 0)
103+
{
104+
// Might want to call RtlNtStatusToDosError(ntstat)?
105+
}
106+
return ret;
99107
}
100-
return ret;
101-
}
102-
else
103-
{
104108
if constexpr(is_same_v<type, char>)
105109
{
106110
// Render to the system narrow encoding null terminated
107111
auto zpath = path.render_null_terminated<char>(path);
108112
return CreateFileA(zpath.c_str(), access, share, nullptr, creation,
109113
flags, nullptr);
110114
}
111-
// Render to the system wide encoding null terminated
112-
auto zpath = path.render_null_terminated<wchar_t>(path);
113-
return CreateFileW(zpath.c_str(), access, share, nullptr, creation,
114-
flags, nullptr);
115-
}
116-
// Should never reach here
117-
std::terminate();
118-
},
119-
path);
120-
}
115+
else // char8_t, char16_t, wchar_t
116+
{
117+
// Render to the system wide encoding null terminated
118+
auto zpath = path.render_null_terminated<wchar_t>(path);
119+
return CreateFileW(zpath.c_str(), access, share, nullptr, creation,
120+
flags, nullptr);
121+
}
122+
},
123+
path);
124+
}
125+
} // namespace path_view_openat_example
121126
#endif
122127

123128
// clang-format off

include/llfio/revision.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
2-
#define LLFIO_PREVIOUS_COMMIT_REF 938b8456e9d575c4455ddeca5fbe808c040b8c88
3-
#define LLFIO_PREVIOUS_COMMIT_DATE "2024-08-20 11:29:01 +00:00"
4-
#define LLFIO_PREVIOUS_COMMIT_UNIQUE 938b8456
2+
#define LLFIO_PREVIOUS_COMMIT_REF f51d47933cf4cdf7ac0766818f1bed6ff39b779e
3+
#define LLFIO_PREVIOUS_COMMIT_DATE "2024-08-22 09:34:43 +00:00"
4+
#define LLFIO_PREVIOUS_COMMIT_UNIQUE f51d4793

include/llfio/v2.0/detail/impl/windows/directory_handle.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ result<directory_handle::buffers_type> directory_handle::read(io_request<buffers
502502
{
503503
auto whattoadd = (7 + offsetof(what_to_enumerate_type, FileName) + ffdi->FileNameLength) & ~7;
504504
auto new_buffer_start = reinterpret_cast<what_to_enumerate_type *>(reinterpret_cast<uintptr_t>(ffdi) + whattoadd);
505-
bytes -= reinterpret_cast<uintptr_t>(new_buffer_start) - reinterpret_cast<uintptr_t>(buffer_);
505+
bytes -= (ULONG)(reinterpret_cast<uintptr_t>(new_buffer_start) - reinterpret_cast<uintptr_t>(buffer_));
506506
buffer_ = new_buffer_start;
507507
}
508508
}

test/tests/byte_socket_handle.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,9 @@ static inline void TestNonBlockingSocketHandles()
515515
}
516516

517517
#if LLFIO_ENABLE_TEST_IO_MULTIPLEXERS
518-
#ifndef LLFIO_EXCLUDE_NETWORKING
519518
static inline void TestMultiplexedSocketHandles()
520519
{
520+
#ifndef LLFIO_EXCLUDE_NETWORKING
521521
static constexpr size_t MAX_SOCKETS = 64;
522522
namespace llfio = LLFIO_V2_NAMESPACE;
523523
auto test_multiplexer = [](llfio::byte_io_multiplexer_ptr multiplexer)
@@ -701,11 +701,13 @@ static inline void TestMultiplexedSocketHandles()
701701
#else
702702
#error Not implemented yet
703703
#endif
704+
#endif
704705
}
705706

706707
#if LLFIO_ENABLE_COROUTINES
707708
static inline void TestCoroutinedSocketHandles()
708709
{
710+
#ifndef LLFIO_EXCLUDE_NETWORKING
709711
static constexpr size_t MAX_SOCKETS = 70;
710712
namespace llfio = LLFIO_V2_NAMESPACE;
711713
auto test_multiplexer = [](llfio::byte_io_multiplexer_ptr multiplexer)
@@ -833,8 +835,8 @@ static inline void TestCoroutinedSocketHandles()
833835
#else
834836
#error Not implemented yet
835837
#endif
836-
}
837838
#endif
839+
}
838840
#endif
839841
#endif
840842

0 commit comments

Comments
 (0)