diff options
Diffstat (limited to 'Kernel/Process.cpp')
-rw-r--r-- | Kernel/Process.cpp | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 28aca99bcb..054b987e50 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -4011,18 +4011,14 @@ int Process::sys$mount(const Syscall::SC_mount_params* user_params) if (!validate_read_and_copy_typed(¶ms, user_params)) return -EFAULT; - auto source_fd = params.source_fd; + auto source = validate_and_copy_string_from_user(params.source); auto target = validate_and_copy_string_from_user(params.target); auto fs_type = validate_and_copy_string_from_user(params.fs_type); - if (target.is_null() || fs_type.is_null()) + if (source.is_null() || target.is_null() || fs_type.is_null()) return -EFAULT; - auto description = file_description(source_fd); - if (!description.is_null()) - dbg() << "mount " << fs_type << ": source fd " << source_fd << " @ " << target; - else - dbg() << "mount " << fs_type << " @ " << target; + dbg() << "mount " << fs_type << ": source " << source << " @ " << target; auto custody_or_error = VFS::the().resolve_path(target, current_directory()); if (custody_or_error.is_error()) @@ -4034,24 +4030,28 @@ int Process::sys$mount(const Syscall::SC_mount_params* user_params) if (params.flags & MS_BIND) { // We're doing a bind mount. - if (description.is_null()) - return -EBADF; - ASSERT(description->custody()); - return VFS::the().bind_mount(*description->custody(), target_custody, params.flags); + auto source_or_error = VFS::the().resolve_path(source, current_directory()); + if (source_or_error.is_error()) + return source_or_error.error(); + auto& source_custody = source_or_error.value(); + return VFS::the().bind_mount(source_custody, target_custody, params.flags); } if (fs_type == "ext2" || fs_type == "Ext2FS") { - if (description.is_null()) - return -EBADF; - ASSERT(description->custody()); - if (!description->file().is_seekable()) { - dbg() << "mount: this is not a seekable file"; + auto source_or_error = VFS::the().open(source, O_RDWR, 0, current_directory()); + if (source_or_error.is_error()) + return source_or_error.error(); + + auto* device = source_or_error.value()->device(); + if (!device || !device->is_block_device()) { + dbg() << "mount: this is not a BlockDevice"; return -ENODEV; } + auto& block_device = static_cast<BlockDevice&>(*device); - dbg() << "mount: attempting to mount " << description->absolute_path() << " on " << target; + dbg() << "mount: attempting to mount " << block_device.absolute_path() << " on " << target; - fs = Ext2FS::create(*description); + fs = Ext2FS::create(block_device); } else if (fs_type == "proc" || fs_type == "ProcFS") { fs = ProcFS::create(); } else if (fs_type == "devpts" || fs_type == "DevPtsFS") { @@ -4063,15 +4063,12 @@ int Process::sys$mount(const Syscall::SC_mount_params* user_params) } if (!fs->initialize()) { - dbg() << "mount: failed to initialize " << fs_type << " filesystem, fd - " << source_fd; + dbg() << "mount: failed to initialize " << fs_type << " filesystem on " << source; return -ENODEV; } auto result = VFS::the().mount(fs.release_nonnull(), target_custody, params.flags); - if (!description.is_null()) - dbg() << "mount: successfully mounted " << description->absolute_path() << " on " << target; - else - dbg() << "mount: successfully mounted " << target; + dbg() << "mount: successfully mounted " << source << " on " << target; return result; } |