Skip to content

Commit da532ee

Browse files
committed
sdwire3: sdwirec: make block device detection more robust in linux
1 parent b303c7c commit da532ee

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

sdwire/backend/block_device_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ def _is_block_device_match_linux(
302302
# Typical path: /sys/devices/pci.../usb1/1-2/1-2.3/...
303303
# We look for patterns like "1-2.3" which indicate USB bus 1,
304304
# port path 2.3
305-
usb_match = re.search(r"/usb(\d+)/(\d+)-([0-9.]+)/", device_path)
305+
usb_match = re.search(
306+
r"/usb(\d+)/.*/(\d+)-([0-9.]+):.*/host", device_path
307+
)
306308
if usb_match:
307309
bus_num = int(usb_match.group(1))
308310
port_path = usb_match.group(3)

sdwire/backend/device/sdwirec.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
from pyftdi.ftdi import Ftdi
44
import usb.core
55
from sdwire.backend.device.usb_device import USBDevice, PortInfo
6-
from sdwire.backend.block_device_utils import map_usb_device_to_block_device, find_sibling_storage_device
6+
from sdwire.backend.block_device_utils import (
7+
map_usb_device_to_block_device,
8+
find_sibling_storage_device,
9+
)
710

811
log = logging.getLogger(__name__)
912

@@ -34,7 +37,7 @@ def _update_block_device(self) -> None:
3437

3538
def __str__(self) -> str:
3639
block_dev_str = self.block_dev if self.block_dev is not None else "None"
37-
return f"{self.serial_string}\t[{self.product_string}::{self.manufacturer_string}]\t{block_dev_str}"
40+
return f"{self.serial_string:<30}[{self.product_string}::{self.manufacturer_string}]\t\t{block_dev_str}"
3841

3942
def __repr__(self) -> str:
4043
return self.__str__()
@@ -66,6 +69,7 @@ def _set_sdwire(self, target: int) -> None:
6669
if not self.usb_device:
6770
log.error("USB device not available")
6871
import sys
72+
6973
print("USB device not available")
7074
sys.exit(1)
7175

@@ -77,6 +81,7 @@ def _set_sdwire(self, target: int) -> None:
7781
ftdi.close()
7882
except Exception as e:
7983
import sys
84+
8085
log.debug("error while updating ftdi device: %s", e, exc_info=True)
8186
print("couldnt switch sdwire device")
8287
sys.exit(1)

0 commit comments

Comments
 (0)