Skip to content

Commit

Permalink
Add Mile::Cirno::Client::Walk.
Browse files Browse the repository at this point in the history
  • Loading branch information
MouriNaruto committed Nov 9, 2024
1 parent 3c4c147 commit b88769c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
34 changes: 34 additions & 0 deletions Mile.Cirno/Mile.Cirno.Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,40 @@ Mile::Cirno::AttachResponse Mile::Cirno::Client::Attach(
return Mile::Cirno::PopAttachResponse(ResponseSpan);
}

Mile::Cirno::WalkResponse Mile::Cirno::Client::Walk(
Mile::Cirno::WalkRequest const& Request)
{
std::uint16_t Tag = this->AllocateTag();
if (MILE_CIRNO_NOTAG == Tag)
{
Mile::Cirno::ThrowException(
"MILE_CIRNO_NOTAG == Tag",
ERROR_INVALID_DATA);
}
auto ExitHandler = Mile::ScopeExitTaskHandler([&]()
{
if (MILE_CIRNO_NOTAG != Tag)
{
this->FreeTag(Tag);
}
});

std::vector<std::uint8_t> RequestBuffer;
Mile::Cirno::PushWalkRequest(
RequestBuffer,
Request);
std::vector<std::uint8_t> ResponseBuffer;
this->Request(
Tag,
MileCirnoWalkRequestMessage,
RequestBuffer,
MileCirnoWalkResponseMessage,
ResponseBuffer);
std::span<std::uint8_t> ResponseSpan =
std::span<std::uint8_t>(ResponseBuffer);
return Mile::Cirno::PopWalkResponse(ResponseSpan);
}

Mile::Cirno::LinuxOpenResponse Mile::Cirno::Client::LinuxOpen(
Mile::Cirno::LinuxOpenRequest const& Request)
{
Expand Down
3 changes: 3 additions & 0 deletions Mile.Cirno/Mile.Cirno.Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ namespace Mile::Cirno
AttachResponse Attach(
AttachRequest const& Request);

WalkResponse Walk(
WalkRequest const& Request);

LinuxOpenResponse LinuxOpen(
LinuxOpenRequest const& Request);

Expand Down
22 changes: 18 additions & 4 deletions Mile.Cirno/Mile.Cirno.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ void Test()
Response.MaximumMessageSize);
}

std::uint32_t FileId = Instance->AllocateFileId();
std::uint32_t AttachFileId = Instance->AllocateFileId();
{
Mile::Cirno::AttachRequest Request;
Request.FileId = FileId;
Request.FileId = AttachFileId;
Request.AuthenticationFileId = MILE_CIRNO_NOFID;
Request.UserName = "";
Request.AccessName = "HostDriverStore";
Expand All @@ -84,6 +84,17 @@ void Test()
Response.UniqueId.Path);
}

std::uint32_t FileId = Instance->AllocateFileId();
{
Mile::Cirno::WalkRequest Request;
Request.FileId = AttachFileId;
Request.NewFileId = FileId;
Request.Names.push_back("FileRepository");
Request.Names.push_back("nvmii.inf_amd64_9af988a7aa90f6d3");
Mile::Cirno::WalkResponse Response = Instance->Walk(Request);
Response = Response;
}

{
Mile::Cirno::LinuxOpenRequest Request;
Request.FileId = FileId;
Expand All @@ -96,19 +107,22 @@ void Test()
Response = Response;
}

std::uint64_t LastOffset = 0;
do
{
Mile::Cirno::ReadDirRequest Request;
Request.FileId = FileId;
Request.Offset = 0;
Request.Offset = LastOffset;
Request.Count = (1 << 16) - Mile::Cirno::HeaderSize - sizeof(std::uint32_t);
Mile::Cirno::ReadDirResponse Response = Instance->ReadDir(Request);
for (Mile::Cirno::DirectoryEntry const& Entry : Response.Data)
{
LastOffset = Entry.Offset;
std::printf(
"[INFO] List Directory: %s\n",
Entry.Name.c_str());
}
}
} while (LastOffset);
}
catch (std::exception const& ex)
{
Expand Down

0 comments on commit b88769c

Please sign in to comment.