Skip to content

Enumerate fixed/removable drives on Linux and order the drive list#990

Merged
mnadareski merged 3 commits into
SabreTools:masterfrom
gmipf:pr/3-linux-fixed-drives
Jun 24, 2026
Merged

Enumerate fixed/removable drives on Linux and order the drive list#990
mnadareski merged 3 commits into
SabreTools:masterfrom
gmipf:pr/3-linux-fixed-drives

Conversation

@gmipf

@gmipf gmipf commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Two related improvements to the Linux drive list, building on #980 (sr/sg enumeration) and #981 (optical drives active).

What this PR does

1. Enumerate fixed and removable drives on Linux (gated)
On Windows the drive list includes fixed and removable drives when IgnoreFixedDrives is off; the Linux branch only added optical nodes, so it was more restrictive. This adds AppendUnixFixedDrives, which enumerates whole block devices from /sys/block (mirroring the optical enumerator) and honors the same existing Options.GUI.IgnoreFixedDrives toggle — no new option or UI.

  • Reads world-readable sysfs; the removable flag selects HardDisk vs Removable, size comes from sysfs.
  • The fixed-drive enumerator skips non-target nodes: virtual block devices (dm-, loop, md, nbd, ram, zd, zram), floppies (fd), and optical drives (sr, which are real targets but surfaced separately by the optical enumerator).
  • Fixed disks are marked active; removable drives are active only when media is present (mirrors DriveInfo.IsReady on Windows).
  • On Unix, fixed/removable come from sysfs rather than DriveInfo (which only exposes mount points like /, not dumpable device nodes). The Windows path is unchanged.

2. Order the drive list
Sorts the list with SabreTools.Text.Compare.NaturalComparer so device indices order numerically (e.g. sr2 before sr10) instead of lexically; Windows drive letters keep a natural, digit-aware order too.

The Linux enumeration helpers live in a separate partial class (Drive.Linux.cs), following the existing ThemeService.Linux.cs pattern, so a future macOS implementation can add its own counterpart.

What this PR does not do

  • No new UI or options (reuses IgnoreFixedDrives).
  • Does not grant non-root raw device access — enumeration only reads sysfs; dumping a fixed disk still needs the usual privileges.
  • Does not touch macOS/BSD enumeration, and does not add the mounted-path/filesystem reader for protection scans (separate future work).
  • No dependencies added.

Tests

MPF.Frontend.Test/DriveTests.cs: hermetic tests (temp fake-sysfs trees, injected roots) for the optical and fixed/removable enumerators (sr/sg matching, excluded-prefix coverage, removable/size classification, missing-metadata fallback). No real devices touched. Built net20 through net10.0, all green.

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

gmipf and others added 2 commits June 23, 2026 18:57
Surface /dev block devices (sda, nvme0n1, ...) on Linux when IgnoreFixedDrives is off, mirroring the existing optical enumeration. Reads world-readable /sys/block (no elevated privileges); the removable flag selects HardDisk vs Removable, size comes from sysfs, and virtual devices (loop/ram/zram/dm-/md/sr/fd/nbd/zd) are skipped. Fixed disks are always active; removable drives are active only when media is present.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replace the plain alphabetical sort with a display order that puts Linux optical block nodes (/dev/sr*) before their generic SCSI counterparts (/dev/sg*), and compares trailing indices numerically so sr2 sorts before sr10. Windows drive letters and fixed/removable device nodes keep a natural, digit-aware order.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@mnadareski mnadareski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some general comments before I can check into the logic.

Comment thread MPF.Frontend/Drive.cs
Comment thread MPF.Frontend/Drive.cs Outdated
Comment thread MPF.Frontend/Drive.cs Outdated
Comment thread MPF.Frontend/Drive.cs Outdated
Comment thread MPF.Frontend/Drive.cs Outdated
Comment thread MPF.Frontend/Drive.cs Outdated
- Sort the drive list with SabreTools.Text.Compare.NaturalComparer instead
  of a hand-rolled comparer. This drops the previous optical-first ranking,
  so the list is now plain natural order (e.g. /dev/sg* before /dev/sr*).
- Guard the Unix append entry points with a PlatformID.Unix check.
- Move the Linux enumeration helpers and the excluded-prefix field into a
  new partial class file, Drive.Linux.cs.
- Extract UnixBlockDevice into its own file.
- Add braces to the Win32NT branch and order the excluded-prefix list
  alphabetically with a comment per entry.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mnadareski mnadareski merged commit ba2c7ce into SabreTools:master Jun 24, 2026
1 check passed
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.

2 participants