diff options
author | Andreas Kling <kling@serenityos.org> | 2021-12-16 20:23:21 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-12-16 22:48:17 +0100 |
commit | f69bd3bd46534f3e675d32e86d360830e5fab100 (patch) | |
tree | 696bb8f16d0c5bf21c205bdaf3d9f49cec7f68f8 /Userland/Libraries/LibCore/System.cpp | |
parent | e923762afc835b3d9b1e3226f74a17e7d164a23b (diff) | |
download | serenity-f69bd3bd46534f3e675d32e86d360830e5fab100.zip |
LibCore: Add syscall wrapper for mount()
Diffstat (limited to 'Userland/Libraries/LibCore/System.cpp')
-rw-r--r-- | Userland/Libraries/LibCore/System.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 9e3fe04c76..f84495a853 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -90,6 +90,22 @@ ErrorOr<void> setgroups(Span<gid_t const> gids) return Error::from_syscall("setgroups"sv, -errno); return {}; } + +ErrorOr<void> mount(int source_fd, StringView target, StringView fs_type, int flags) +{ + if (target.is_null() || fs_type.is_null()) + return Error::from_errno(EFAULT); + + Syscall::SC_mount_params params { + { target.characters_without_null_termination(), target.length() }, + { fs_type.characters_without_null_termination(), fs_type.length() }, + source_fd, + flags + }; + int rc = syscall(SC_mount, ¶ms); + HANDLE_SYSCALL_RETURN_VALUE("mount", rc, {}); +} + #endif ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigaction* old_action) @@ -431,4 +447,22 @@ ErrorOr<bool> isatty(int fd) return rc == 1; } +ErrorOr<void> symlink(StringView target, StringView link_path) +{ +#ifdef __serenity__ + Syscall::SC_symlink_params params { + .target = { target.characters_without_null_termination(), target.length() }, + .linkpath = { link_path.characters_without_null_termination(), link_path.length() }, + }; + int rc = syscall(SC_symlink, ¶ms); + HANDLE_SYSCALL_RETURN_VALUE("symlink"sv, rc, {}); +#else + String target_string = target; + String link_path_string = link_path; + if (::symlink(target_string.characters(), link_path_string.characters()) < 0) + return Error::from_syscall("symlink"sv, -errno); + return {}; +#endif +} + } |