From 570b2bddca6734997bc6a00d20dbe4f4993d546f Mon Sep 17 00:00:00 2001 From: digant73 Date: Wed, 29 Apr 2026 20:30:59 +0200 Subject: [PATCH] Avoid to open bd drive if no content is present --- Utilities/File.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index d58331e0e2..0059673336 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -1745,6 +1745,17 @@ fs::file::file(const std::string& path, bs_t mode) // (the following GetFileInformationByHandle() would always fail on a raw device). if (is_optical_raw_device(path)) { + DISK_GEOMETRY_EX geometry; + + // Try to retrieve information on content. If it fails, no disc is probably mounted so abort the file opening + if (!DeviceIoControl(handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, nullptr, 0, &geometry, sizeof(geometry), nullptr, nullptr)) + { + const DWORD last_error = GetLastError(); + CloseHandle(handle); + g_tls_error = to_error(last_error); + return; + } + m_file = std::make_unique(handle, true); return; }