0

I'm on FreeBSD11. I want to get all devices that connect to my system and save their information with c++. for this reason I run camcontrol devlist command. The output is:

<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)

I put this output in a file, with getline in c++, only get the line from at scbus0 target 0 lun 0 (pass0,ada0) and ignore first part.

I want to get ada0,ada1,ada2,ada3,ada4,da0 then with /usr/local/sbin/smartctl -i /dev/<device> get it's information and for other like da0,cd0,... that won't have output in this command save their name.

I'm not sure if this is a good way or not. Please give me a better solution if exist, or help me to solve my problem.

F.M
  • 463
  • 2
  • 7
  • 20

1 Answers1

1

If you're only interested in disks, you might consider trying to use libgeom(3) instead. It offers functions to get providers.

Another approach might be to use libcam to pull the device list as camcontrol does and then you can handle formatting as needed. You can look at how the camcontrol program does this in camcontrol.c 's getdevlist function.

Lucas Holt
  • 3,826
  • 1
  • 32
  • 41
  • Thank you for your reply. It seems **camcontrol.c** is very good for this reason, but I don't know how should I use this code. Would you please say an example. Thnks – F.M May 09 '17 at 05:31