1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

Kernel+Userland: Split bind-mounting and re-mounting from mount syscall

These 2 are an actual separate types of syscalls, so let's stop using
special flags for bind mounting or re-mounting and instead let userspace
calling directly for this kind of actions.
This commit is contained in:
Liav A 2023-02-25 19:30:28 +02:00 committed by Andrew Kaster
parent 04b44a827a
commit 0bbd9040ef
10 changed files with 204 additions and 42 deletions

View file

@ -95,7 +95,15 @@ static bool mount_by_line(DeprecatedString const& line)
dbgln("Mounting {} ({}) on {}", filename, fstype, mountpoint);
auto error_or_void = Core::System::mount(fd, mountpoint, fstype, flags);
ErrorOr<void> error_or_void;
if (flags & MS_BIND)
error_or_void = Core::System::bindmount(fd, mountpoint, flags & ~MS_BIND);
else if (flags & MS_REMOUNT)
error_or_void = Core::System::remount(mountpoint, flags & ~MS_REMOUNT);
else
error_or_void = Core::System::mount(fd, mountpoint, fstype, flags);
if (error_or_void.is_error()) {
warnln("Failed to mount {} (FD: {}) ({}) on {}: {}", filename, fd, fstype, mountpoint, error_or_void.error());
return false;
@ -215,15 +223,27 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return 0;
}
if (!source.is_empty() && !mountpoint.is_empty()) {
if (fs_type.is_empty())
fs_type = "ext2"sv;
if (source.is_empty() && !mountpoint.is_empty()) {
int flags = !options.is_empty() ? parse_options(options) : 0;
if (!(flags & MS_REMOUNT))
return Error::from_string_literal("Expected valid source.");
TRY(Core::System::remount(mountpoint, flags & ~MS_REMOUNT));
return 0;
}
if (!source.is_empty() && !mountpoint.is_empty()) {
int flags = !options.is_empty() ? parse_options(options) : 0;
int const fd = TRY(get_source_fd(source));
TRY(Core::System::mount(fd, mountpoint, fs_type, flags));
if (flags & MS_BIND) {
TRY(Core::System::bindmount(fd, mountpoint, flags & ~MS_BIND));
} else if (flags & MS_REMOUNT) {
TRY(Core::System::remount(mountpoint, flags & ~MS_REMOUNT));
} else {
if (fs_type.is_empty())
fs_type = "ext2"sv;
TRY(Core::System::mount(fd, mountpoint, fs_type, flags));
}
return 0;
}