diff --git a/Userland/Utilities/mount.cpp b/Userland/Utilities/mount.cpp index 79d7921e521..8292b1111a6 100644 --- a/Userland/Utilities/mount.cpp +++ b/Userland/Utilities/mount.cpp @@ -262,11 +262,14 @@ ErrorOr serenity_main(Main::Arguments arguments) } else { if (fs_type.is_empty()) 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; }