Skip to content

Mark empty optical drives as inactive on Linux - #1066

Open
gmipf wants to merge 11 commits into
SabreTools:masterfrom
gmipf:pr/13-linux-disc-active
Open

gmipf wants to merge 11 commits into
SabreTools:masterfrom
gmipf:pr/13-linux-disc-active

Conversation

@gmipf

@gmipf gmipf commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

This builds on #1063, only the last commit is new. It uses the udev check that #1063 added.

On Windows, MPF marks a drive that is not ready as inactive, so a drive with a disc is selected first. On Linux, every optical drive was marked as active, so an empty drive was selected like one with a disc. Optical drives on Linux are now marked as active unless udev saw no disc in them, and RefreshDrive asks udev again, as it reads IsReady again on Windows. GetUnixBlockDevice moved to Drive, so that the sg devices are checked through their sr device.

Measured on Linux with a USB Plextor PX-760A and two empty drives:

  • With a disc only in the Plextor, its sr and sg devices are the only ones marked as active. Before, all six were. The output names are the same as before.
  • With the tray open, the Plextor is marked as inactive. Listing and refreshing the drives did not close the tray (5 times each, 3 cycles).
  • After closing the tray, the Plextor is marked as active again after 12.1 s, when udev has seen the disc (3 cycles). On Windows 11, IsReady of the same drive became true 11.8 s after closing the tray.

Nothing changes on macOS, where a drive without a disc has no /dev/disk node and is not listed.

Prepared with AI assistance (Claude Opus 5.5) and reviewed before submission.

gmipf and others added 11 commits October 19, 2026 19:53
DiscFileSystem gives read-only access to the files of a disc. A drive
letter or a mounted folder is read as a folder, a dump image or the
device path of an optical drive on Linux is read through the ISO 9660
and UDF readers of SabreTools.Serialization, and on macOS the mount
point macOS created is found with "mount".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
System detection, the submission information and the protection scan
read the files of the disc through DiscFileSystem, so a disc in a drive
that is not mounted is read as well. After a dump, a drive path that is
not a folder is no longer scanned as one: the files of the dump image
are scanned instead, writing to a temporary folder only what the
scanner reads. The new "Scan Dump Image Files" option does the same for
drive letters on Windows, and MPF.Check scans the dump image when
--scan is given without --path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Opening the device of an optical drive makes the Linux kernel close the
tray if it is open, and MPF opens the device to read the disc files when
it starts, when a drive is selected and when the label is updated. udev
keeps whether there is a disc in the drive, so the device is not opened
if udev saw no disc in it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Optical drives on Linux were always marked as active, so an empty drive
was selected at startup like a drive with a disc. They are now marked as
active unless udev saw no disc in them, like a drive that is not ready
on Windows, and udev is asked again when the drive is refreshed. The
output name of an empty optical drive on Linux stays the default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DriveInfo does not report the file system and size of a disc that is
not mounted, so on Linux the media type could not be detected from
them and the size check of the Xbox 360 detection always passed. They
are now read from the disc in an optical drive when the drives are
listed and when a drive is refreshed, with the readers used for its
files, and named and sized as Windows reports them for a mounted disc:
CDFS with the size of the ISO 9660 volume, or UDF with the size up to
the end of the UDF partition.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Opening the device of a drive with an open tray makes the kernel close
the tray. udev notices an opened tray up to two seconds later, so
reading the disc in that moment still closed the tray. The device is
now opened with O_NONBLOCK, which leaves the tray as it is, and reads
fail while there is no disc. It is still read in random order, as
before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On macOS, the file system of a disc was left empty and its size was the
size of the whole disc that diskutil reports, in raw 2352-byte sectors
for a CD, so the media type was not detected. They are now read from the
disc in an optical drive when the drives are listed, like on Linux, from
the raw device of the whole disc, which belongs to the user logged in at
the console. The devices of the single tracks belong to root, and the
block device of the whole disc cannot be opened when the disc has audio
tracks, as macOS mounts them on it. The raw device can only be read in
whole blocks, so VolumeStream can now read whole blocks and keeps the
ones it read, as reading the file system reads some sectors more than
once and the raw device does not cache them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant