Skip to content

Commit

Permalink
sysdeps/managarm: Add sys_fstatfs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennisbonke committed Dec 23, 2024
1 parent 4b21d4f commit b45b7e9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions sysdeps/managarm/generic/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2734,4 +2734,37 @@ int sys_sysinfo(struct sysinfo *info) {
return 0;
}

int sys_fstatfs(int fd, struct statfs *buf) {
SignalGuard sguard;

managarm::posix::FstatfsRequest<MemoryAllocator> req(getSysdepsAllocator());
req.set_fd(fd);

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

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

managarm::posix::FstatfsResponse resp(getSysdepsAllocator());
resp.ParseFromArray(recv_resp.data(), recv_resp.length());

if (resp.error() == managarm::posix::Errors::BAD_FD) {
return EBADF;
} else if (resp.error() == managarm::posix::Errors::FILE_NOT_FOUND) {
// Check?
return ENOENT;
} else {
__ensure(resp.error() == managarm::posix::Errors::SUCCESS);
memset(buf, NULL, sizeof(struct statfs));
buf->f_type = resp.fstype();
return 0;
}
}

} // namespace mlibc

0 comments on commit b45b7e9

Please sign in to comment.