Getting USB Flash Name

Hi all,
I want to get all devices that connected to my system. In order to I run
Code:
sysctl kern.disk
it gives me
Code:
ada0 ada1 ada2 cd0 da0 da1
.

Now I want to know all informations of devices. for ada I used
Code:
smartctl -i /dev/ada0
but this command not worked for flsh or cd rom.

Which command will get informations like name(sillicon power) ?
Thanks
 
Thanks for your reply.
I cannot use this command, I should get the output with c++ and this command does not save the complete output.Is there any command that I gave the name like da0 and it shows the information?
 
If the device is a SCSI device (or something that has a functioning SCSI emulation layer), send it a SCSI Inquiry command (CDB), and decode the output. The default output gives you vendor/model/revision. Then you can ask for the serial number page at page number 0x80, or you can ask for the VPD (Vital Product Data) page at page 0x83. The single best identifier for a drive is the world-wide name of the logical unit, which can usually be found on the VPD page. Note that not all bad SCSI devices (in particular SCSI emulations) will support all that information.

For SATA devices, there are equivalent ways to send "Identify" commands to the hardware, and parse the output.

For devices that implement neither SCSI nor SATA standards, it gets really gnarly. For example, you could do this for NVMe devices using the native interfaces, but it would take downloading the NVMe standards documents, and spending a few days with trial and error and writing code. I don't know about the native USB mass storage interfaces, never had to deal with that.

On FreeBSD, much of this is available using the camcontrol command. On Linux, one would typically use hdparm or one of the sg_utils programs. To get the real raw data (for example from a C++ program), you'll need to find the ioctl() calls to send low-level commands to the hardware, and learn how to do that, handle errors, and decode the output. A good initial guide for that should be the source code to sg_utils, except that it is pretty hard to read (since sg_utils has an interestingly checkered history).

As described above, you can also get much of this information from the kernel (sysctl on FreeBSD, the /sys/ file system on Linux). But beware that information is the same stuff that was originally obtained by hardware-commands (like SCSI Inquiry CDBs), and that has been cached by the kernel. Because it is cached, it can be stale (meaning: wrong!) in certain circumstances. Managing hardware is difficult and lots of work.
 
Back
Top