Skip to content

Conversation

Foutete
Copy link
Contributor

@Foutete Foutete commented Sep 19, 2025

When an USB Device can't be accessed, snagrecover prints a generic error message stating to check presence
and access right.
Improve this by testing if the USB error is a permission error. If so log an error message and some hints
on how to solve it.

@Foutete Foutete force-pushed the usb_access_permission branch from f804fb6 to 4cd9975 Compare September 19, 2025 17:01
When an USB Device can't be accessed, snagrecover prints
a generic error message stating to check presence
and access right.
Improve this by testing if the USB error is a permission
error. If so log an error message and some hints
on how to solve it.

Signed-off-by: François Foltete <[email protected]>
@Foutete Foutete force-pushed the usb_access_permission branch from 4cd9975 to 9f72262 Compare September 22, 2025 08:57
Copy link
Collaborator

@rgantois rgantois left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! I've requested a few changes.

except usb.USBError as e:
if e.errno == errno.EACCES:
logger.error(
f"USB Device has been found at address {pretty_addr} but can't be accessed because of permission issue."
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/has been found/was found/
s/of permission issue/of a device file access rights issue/

"Please check your udev config (refer to README.md#Installation on Linux)."
)
logger.error(
"The following udev rule allow access to the USB device:"
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/allow access/grants access/

)
elif sys.platform == "win32":
logger.error(
"Please check your installation (refer to README.md#Installation on Windows 10 or 11)."
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to be more specific, a USB access rights issue on Windows would likely be due to no appropriate libusb driver being bound to the device.

So:

"Please check that the 'libusb-win32' driver is bound to this USB device ID: {dev.idProduct:04x}:{dev.idVendor:04x}"
"This is usually done with the Zadig tool, please check the Snagboot installation guide for more information."

"The following udev rule allow access to the USB device:"
)
logger.error(
f'SUBSYSTEM=="usb", ATTRS{{idVendor}}=="{dev.idProduct:x}", ATTRS{{idProduct}}=="{dev.idVendor:x}", MODE="0660", TAG+="uaccess"'
Copy link
Collaborator

Choose a reason for hiding this comment

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

USB vendor/device ID pairs should be formatted with 4 hexadecimal digits and leading zeros, so: {...:04x}.

)

if error_on_fail:
# Don't retry if it is a permission issue
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will still allow retrying if error_on_fail is false though.

Moreover, I'm wondering if not retrying is correct or not. After all, the udev rule could take some time to kick in... Therefore, I think we should only run the access rights check on the last retry.

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