mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-16 22:42:18 +00:00
Utilities: Add fusermount
This only contains the bare minimum amount of functionality required by libfuse.
This commit is contained in:
parent
a08d1637e2
commit
f5a74d7141
Notes:
sideshowbarker
2024-07-17 21:26:19 +09:00
Author: https://github.com/implicitfield
Commit: f5a74d7141
Pull-request: https://github.com/SerenityOS/serenity/pull/23098
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/supercomputer7
1 changed files with 58 additions and 0 deletions
58
Userland/Utilities/fusermount.cpp
Normal file
58
Userland/Utilities/fusermount.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2024, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/ByteString.h>
|
||||
#include <AK/Error.h>
|
||||
#include <Kernel/API/FileSystem/MountSpecificFlags.h>
|
||||
#include <Kernel/API/Ioctl.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibMain/Main.h>
|
||||
|
||||
static ErrorOr<void> set_mount_flag(ByteString key, u64 value, int mount_fd)
|
||||
{
|
||||
MountSpecificFlag flag;
|
||||
flag.key_string_length = key.bytes().size();
|
||||
flag.key_string_addr = key.bytes().data();
|
||||
flag.value_type = MountSpecificFlag::ValueType::UnsignedInteger;
|
||||
flag.value_length = 8;
|
||||
flag.value_addr = &value;
|
||||
|
||||
return Core::System::ioctl(mount_fd, MOUNT_IOCTL_SET_MOUNT_SPECIFIC_FLAG, &flag);
|
||||
}
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
StringView fd_string;
|
||||
StringView target;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.set_general_help("Mount a FUSE-based filesystem");
|
||||
args_parser.add_positional_argument(fd_string, "File descriptor to mount", "fd");
|
||||
args_parser.add_positional_argument(target, "Path to mount location", "target");
|
||||
args_parser.parse(arguments);
|
||||
|
||||
if (fd_string.is_empty())
|
||||
return Error::from_string_literal("No file descriptor passed");
|
||||
|
||||
if (target.is_empty())
|
||||
return Error::from_string_literal("No target passed");
|
||||
|
||||
auto maybe_fd = fd_string.to_number<int>();
|
||||
if (!maybe_fd.has_value())
|
||||
return Error::from_string_literal("Invalid file descriptor passed");
|
||||
|
||||
int fd = maybe_fd.release_value();
|
||||
|
||||
int mount_fd = TRY(Core::System::fsopen("FUSE"sv, 0));
|
||||
|
||||
TRY(set_mount_flag("fd", fd, mount_fd));
|
||||
TRY(set_mount_flag("rootmode", 40000, mount_fd));
|
||||
|
||||
TRY(Core::System::fsmount(mount_fd, -1, target));
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue