Sfoglia il codice sorgente

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.
Andreas Kling 6 anni fa
parent
commit
7c7343de98
1 ha cambiato i file con 14 aggiunte e 7 eliminazioni
  1. 14 7
      Kernel/Process.cpp

+ 14 - 7
Kernel/Process.cpp

@@ -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);
 
-    dbg() << "mount: attempting to mount device (" << major << "," << minor << ") on " << mountpoint;
+    auto* device = VFS::the().get_device(major, minor);
+    if (!device) {
+        dbg() << "mount: device (" << major << "," << minor << ") not found";
+        return -ENODEV;
+    }
 
-    // Do a quick check to make sure we're not passing nullptr to Ext2FS::create!
-    if (dev == nullptr)
+    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);
+    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