USBデバイスが見つかりません

USBデバイスが見つかりません

私は現在、もっと学ぶためにUSBを研究しています。

lsusb私は私のシステムのUSBバスとデバイスに関する情報を表示しました。 Linuxでは、基本的にすべてがディレクトリファイルであることを知り、lsusbが読み取るディレクトリを見つけようとしました。 。usbdevfsという疑似ファイルシステムが見つかりました/proc/bus/usb

ただし、ディレクトリがないため、そのディレクトリに移動できません。結果からディレクトリをgrepingしようとしましたが、mount成功しませんでした。すばやくcd / && find -name usbディレクトリにリンクされますが、/sys/bus/usb調査では/dev/bus/usbシンボリックリンクのみが提供されます。/proc/sys/bus/usb/devices/sys/devices/pci00[...]

注:

  • 私はDebian Busterを使います。
  • USBデバイスに問題はありません(うまくいきます)。

それでは、私のUSBデバイスはどこにありますか?

ベストアンサー1

読み取っているディレクトリとファイルをすばやく見つけるには、lsusbコマンドを追跡してopen()システムコールを検索します。

strace lsusb 2>&1 | grep ^open
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libusb-1.0.so.0", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libudev.so.1", O_RDONLY|O_CLOEXEC) = 3
...
openat(AT_FDCWD, "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-6/uevent", O_RDONLY|O_CLOEXEC) = 7
openat(AT_FDCWD, "/sys/bus/usb/devices/1-6/busnum", O_RDONLY|O_CLOEXEC) = 7
openat(AT_FDCWD, "/sys/bus/usb/devices/1-6/devnum", O_RDONLY|O_CLOEXEC) = 7
openat(AT_FDCWD, "/sys/bus/usb/devices/1-6/speed", O_RDONLY|O_CLOEXEC) = 7
openat(AT_FDCWD, "/sys/bus/usb/devices/1-6/descriptors", O_RDONLY|O_CLOEXEC) = 7
...

で終わる行は無視してください。ENOENTこれは、開こうとしているファイルが存在しないことを意味します。また、いくつかの変更も確認できます。

パラメータが何であるかを知りたい場合は、openat()マニュアルページを読んでシステムコールのセクション2を使用してください。

$ man 2 open
OPEN(2)                                                                                   Linux Programmer's Manual                                                                                   OPEN(2)

NAME
       open, openat, creat - open and possibly create a file

SYNOPSIS
       #include <sys/types.h>
       #include <sys/stat.h>
       #include <fcntl.h>

/proctryに関する情報$ man 5 procですが、今はもっと興味があるでしょう/sys

$ mount | grep '/sys '
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
^^^^^

$ apropos sysfs
sysfs (2)            - get filesystem type information
sysfs (5)            - a filesystem for exporting kernel objects <== you want this one

$ man 5 sysfs
SYSFS(5)                              Linux Programmer's Manual                              SYSFS(5)

NAME
       sysfs - a filesystem for exporting kernel objects

DESCRIPTION
       The  sysfs filesystem is a pseudo-filesystem which provides an interface to kernel data struc‐
       tures.  (More precisely, the files and directories in sysfs provide  a  view  of  the  kobject
       structures  defined  internally within the kernel.)  The files under sysfs provide information
       about devices, kernel modules, filesystems, and other kernel components.

USBデバイスにアクセスするためのデバイスファイルを探している場合は、次のコマンドを試してください。

$ find /dev -ls | grep usb
find: ‘/dev/vboxusb’: Permission denied
  2421522      0 drwxr-xr-x   2 root     root           60 Oct 21 17:47 /dev/usb
  2421523      0 crw-------   1 root     root     180,   0 Oct 21 17:47 /dev/usb/hiddev0
    29281      0 lrwxrwxrwx   1 root     root           12 Oct 20 14:33 /dev/v4l/by-path/pci-0000:00:14.0-usb-0:5:1.0-video-index0 -> ../../video0
    25532      0 lrwxrwxrwx   1 root     root           12 Oct 20 14:33 /dev/v4l/by-path/pci-0000:00:14.0-usb-0:5:1.0-video-index1 -> ../../video1

おすすめ記事