[Yunq] Return status from client calls.
This commit is contained in:
parent
700f3f94cb
commit
c209925a3c
25 changed files with 102 additions and 112 deletions
|
|
@ -57,29 +57,29 @@ struct PartitionEntry {
|
|||
GptReader::GptReader(glcr::UniquePtr<DenaliClient> denali)
|
||||
: denali_(glcr::Move(denali)) {}
|
||||
|
||||
glcr::ErrorCode GptReader::ParsePartitionTables() {
|
||||
glcr::Status GptReader::ParsePartitionTables() {
|
||||
ReadRequest req;
|
||||
req.set_device_id(0);
|
||||
req.set_lba(0);
|
||||
req.set_size(2);
|
||||
ReadResponse resp;
|
||||
RET_ERR(denali_->Read(req, resp));
|
||||
RETURN_ERROR(denali_->Read(req, resp));
|
||||
mmth::OwnedMemoryRegion lba_1_and_2 =
|
||||
mmth::OwnedMemoryRegion::FromCapability(resp.memory());
|
||||
uint16_t* mbr_sig = reinterpret_cast<uint16_t*>(lba_1_and_2.vaddr() + 0x1FE);
|
||||
if (*mbr_sig != 0xAA55) {
|
||||
dbgln("Invalid MBR Sig: {x}", *mbr_sig);
|
||||
return glcr::FAILED_PRECONDITION;
|
||||
return glcr::FailedPrecondition(
|
||||
glcr::StrFormat("Invalid MBR Sig: {x}", *mbr_sig));
|
||||
}
|
||||
MbrPartition* first_partition =
|
||||
reinterpret_cast<MbrPartition*>(lba_1_and_2.vaddr() + 0x1BE);
|
||||
if (first_partition->boot_indicator != 0) {
|
||||
dbgln("Boot indicator set: {}", first_partition->boot_indicator);
|
||||
return glcr::FAILED_PRECONDITION;
|
||||
return glcr::FailedPrecondition(glcr::StrFormat(
|
||||
"Boot indicator set: {}", first_partition->boot_indicator));
|
||||
}
|
||||
if (first_partition->os_type != 0xEE) {
|
||||
dbgln("Incorrect OS type: {x}", first_partition->os_type);
|
||||
return glcr::FAILED_PRECONDITION;
|
||||
return glcr::FailedPrecondition(
|
||||
glcr::StrFormat("Incorrect OS type: {x}", first_partition->os_type));
|
||||
}
|
||||
#if GPT_DEBUG
|
||||
dbgln("LBAs: ({x}, {x})", first_partition->starting_lba,
|
||||
|
|
@ -105,7 +105,7 @@ glcr::ErrorCode GptReader::ParsePartitionTables() {
|
|||
req.set_device_id(0);
|
||||
req.set_lba(header->lba_partition_entries);
|
||||
req.set_size(num_blocks);
|
||||
RET_ERR(denali_->Read(req, resp));
|
||||
RETURN_ERROR(denali_->Read(req, resp));
|
||||
mmth::OwnedMemoryRegion part_table =
|
||||
mmth::OwnedMemoryRegion::FromCapability(resp.memory());
|
||||
for (uint64_t i = 0; i < num_partitions; i++) {
|
||||
|
|
@ -130,5 +130,5 @@ glcr::ErrorCode GptReader::ParsePartitionTables() {
|
|||
}
|
||||
}
|
||||
|
||||
return glcr::OK;
|
||||
return glcr::Status::Ok();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class GptReader {
|
|||
public:
|
||||
GptReader(glcr::UniquePtr<DenaliClient> denali);
|
||||
|
||||
glcr::ErrorCode ParsePartitionTables();
|
||||
glcr::Status ParsePartitionTables();
|
||||
|
||||
uint64_t GetPrimaryPartitionLba() { return primary_partition_lba_; }
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ YellowstoneClient::~YellowstoneClient() {
|
|||
|
||||
|
||||
|
||||
glcr::ErrorCode YellowstoneClient::RegisterEndpoint(const RegisterEndpointRequest& request) {
|
||||
glcr::Status YellowstoneClient::RegisterEndpoint(const RegisterEndpointRequest& request) {
|
||||
|
||||
uint64_t buffer_size = kBufferSize;
|
||||
uint64_t cap_size = kCapBufferSize;
|
||||
|
|
@ -43,7 +43,7 @@ glcr::ErrorCode YellowstoneClient::RegisterEndpoint(const RegisterEndpointReques
|
|||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||
|
||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||
return glcr::INVALID_RESPONSE;
|
||||
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||
}
|
||||
|
||||
// Check Response Code.
|
||||
|
|
@ -57,7 +57,7 @@ glcr::ErrorCode YellowstoneClient::RegisterEndpoint(const RegisterEndpointReques
|
|||
|
||||
|
||||
|
||||
glcr::ErrorCode YellowstoneClient::GetEndpoint(const GetEndpointRequest& request, Endpoint& response) {
|
||||
glcr::Status YellowstoneClient::GetEndpoint(const GetEndpointRequest& request, Endpoint& response) {
|
||||
|
||||
uint64_t buffer_size = kBufferSize;
|
||||
uint64_t cap_size = kCapBufferSize;
|
||||
|
|
@ -80,18 +80,14 @@ glcr::ErrorCode YellowstoneClient::GetEndpoint(const GetEndpointRequest& request
|
|||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||
|
||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||
return glcr::INVALID_RESPONSE;
|
||||
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||
}
|
||||
|
||||
// Check Response Code.
|
||||
RET_ERR(buffer_.At<uint64_t>(8));
|
||||
|
||||
|
||||
// TODO: Return status.
|
||||
auto status = response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
||||
if (!status) {
|
||||
return status.code();
|
||||
}
|
||||
RETURN_ERROR(response.ParseFromBytes(buffer_, 16, cap_buffer_));
|
||||
|
||||
|
||||
return glcr::OK;
|
||||
|
|
@ -100,7 +96,7 @@ glcr::ErrorCode YellowstoneClient::GetEndpoint(const GetEndpointRequest& request
|
|||
|
||||
|
||||
|
||||
glcr::ErrorCode YellowstoneClient::GetAhciInfo(AhciInfo& response) {
|
||||
glcr::Status YellowstoneClient::GetAhciInfo(AhciInfo& response) {
|
||||
|
||||
uint64_t buffer_size = kBufferSize;
|
||||
uint64_t cap_size = kCapBufferSize;
|
||||
|
|
@ -123,18 +119,14 @@ glcr::ErrorCode YellowstoneClient::GetAhciInfo(AhciInfo& response) {
|
|||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||
|
||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||
return glcr::INVALID_RESPONSE;
|
||||
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||
}
|
||||
|
||||
// Check Response Code.
|
||||
RET_ERR(buffer_.At<uint64_t>(8));
|
||||
|
||||
|
||||
// TODO: Return status.
|
||||
auto status = response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
||||
if (!status) {
|
||||
return status.code();
|
||||
}
|
||||
RETURN_ERROR(response.ParseFromBytes(buffer_, 16, cap_buffer_));
|
||||
|
||||
|
||||
return glcr::OK;
|
||||
|
|
@ -143,7 +135,7 @@ glcr::ErrorCode YellowstoneClient::GetAhciInfo(AhciInfo& response) {
|
|||
|
||||
|
||||
|
||||
glcr::ErrorCode YellowstoneClient::GetFramebufferInfo(FramebufferInfo& response) {
|
||||
glcr::Status YellowstoneClient::GetFramebufferInfo(FramebufferInfo& response) {
|
||||
|
||||
uint64_t buffer_size = kBufferSize;
|
||||
uint64_t cap_size = kCapBufferSize;
|
||||
|
|
@ -166,18 +158,14 @@ glcr::ErrorCode YellowstoneClient::GetFramebufferInfo(FramebufferInfo& response)
|
|||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||
|
||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||
return glcr::INVALID_RESPONSE;
|
||||
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||
}
|
||||
|
||||
// Check Response Code.
|
||||
RET_ERR(buffer_.At<uint64_t>(8));
|
||||
|
||||
|
||||
// TODO: Return status.
|
||||
auto status = response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
||||
if (!status) {
|
||||
return status.code();
|
||||
}
|
||||
RETURN_ERROR(response.ParseFromBytes(buffer_, 16, cap_buffer_));
|
||||
|
||||
|
||||
return glcr::OK;
|
||||
|
|
@ -186,7 +174,7 @@ glcr::ErrorCode YellowstoneClient::GetFramebufferInfo(FramebufferInfo& response)
|
|||
|
||||
|
||||
|
||||
glcr::ErrorCode YellowstoneClient::GetDenali(DenaliInfo& response) {
|
||||
glcr::Status YellowstoneClient::GetDenali(DenaliInfo& response) {
|
||||
|
||||
uint64_t buffer_size = kBufferSize;
|
||||
uint64_t cap_size = kCapBufferSize;
|
||||
|
|
@ -209,18 +197,14 @@ glcr::ErrorCode YellowstoneClient::GetDenali(DenaliInfo& response) {
|
|||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||
|
||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||
return glcr::INVALID_RESPONSE;
|
||||
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||
}
|
||||
|
||||
// Check Response Code.
|
||||
RET_ERR(buffer_.At<uint64_t>(8));
|
||||
|
||||
|
||||
// TODO: Return status.
|
||||
auto status = response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
||||
if (!status) {
|
||||
return status.code();
|
||||
}
|
||||
RETURN_ERROR(response.ParseFromBytes(buffer_, 16, cap_buffer_));
|
||||
|
||||
|
||||
return glcr::OK;
|
||||
|
|
|
|||
|
|
@ -22,23 +22,23 @@ class YellowstoneClient {
|
|||
|
||||
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode RegisterEndpoint(const RegisterEndpointRequest& request);
|
||||
[[nodiscard]] glcr::Status RegisterEndpoint(const RegisterEndpointRequest& request);
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode GetEndpoint(const GetEndpointRequest& request, Endpoint& response);
|
||||
[[nodiscard]] glcr::Status GetEndpoint(const GetEndpointRequest& request, Endpoint& response);
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode GetAhciInfo(AhciInfo& response);
|
||||
[[nodiscard]] glcr::Status GetAhciInfo(AhciInfo& response);
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode GetFramebufferInfo(FramebufferInfo& response);
|
||||
[[nodiscard]] glcr::Status GetFramebufferInfo(FramebufferInfo& response);
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode GetDenali(DenaliInfo& response);
|
||||
[[nodiscard]] glcr::Status GetDenali(DenaliInfo& response);
|
||||
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ void YellowstoneServerBase::ServerThread() {
|
|||
glcr::Status err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
||||
if (!err) {
|
||||
WriteError(resp_buffer, err.code());
|
||||
dbgln("Responding Error {}", err.message());
|
||||
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
|
||||
} else {
|
||||
WriteHeader(resp_buffer, resp_length);
|
||||
|
|
@ -105,7 +106,6 @@ glcr::Status YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& reques
|
|||
|
||||
|
||||
RegisterEndpointRequest yunq_request;
|
||||
// TODO: Return status.
|
||||
RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
|
||||
|
||||
|
||||
|
|
@ -124,7 +124,6 @@ glcr::Status YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& reques
|
|||
|
||||
|
||||
GetEndpointRequest yunq_request;
|
||||
// TODO: Return status.
|
||||
RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@ glcr::ErrorOr<PartitionInfo> HandleDenaliRegistration(z_cap_t endpoint_cap) {
|
|||
GptReader reader(
|
||||
glcr::UniquePtr<DenaliClient>(new DenaliClient(endpoint_cap)));
|
||||
|
||||
RET_ERR(reader.ParsePartitionTables());
|
||||
auto status = reader.ParsePartitionTables();
|
||||
if (!status.ok()) {
|
||||
dbgln("GPT Reader: {}", status.message());
|
||||
return status.code();
|
||||
}
|
||||
|
||||
return PartitionInfo{.device_id = 0,
|
||||
.partition_lba = reader.GetPrimaryPartitionLba()};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue