我在 FreeBSD11 上。我想获取所有连接到我的系统的设备并使用 C++ 保存它们的信息。为此,我运行 camcontrol devlist
命令。输出是:
<OCZ-VERTEX4 1.4.1.3> at scbus0 target 0 lun 0 (pass0,ada0)
<OCZ-AGILITY3 2.15> at scbus0 target 1 lun 0 (pass1,ada1)
<OCZ-AGILITY3 2.15> at scbus1 target 0 lun 0 (pass2,ada2)
<OCZ-AGILITY3 2.15> at scbus1 target 1 lun 0 (pass3,ada3)
<OCZ-AGILITY3 2.15> at scbus3 target 0 lun 0 (pass4,ada4)
< USB FLASH DRIVE PMAP> at scbus4 target 0 lun 0 (da0,pass5)
我把这个输出放在一个文件中,getline
在 C++ 中,仅从 at scbus0 target 0 lun 0 (pass0,ada0) 获取行并忽略第一部分。
我想得到 ada0,ada1,ada2,ada3,ada4,da0 然后用 /usr/local/sbin/smartctl -i /dev/<device>
获取它的信息,对于其他类似 da0、cd0 等在此命令中没有输出的信息,请保存其名称。
我不确定这是不是一个好方法。如果存在,请给我一个更好的解决方案,或者帮助我解决我的问题。
最佳答案
如果您只对磁盘感兴趣,您可以考虑尝试使用 libgeom(3)反而。它提供了获取提供者的功能。
另一种方法可能是使用 libcam 像 camcontrol 那样提取设备列表,然后您可以根据需要处理格式化。您可以在 camcontrol.c 中查看 camcontrol 程序如何执行此操作的 getdevlist 功能。
关于c++ - 使用 C++ 获取设备列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43842825/