summaryrefslogtreecommitdiff
path: root/lib/mlibc/sysdeps/managarm/generic/mount.cpp
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-07 17:28:00 -0500
committerIan Moffett <ian@osmora.org>2024-03-07 17:28:32 -0500
commitbd5969fc876a10b18613302db7087ef3c40f18e1 (patch)
tree7c2b8619afe902abf99570df2873fbdf40a4d1a1 /lib/mlibc/sysdeps/managarm/generic/mount.cpp
parenta95b38b1b92b172e6cc4e8e56a88a30cc65907b0 (diff)
lib: Add mlibc
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/sysdeps/managarm/generic/mount.cpp')
-rw-r--r--lib/mlibc/sysdeps/managarm/generic/mount.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/mlibc/sysdeps/managarm/generic/mount.cpp b/lib/mlibc/sysdeps/managarm/generic/mount.cpp
new file mode 100644
index 0000000..5677b20
--- /dev/null
+++ b/lib/mlibc/sysdeps/managarm/generic/mount.cpp
@@ -0,0 +1,44 @@
+#include <errno.h>
+#include <string.h>
+#include <sys/mount.h>
+
+#include <bits/ensure.h>
+#include <mlibc/allocator.hpp>
+#include <mlibc/posix-pipe.hpp>
+#include <mlibc/all-sysdeps.hpp>
+#include <posix.frigg_bragi.hpp>
+#include <bragi/helpers-frigg.hpp>
+
+namespace mlibc {
+
+int sys_mount(const char *source, const char *target,
+ const char *fstype, unsigned long, const void *) {
+ SignalGuard sguard;
+
+ managarm::posix::MountRequest<MemoryAllocator> req(getSysdepsAllocator());
+ req.set_path(frg::string<MemoryAllocator>(getSysdepsAllocator(), source));
+ req.set_target_path(frg::string<MemoryAllocator>(getSysdepsAllocator(), target));
+ req.set_fs_type(frg::string<MemoryAllocator>(getSysdepsAllocator(), fstype));
+
+ auto [offer, send_head, send_tail, recv_resp] =
+ exchangeMsgsSync(
+ getPosixLane(),
+ helix_ng::offer(
+ helix_ng::sendBragiHeadTail(req, getSysdepsAllocator()),
+ helix_ng::recvInline()
+ )
+ );
+
+ HEL_CHECK(offer.error());
+ HEL_CHECK(send_head.error());
+ HEL_CHECK(send_tail.error());
+ HEL_CHECK(recv_resp.error());
+
+ auto resp = *bragi::parse_head_only<managarm::posix::SvrResponse>(recv_resp, getSysdepsAllocator());
+ if(resp.error() == managarm::posix::Errors::FILE_NOT_FOUND)
+ return ENOENT;
+ __ensure(resp.error() == managarm::posix::Errors::SUCCESS);
+ return 0;
+}
+
+} //namespace mlibc