- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我需要知道如何找出/proc/bus/usb/devices 中/dev/sdX 设备映射到的条目。基本上,我需要知道给定 U 盘的供应商 ID 和产品 ID(可能没有序列号)。
在我的例子中,我的闪存驱动器在/proc/bus/usb/devices 中有这个条目:
T: Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 6 Spd=480 MxCh= 0
D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=0781 ProdID=5530 Rev= 2.00
S: Manufacturer=SanDisk
S: Product=Cruzer
S: SerialNumber=0765400A1BD05BEE
C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=200mA
I:* If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage
E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
我碰巧知道在我的例子中它是/dev/sda,但我不确定如何在代码中解决这个问题。我的第一种方法是遍历所有/dev/sdXX 设备并发出 SCSI_IOCTL_GET_BUS_NUMBER 和/或 SCSI_IOCTL_GET_IDLUN 请求,但返回的信息无法帮助我匹配它:
/tmp # ./getscsiinfo /dev/sda
SCSI bus number: 8
ID: 00
LUN: 00
Channel: 00
Host#: 08
four_in_one: 08000000
host_unique_id: 0
我不确定如何使用 SCSI 总线编号或 ID、LUN、 channel 、主机将其映射到/proc/bus/usb/devices 中的条目。或者我如何从/proc/bus/usb/001/006 设备获取 SCSI 总线号,这是一个 usbfs 设备并且似乎不喜欢相同的 ioctl:
/tmp # ./getscsiinfo /proc/bus/usb/001/006
Could not get bus number: Inappropriate ioctl for device
这是我的小getscsiinfo测试工具的测试代码:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <scsi/scsi.h>
#include <scsi/sg.h>
#include <sys/ioctl.h>
struct scsi_idlun
{
int four_in_one;
int host_unique_id;
};
int main(int argc, char** argv) {
if (argc != 2)
return 1;
int fd = open(argv[1], O_RDONLY | O_NONBLOCK);
if (fd < 0)
{
printf("Error opening device: %m\n");
return 1;
}
int busNumber = -1;
if (ioctl(fd, SCSI_IOCTL_GET_BUS_NUMBER, &busNumber) < 0)
{
printf("Could not get bus number: %m\n");
close(fd);
return 1;
}
printf("SCSI bus number: %d\n", busNumber);
struct scsi_idlun argid;
if (ioctl(fd, SCSI_IOCTL_GET_IDLUN, &argid) < 0)
{
printf("Could not get id: %m\n");
close(fd);
return 1;
}
printf("ID: %02x\n", argid.four_in_one & 0xFF);
printf("LUN: %02x\n", (argid.four_in_one >> 8) & 0xFF);
printf("Channel: %02x\n", (argid.four_in_one >> 16) & 0xFF);
printf("Host#: %02x\n", (argid.four_in_one >> 24) & 0xFF);
printf("four_in_one: %08x\n", (unsigned int)argid.four_in_one);
printf("host_unique_id: %d\n", argid.host_unique_id);
close(fd);
return 0;
}
有人知道吗?
最佳答案
我相信您可以使用 libudev 库收集此类信息。
以下是有关它的一些详细信息:http://www.signal11.us/oss/udev/
我在上面的网站上发现了这样的东西:
.. Using libudev, we'll be able to inspect the devices, including their Vendor ID (VID), Product ID (PID), serial number, and device strings, without ever opening the device. Further, libudev will tell us exactly where inside /dev the device's node is located, giving the application a robust and distribution-independent way of accessing the device. ...
关于c - 如何将/proc/bus/usb/devices 条目映射到/dev/sdX 设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10653794/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
i=5 expr $i + 6 1>/dev/null 将标准输出重定向到/dev/null。怎么样 expr $i + 6 >/dev/null expr $i + 6 1>/dev/null 和
在 R 中,可以握住设备,绘制图片,然后刷新设备来渲染图形。这对于具有数千个数据点、颜色渐变等的非常复杂的绘图非常有用,因为如果不保持,设备将在每次绘图操作后刷新。效果非常好。 但是,一旦绘图就位,任
我想通过串口dev文件执行IPC管道。这是要求首先我尝试使用 sudo socat /dev/ttyS0,raw,echo=0,crnl /dev/ttyS1,raw,echo=0,crnl 报错如下
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
我正在尝试使用 mpg123 播放随机歌曲命令行。但不知道我的默认音频设备是什么。或者如果我需要使用“-a”选项指定任何其他音频设备。/dev/audio 和/dev/dsp 都是音频设备。如何知道哪
我可以看到/dev/uinput 和/dev/input 都存在于我的 Ubuntu 中并且它们很相似。它们可用于检测/模拟按键/鼠标/触摸事件。所以我对它们之间的区别感到困惑?谢谢! 新增:是的,我
cat/dev/urandom 总是一种在显示器上创建滚动字符的有趣方式,但会产生太多不可打印的字符。 有没有一种简单的方法可以在命令行上对其进行编码,使其所有输出都是可读字符,例如 base64 或
是否可以在没有 bit.dev 帐户的情况下将 bit 设置为本地服务器以进行内部处理? 我知道您可能没有相同的功能 -- bit's FAQ page说“与 Bit CLI 不同,bit.dev 服
我试图在 Ubuntu 的启动过程中尽早采样一些随机性。我想知道是否有人建议如何做到这一点。我目前的想法是寻找/dev/random 和/dev/urandom 在引导序列中创建的位置,并在那里添加我
我正在尝试使用'dotnet dev-certs'工具导出https证书以包含在Docker镜像中。现在我正在使用: dotnet dev-certs https -v -ep $(HOME)\.as
我发现非常方便的 dev.copy2pdf 命令可以将我正在查看的窗口复制到 pdf 文件中,如下所示: plot(rnorm(1000)) dev.copy2pdf(file="myfile.pdf
谁能告诉我为什么从硬盘驱动器上清除数据时出于安全性考虑首选/dev/random? 最佳答案 简单的答案,/dev/random不是首选。两者同样安全。使用/dev/zero可以更轻松地进行验证。还可
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我有一个从 initramfs 镜像启动的嵌入式 Linux(vanilla、3.3.8、i486、Vortex86dx)系统。 我有一个 IDE 闪存盘,在/dev/hda1 和/dev/hda2
在Linux中,/dev/ttyS0和/dev/ttys0有什么区别? 我知道第一个是串行端口,但第二个是什么,带有小的 s? 最佳答案 see this For a pseudo terminal
我有一些命名空间的测试被自动加载到包 A 中使用 "autoload-dev": { "psr-4": { "Vendor\\PackageA\\PhpUnit\\": "te
我意识到/dev/stdout 和/dev/stderr 文件在没有根目录的 Android 设备上不存在。我同意这一点——但我需要一些方法来在我的 shell 脚本中重定向输入/输出——包括将输出重
我想对使用 composer 安装的软件包的最低支持版本运行测试,但理想情况下我想要最新版本的开发软件包。 具体来说,我想运行它来安装最低版本的软件包以进行测试: composer update --
我必须将开发分支从 testing 重命名为 tom 。重命名后,我必须创建一个具有相同名称的开发分支,它是 testing 并且它应该指向 master 的特定提交。 我已将分支重命名为: git
我是一名优秀的程序员,十分优秀!