You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何可靠识别Linux系统下对应QNAP前置USB口的/sys/device设备

问题:识别QNAP NAS前置USB接口以实现一键复制功能

Qnap TVS-x72XT正面面板的按钮和USB接口图片

大多数QNAP NAS的正面配有一个“复制”按钮,旁边是一个USB-A接口。按下该按钮会复制插入旁边USB接口的硬盘内容。我想为Linux开发该功能,但无法找到可靠的方法确定/sys/devices下哪个设备对应该前置USB接口。在我的设备上,插入该接口的USB3硬盘会显示在/sys/devices/.../usb2/2-4/2-4:1.0路径下,而USB2闪存盘则显示在/sys/devices/.../usb1/1-4/1-4:1.0路径下。

我曾以为通过/sys/devices/.../physical_location可以解决问题,但该接口对USB2和USB3设备上报的位置信息不一致:USB3设备的信息为{"horizontal_position": "left", "vertical_position": "lower", "panel": "left"},USB2设备则为{"horizontal_position": "center", "vertical_position": "lower", "panel": "left"}。

既然QNAP的系统可以实现该功能,那必然存在匹配该USB接口与对应存储设备的方法,但我搜索多日仍未找到。

补充说明

为准确说明,以下是各场景下的lsusb -tv输出:

前置USB口插入USB2设备时输出

# lsusb -tv
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 10000M
    ID 1d6b:0003 Linux Foundation 3.0 root hub
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub
    |__ Port 2: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        ID 2537:1081 Norelsys 
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 10000M
    ID 1d6b:0003 Linux Foundation 3.0 root hub
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub
    |__ Port 4: Dev 4, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive

前置USB口插入USB3设备时输出

# lsusb -tv
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 10000M
    ID 1d6b:0003 Linux Foundation 3.0 root hub
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub
    |__ Port 2: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        ID 2537:1081 Norelsys 
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 10000M
    ID 1d6b:0003 Linux Foundation 3.0 root hub
    |__ Port 4: Dev 20, If 0, Class=Mass Storage, Driver=uas, 5000M
        ID 04e8:61b5 Samsung Electronics Co., Ltd M3 Portable Hard Drive 2TB
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub

其他测试场景

  1. 后置两个接口分别插入USB2和USB3设备,前置接口无设备:
# lsusb -tv
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 10000M
    ID 1d6b:0003 Linux Foundation 3.0 root hub
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub
    |__ Port 2: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        ID 2537:1081 Norelsys 
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 10000M
    ID 1d6b:0003 Linux Foundation 3.0 root hub
    |__ Port 3: Dev 21, If 0, Class=Mass Storage, Driver=uas, 5000M
        ID 04e8:61b5 Samsung Electronics Co., Ltd M3 Portable Hard Drive 2TB
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub
    |__ Port 2: Dev 5, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
  1. 与上述情况相同,但两个设备互换,前置接口仍无设备:
# lsusb -tv 
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 10000M
    ID 1d6b:0003 Linux Foundation 3.0 root hub
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub
    |__ Port 2: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        ID 2537:1081 Norelsys 
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 10000M
    ID 1d6b:0003 Linux Foundation 3.0 root hub
    |__ Port 2: Dev 22, If 0, Class=Mass Storage, Driver=uas, 5000M
        ID 04e8:61b5 Samsung Electronics Co., Ltd M3 Portable Hard Drive 2TB
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub
    |__ Port 3: Dev 6, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
  1. 3个USB-A接口均插入USB2设备:
# lsusb -tv
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 10000M
    ID 1d6b:0003 Linux Foundation 3.0 root hub
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub
    |__ Port 2: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        ID 2537:1081 Norelsys 
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 10000M
    ID 1d6b:0003 Linux Foundation 3.0 root hub
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub
    |__ Port 2: Dev 12, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        ID 058f:6387 Alcor Micro Corp. Flash Drive
    |__ Port 3: Dev 11, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        ID 058f:6387 Alcor Micro Corp. Flash Drive
    |__ Port 4: Dev 10, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive

当设备为USB2类型时,始终使用Bus 01.Port 1,这无法帮助我区分设备是插入前置还是后置接口。另外注意Bus 03.Port 1似乎是承载QNAP系统的内部存储。

内容的提问来源于stack exchange,提问作者Augier

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 04:27:02