mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:37:45 +00:00
Kernel+LibC+Userland: Support mounting other kinds of filesystems
This commit is contained in:
parent
66a0a12435
commit
425c356288
6 changed files with 58 additions and 46 deletions
|
@ -9,6 +9,9 @@
|
|||
#include <Kernel/Devices/NullDevice.h>
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
#include <Kernel/FileSystem/Ext2FileSystem.h>
|
||||
#include <Kernel/FileSystem/ProcFS.h>
|
||||
#include <Kernel/FileSystem/DevPtsFS.h>
|
||||
#include <Kernel/FileSystem/TmpFS.h>
|
||||
#include <Kernel/FileSystem/FIFO.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
#include <Kernel/FileSystem/InodeWatcher.h>
|
||||
|
@ -2735,15 +2738,15 @@ int Process::sys$reboot()
|
|||
return ESUCCESS;
|
||||
}
|
||||
|
||||
int Process::sys$mount(const char* device_path, const char* mountpoint)
|
||||
int Process::sys$mount(const char* device_path, const char* mountpoint, const char* fstype)
|
||||
{
|
||||
if (!is_superuser())
|
||||
return -EPERM;
|
||||
|
||||
if (!validate_read_str(device_path) || !validate_read_str(mountpoint))
|
||||
if (!validate_read_str(device_path) || !validate_read_str(mountpoint) || !validate_read_str(fstype))
|
||||
return -EFAULT;
|
||||
|
||||
dbg() << "mount: device " << device_path << " @ " << mountpoint;
|
||||
dbg() << "mount " << fstype << ": device " << device_path << " @ " << mountpoint;
|
||||
|
||||
auto custody_or_error = VFS::the().resolve_path(mountpoint, current_directory());
|
||||
if (custody_or_error.is_error())
|
||||
|
@ -2751,37 +2754,47 @@ int Process::sys$mount(const char* device_path, const char* mountpoint)
|
|||
|
||||
auto& mountpoint_custody = custody_or_error.value();
|
||||
|
||||
auto metadata_or_error = VFS::the().lookup_metadata(device_path, current_directory());
|
||||
if (metadata_or_error.is_error())
|
||||
return metadata_or_error.error();
|
||||
RefPtr<FS> fs { nullptr };
|
||||
|
||||
auto major = metadata_or_error.value().major_device;
|
||||
auto minor = metadata_or_error.value().minor_device;
|
||||
if (strcmp(fstype, "ext2") == 0 || strcmp(fstype, "Ext2FS") == 0) {
|
||||
auto metadata_or_error = VFS::the().lookup_metadata(device_path, current_directory());
|
||||
if (metadata_or_error.is_error())
|
||||
return metadata_or_error.error();
|
||||
|
||||
auto* device = VFS::the().get_device(major, minor);
|
||||
if (!device) {
|
||||
dbg() << "mount: device (" << major << "," << minor << ") not found";
|
||||
auto major = metadata_or_error.value().major_device;
|
||||
auto minor = metadata_or_error.value().minor_device;
|
||||
|
||||
auto* device = VFS::the().get_device(major, minor);
|
||||
if (!device) {
|
||||
dbg() << "mount: device (" << major << "," << minor << ") not found";
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (!device->is_disk_device()) {
|
||||
dbg() << "mount: device (" << major << "," << minor << ") is not a DiskDevice";
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
auto& disk_device = static_cast<DiskDevice&>(*device);
|
||||
|
||||
dbg() << "mount: attempting to mount device (" << major << "," << minor << ") on " << mountpoint;
|
||||
|
||||
fs = Ext2FS::create(disk_device);
|
||||
} else if (strcmp(fstype, "proc") == 0 || strcmp(fstype, "ProcFS") == 0)
|
||||
fs = ProcFS::create();
|
||||
else if (strcmp(fstype, "devpts") == 0 || strcmp(fstype, "DevPtsFS") == 0)
|
||||
fs = DevPtsFS::create();
|
||||
else if (strcmp(fstype, "tmp") == 0 || strcmp(fstype, "TmpFS") == 0)
|
||||
fs = TmpFS::create();
|
||||
else
|
||||
return -ENODEV;
|
||||
|
||||
if (!fs->initialize()) {
|
||||
dbg() << "mount: failed to initialize " << fstype << " filesystem on " << device_path;
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (!device->is_disk_device()) {
|
||||
dbg() << "mount: device (" << major << "," << minor << ") is not a DiskDevice";
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
auto& disk_device = static_cast<DiskDevice&>(*device);
|
||||
|
||||
dbg() << "mount: attempting to mount device (" << major << "," << minor << ") on " << mountpoint;
|
||||
|
||||
// We currently only support ext2. Sorry :^)
|
||||
auto ext2fs = Ext2FS::create(disk_device);
|
||||
if (!ext2fs->initialize()) {
|
||||
dbg() << "mount: could not find ext2 filesystem on " << device_path;
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
// Let's mount the volume now
|
||||
auto result = VFS::the().mount(ext2fs, mountpoint_custody);
|
||||
auto result = VFS::the().mount(fs.release_nonnull(), mountpoint_custody);
|
||||
dbg() << "mount: successfully mounted " << device_path << " on " << mountpoint;
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ public:
|
|||
int sys$unlink(const char* pathname);
|
||||
int sys$symlink(const char* target, const char* linkpath);
|
||||
int sys$rmdir(const char* pathname);
|
||||
int sys$mount(const char* device, const char* mountpoint);
|
||||
int sys$mount(const char* device, const char* mountpoint, const char* fstype);
|
||||
int sys$umount(const char* mountpoint);
|
||||
int sys$read_tsc(u32* lsw, u32* msw);
|
||||
int sys$chmod(const char* pathname, mode_t);
|
||||
|
|
|
@ -293,7 +293,7 @@ static u32 handle(RegisterDump& regs, u32 function, u32 arg1, u32 arg2, u32 arg3
|
|||
break;
|
||||
}
|
||||
case Syscall::SC_mount:
|
||||
return current->process().sys$mount((const char*)arg1, (const char*)arg2);
|
||||
return current->process().sys$mount((const char*)arg1, (const char*)arg2, (const char*)arg3);
|
||||
case Syscall::SC_reboot: {
|
||||
return current->process().sys$reboot();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue