1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:58:11 +00:00

Kernel: mount() should fail if the provided device is not a disk device

In the future, we should allow mounting any block device. At the moment
there is too much filesystem code that depends on the underlying device
being a DiskDevice.
This commit is contained in:
Andreas Kling 2019-08-02 19:30:30 +02:00
parent a6fb055028
commit 7c7343de98

View file

@ -2755,20 +2755,27 @@ int Process::sys$mount(const char* device_path, const char* mountpoint)
auto major = metadata_or_error.value().major_device;
auto minor = metadata_or_error.value().minor_device;
auto* dev = VFS::the().get_device(major, minor);
auto* disk_device = static_cast<DiskDevice*>(dev);
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;
// Do a quick check to make sure we're not passing nullptr to Ext2FS::create!
if (dev == nullptr)
return -ENODEV;
// We currently only support ext2. Sorry :^)
auto ext2fs = Ext2FS::create(*disk_device);
auto ext2fs = Ext2FS::create(disk_device);
if (!ext2fs->initialize()) {
dbg() << "mount: could not find ext2 filesystem on " << device_path;
return -ENODEV; // Hmmm, this doesn't seem quite right....
return -ENODEV;
}
// Let's mount the volume now