Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sysdeps/managarm: implement basic NVME_IOCTL_*s #1228

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions sysdeps/managarm/generic/ioctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <linux/cdrom.h>
#include <linux/input.h>
#include <linux/kd.h>
#include <linux/nvme_ioctl.h>
#include <linux/sockios.h>
#include <linux/usb/cdc-wdm.h>
#include <linux/vt.h>
Expand Down Expand Up @@ -1093,6 +1094,62 @@ int sys_ioctl(int fd, unsigned long request, void *arg, int *result) {
*result = resp.result();
*param = resp.size();
return 0;
} else if (request == NVME_IOCTL_ID) {
managarm::fs::GenericIoctlRequest<MemoryAllocator> req(getSysdepsAllocator());
req.set_command(request);

auto [offer, send_ioctl_req, send_req, recv_resp] = exchangeMsgsSync(
handle,
helix_ng::offer(
helix_ng::sendBragiHeadOnly(ioctl_req, getSysdepsAllocator()),
helix_ng::sendBragiHeadOnly(req, getSysdepsAllocator()),
helix_ng::recvInline()
)
);

HEL_CHECK(offer.error());
HEL_CHECK(send_ioctl_req.error());
HEL_CHECK(send_req.error());
HEL_CHECK(recv_resp.error());

managarm::fs::GenericIoctlReply<MemoryAllocator> resp(getSysdepsAllocator());
resp.ParseFromArray(recv_resp.data(), recv_resp.length());
__ensure(resp.error() == managarm::fs::Errors::SUCCESS);
*result = resp.result();
return 0;
} else if (request == NVME_IOCTL_ADMIN_CMD) {
auto param = reinterpret_cast<struct nvme_admin_cmd *>(arg);

managarm::fs::GenericIoctlRequest<MemoryAllocator> req(getSysdepsAllocator());
req.set_command(request);

auto [offer, send_ioctl_req, send_req, send_buffer, send_data, recv_resp, recv_data] =
exchangeMsgsSync(
handle,
helix_ng::offer(
helix_ng::sendBragiHeadOnly(ioctl_req, getSysdepsAllocator()),
helix_ng::sendBragiHeadOnly(req, getSysdepsAllocator()),
helix_ng::sendBuffer(param, sizeof(*param)),
helix_ng::sendBuffer(reinterpret_cast<void *>(param->addr), param->data_len),
helix_ng::recvInline(),
helix_ng::recvBuffer(reinterpret_cast<void *>(param->addr), param->data_len)
)
);

HEL_CHECK(offer.error());
HEL_CHECK(send_ioctl_req.error());
HEL_CHECK(send_req.error());
HEL_CHECK(send_buffer.error());
HEL_CHECK(send_data.error());
HEL_CHECK(recv_resp.error());
HEL_CHECK(recv_data.error());

managarm::fs::GenericIoctlReply<MemoryAllocator> resp(getSysdepsAllocator());
resp.ParseFromArray(recv_resp.data(), recv_resp.length());
__ensure(resp.error() == managarm::fs::Errors::SUCCESS);
*result = resp.result();
param->result = resp.status();
return 0;
}

mlibc::infoLogger() << "mlibc: Unexpected ioctl with"
Expand Down
Loading