mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:27:42 +00:00
Kernel: Pass a parameter struct to mount()
This was the last remaining syscall that took a null-terminated string and figured out how long it was by walking it in kernelspace *shudder*.
This commit is contained in:
parent
e380142853
commit
f5092b1c7e
5 changed files with 43 additions and 24 deletions
|
@ -3575,28 +3575,35 @@ int Process::sys$reboot()
|
|||
return ESUCCESS;
|
||||
}
|
||||
|
||||
int Process::sys$mount(const char* device_path, const char* mountpoint, const char* fstype)
|
||||
int Process::sys$mount(const Syscall::SC_mount_params* user_params)
|
||||
{
|
||||
if (!is_superuser())
|
||||
return -EPERM;
|
||||
|
||||
SmapDisabler disabler;
|
||||
if (!validate_read_typed(user_params))
|
||||
return -EFAULT;
|
||||
Syscall::SC_mount_params params;
|
||||
copy_from_user(¶ms, user_params);
|
||||
|
||||
if (!validate_read_str(device_path) || !validate_read_str(mountpoint) || !validate_read_str(fstype))
|
||||
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 (source.is_null() || target.is_null() || fs_type.is_null())
|
||||
return -EFAULT;
|
||||
|
||||
dbg() << "mount " << fstype << ": device " << device_path << " @ " << mountpoint;
|
||||
dbg() << "mount " << fs_type << ": source " << source << " @ " << target;
|
||||
|
||||
auto custody_or_error = VFS::the().resolve_path(mountpoint, current_directory());
|
||||
auto custody_or_error = VFS::the().resolve_path(target, current_directory());
|
||||
if (custody_or_error.is_error())
|
||||
return custody_or_error.error();
|
||||
|
||||
auto& mountpoint_custody = custody_or_error.value();
|
||||
auto& target_custody = custody_or_error.value();
|
||||
|
||||
RefPtr<FS> fs { nullptr };
|
||||
RefPtr<FS> fs;
|
||||
|
||||
if (strcmp(fstype, "ext2") == 0 || strcmp(fstype, "Ext2FS") == 0) {
|
||||
auto metadata_or_error = VFS::the().lookup_metadata(device_path, current_directory());
|
||||
if (fs_type == "ext2" || fs_type == "Ext2FS") {
|
||||
auto metadata_or_error = VFS::the().lookup_metadata(source, current_directory());
|
||||
if (metadata_or_error.is_error())
|
||||
return metadata_or_error.error();
|
||||
|
||||
|
@ -3616,25 +3623,26 @@ int Process::sys$mount(const char* device_path, const char* mountpoint, const ch
|
|||
|
||||
auto& disk_device = static_cast<DiskDevice&>(*device);
|
||||
|
||||
dbg() << "mount: attempting to mount device (" << major << "," << minor << ") on " << mountpoint;
|
||||
dbg() << "mount: attempting to mount device (" << major << "," << minor << ") on " << target;
|
||||
|
||||
fs = Ext2FS::create(disk_device);
|
||||
} else if (strcmp(fstype, "proc") == 0 || strcmp(fstype, "ProcFS") == 0)
|
||||
} else if (fs_type == "proc" || fs_type == "ProcFS") {
|
||||
fs = ProcFS::create();
|
||||
else if (strcmp(fstype, "devpts") == 0 || strcmp(fstype, "DevPtsFS") == 0)
|
||||
} else if (fs_type == "devpts" || fs_type == "DevPtsFS") {
|
||||
fs = DevPtsFS::create();
|
||||
else if (strcmp(fstype, "tmp") == 0 || strcmp(fstype, "TmpFS") == 0)
|
||||
} else if (fs_type == "tmp" || fs_type == "TmpFS") {
|
||||
fs = TmpFS::create();
|
||||
else
|
||||
return -ENODEV;
|
||||
|
||||
if (!fs->initialize()) {
|
||||
dbg() << "mount: failed to initialize " << fstype << " filesystem on " << device_path;
|
||||
} else {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
auto result = VFS::the().mount(fs.release_nonnull(), mountpoint_custody);
|
||||
dbg() << "mount: successfully mounted " << device_path << " on " << mountpoint;
|
||||
if (!fs->initialize()) {
|
||||
dbg() << "mount: failed to initialize " << fs_type << " filesystem on " << source;
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
auto result = VFS::the().mount(fs.release_nonnull(), target_custody);
|
||||
dbg() << "mount: successfully mounted " << source << " on " << target;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ public:
|
|||
int sys$unlink(const char* pathname, size_t path_length);
|
||||
int sys$symlink(const Syscall::SC_symlink_params*);
|
||||
int sys$rmdir(const char* pathname, size_t path_length);
|
||||
int sys$mount(const char* device, const char* mountpoint, const char* fstype);
|
||||
int sys$mount(const Syscall::SC_mount_params*);
|
||||
int sys$umount(const char* mountpoint, size_t mountpoint_length);
|
||||
int sys$chmod(const char* pathname, size_t path_length, mode_t);
|
||||
int sys$fchmod(int fd, mode_t);
|
||||
|
|
|
@ -355,6 +355,12 @@ struct SC_rename_params {
|
|||
StringArgument new_path;
|
||||
};
|
||||
|
||||
struct SC_mount_params {
|
||||
StringArgument source;
|
||||
StringArgument target;
|
||||
StringArgument fs_type;
|
||||
};
|
||||
|
||||
void initialize();
|
||||
int sync();
|
||||
|
||||
|
|
|
@ -610,9 +610,14 @@ int reboot()
|
|||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int mount(const char* device, const char* mountpoint, const char* fstype)
|
||||
int mount(const char* source, const char* target, const char* fs_type)
|
||||
{
|
||||
int rc = syscall(SC_mount, device, mountpoint, fstype);
|
||||
if (!source || !target || !fs_type) {
|
||||
errno = EFAULT;
|
||||
return -1;
|
||||
}
|
||||
Syscall::SC_mount_params params { { source, strlen(source) }, { target, strlen(target) }, { fs_type, strlen(fs_type) } };
|
||||
int rc = syscall(SC_mount, ¶ms);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ int fchown(int fd, uid_t, gid_t);
|
|||
int ftruncate(int fd, off_t length);
|
||||
int halt();
|
||||
int reboot();
|
||||
int mount(const char* device, const char* mountpoint, const char* fstype);
|
||||
int mount(const char* source, const char* target, const char* fs_type);
|
||||
int umount(const char* mountpoint);
|
||||
|
||||
enum {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue