diff options
author | Liav A <liavalb@gmail.com> | 2020-03-26 02:51:16 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-02 12:03:08 +0200 |
commit | a60ea79a41845767ce40f225de20da7c99534ad1 (patch) | |
tree | 771b082c27a3cf8060fb23a8548be83ec8837677 /Kernel | |
parent | 6b59311d4bdc1447e085573f9bd2c42819e264dd (diff) | |
download | serenity-a60ea79a41845767ce40f225de20da7c99534ad1.zip |
Kernel & Userland: Allow to mount image files formatted with Ext2FS
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Process.cpp | 43 | ||||
-rw-r--r-- | Kernel/Syscall.h | 2 |
2 files changed, 24 insertions, 21 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 054b987e50..28aca99bcb 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -4011,14 +4011,18 @@ int Process::sys$mount(const Syscall::SC_mount_params* user_params) if (!validate_read_and_copy_typed(¶ms, user_params)) return -EFAULT; - auto source = validate_and_copy_string_from_user(params.source); + auto source_fd = params.source_fd; auto target = validate_and_copy_string_from_user(params.target); auto fs_type = validate_and_copy_string_from_user(params.fs_type); - if (source.is_null() || target.is_null() || fs_type.is_null()) + if (target.is_null() || fs_type.is_null()) return -EFAULT; - dbg() << "mount " << fs_type << ": source " << source << " @ " << target; + 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; auto custody_or_error = VFS::the().resolve_path(target, current_directory()); if (custody_or_error.is_error()) @@ -4030,28 +4034,24 @@ int Process::sys$mount(const Syscall::SC_mount_params* user_params) if (params.flags & MS_BIND) { // We're doing a bind mount. - 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 (description.is_null()) + return -EBADF; + ASSERT(description->custody()); + return VFS::the().bind_mount(*description->custody(), target_custody, params.flags); } if (fs_type == "ext2" || fs_type == "Ext2FS") { - 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"; + if (description.is_null()) + return -EBADF; + ASSERT(description->custody()); + if (!description->file().is_seekable()) { + dbg() << "mount: this is not a seekable file"; return -ENODEV; } - auto& block_device = static_cast<BlockDevice&>(*device); - dbg() << "mount: attempting to mount " << block_device.absolute_path() << " on " << target; + dbg() << "mount: attempting to mount " << description->absolute_path() << " on " << target; - fs = Ext2FS::create(block_device); + fs = Ext2FS::create(*description); } else if (fs_type == "proc" || fs_type == "ProcFS") { fs = ProcFS::create(); } else if (fs_type == "devpts" || fs_type == "DevPtsFS") { @@ -4063,12 +4063,15 @@ int Process::sys$mount(const Syscall::SC_mount_params* user_params) } if (!fs->initialize()) { - dbg() << "mount: failed to initialize " << fs_type << " filesystem on " << source; + dbg() << "mount: failed to initialize " << fs_type << " filesystem, fd - " << source_fd; return -ENODEV; } auto result = VFS::the().mount(fs.release_nonnull(), target_custody, params.flags); - dbg() << "mount: successfully mounted " << source << " on " << target; + if (!description.is_null()) + dbg() << "mount: successfully mounted " << description->absolute_path() << " on " << target; + else + dbg() << "mount: successfully mounted " << target; return result; } diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index cfb072c650..d3167bff87 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -395,7 +395,7 @@ struct SC_rename_params { }; struct SC_mount_params { - StringArgument source; + int source_fd; StringArgument target; StringArgument fs_type; int flags; |