Explorar o código

Utilities/mount: Resolve regression on mounting non-storage-backed FSes

Without this patch, we fail on manually mounting RAMFS (which I tested
for) but any filesystem that is not backed by actual storage will fail.
This bug was introduced in 0739b5df11f2125f2f4b592e19c0d240620c5df6 and
now is resolved by checking if the source fd is negative, to avoid fail
of the fstat call on it.
Liav A. hai 1 ano
pai
achega
476b3703fd
Modificáronse 1 ficheiros con 8 adicións e 5 borrados
  1. 8 5
      Userland/Utilities/mount.cpp

+ 8 - 5
Userland/Utilities/mount.cpp

@@ -262,11 +262,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
         } else {
         } else {
             if (fs_type.is_empty())
             if (fs_type.is_empty())
                 fs_type = "ext2"sv;
                 fs_type = "ext2"sv;
-            auto stat = TRY(Core::System::fstat(fd));
-            if (!S_ISBLK(stat.st_mode))
-                TRY(mount_using_loop_device(fd, mountpoint, fs_type, flags));
-            else
-                TRY(Core::System::mount(fd, mountpoint, fs_type, flags));
+            if (fd >= 0) {
+                auto stat = TRY(Core::System::fstat(fd));
+                if (!S_ISBLK(stat.st_mode)) {
+                    TRY(mount_using_loop_device(fd, mountpoint, fs_type, flags));
+                    return 0;
+                }
+            }
+            TRY(Core::System::mount(fd, mountpoint, fs_type, flags));
         }
         }
         return 0;
         return 0;
     }
     }