Improve partition name extraction logic#381
Conversation
This allows us to recognize USB sticks that have an ISO9660 image directly written on it (e.g., GhostBSD). Upstream PR: gnustep#381
There was a problem hiding this comment.
Pull request overview
This PR improves the partition name extraction logic in NSWorkspace to properly handle modern Linux block device naming schemes. The previous implementation naively truncated device names to 3 characters, which failed for devices like NVMe drives (nvme0n1p1), MMC/SD cards (mmcblk0p1), and ISO9660 images on USB sticks.
Changes:
- Updated copyright year to 2026
- Replaced crude 3-character truncation with comprehensive device-type-aware partition stripping logic
- Added support for nvme, mmcblk, sd, hd, vd, and xvd device naming patterns with proper partition suffix removal
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| else if ([devName hasPrefix:@"sd"] || [devName hasPrefix:@"hd"] || | ||
| [devName hasPrefix:@"vd"] || [devName hasPrefix:@"xvd"]) | ||
| { | ||
| /* For sd/hd/vd devices, remove trailing digits (sda1 → sda) */ |
There was a problem hiding this comment.
The comment mentions only "sd/hd/vd devices" but the code also handles "xvd" devices (Xen virtual disks). The comment should include "xvd" for completeness.
| /* For sd/hd/vd devices, remove trailing digits (sda1 → sda) */ | |
| /* For sd/hd/vd/xvd devices, remove trailing digits (sda1 → sda) */ |
|
|
||
| /* Extract block device name by removing partition suffix | ||
| * Handle various device naming schemes: | ||
| * sd*, hd* → just remove trailing digits (sda1 → sda) |
There was a problem hiding this comment.
The comment states that only sd* and hd* devices have trailing digits removed, but the code also handles vd* and xvd* devices (virtual disk devices). The comment should be updated to reflect all device types handled: "sd*, hd*, vd*, xvd* → remove trailing digits".
fredkiefer
left a comment
There was a problem hiding this comment.
Looks good to me.
The Copilot comments are really very helpful, your should address these. Having a test would be nice, but not strictly required.
I would prefer to have this new code in a helper function/method, but again this is not required. I also prefer to have a space after the colon in a method call, but the code around this change is also lacking that.
|
It would be great to finish this PR. There are only minor things missing. |
Extract partition name stripping into a helper method _stripPartitionSuffixFromDeviceName: supporting modern Linux block device naming schemes (nvme, mmcblk, sd, hd, vd, xvd). Previously only sd/hd were handled with crude 3-char truncation. Without this fix, ISO9660 images directly written to USB sticks are not recognized properly.
|
Thanks for merging @fredkiefer |
Without this fix, a ISO9660 image directly written to a USB stick (e.g., GhostBSD, Linux Live system) is not recognized properly. With this fix, it is.
Original comment said
// This is a very crude way of removing the partition number.