Retrieve device information in Linux from device file descriptor using c++ -
how can device info including device name device file descriptor?
for example, in skype can see device "/dev/snd/pcmc2d0c" has name: "usb 2.0 camera. usb audio default audio device (default:card=camera)"
how can such device name using c++?
int file = open("/dev/snd/pcmc2d0c", o_rdwr | o_nonblock, 0); if (-1 == file) // check error occurred during opening? { perror("open"); return -1; } if (-1 == ioctl(file, /* appropriate ioctl value device info? */, /* appropriate structure fill device info? */)) { perror("ioctl"); return -1; }
there no ioctl
values getting device information. in special case it's usb device, has other sources device type information.
you can sysfs
file system, mounted @ /sys
. there directory /sys/bus/usb/devices/
, has symbolic link entries pointing real devices.
on system, there example /sys/bus/usb/devices/3-4
. symbolic link leads directory /sys/devices/pci0000:00/0000:00:12.0/usb3/3-4/
, has several files identifying device.
idvendor
, idproduct
contain numbers 045e
, 00cb
. these numbers, can file /usr/share/misc/usb.ids
, find
... 045e microsoft corp. ... 00ca fingerprint reader 00cb basic optical mouse v2.0 00ce generic ppc flash device ...
you have similar information hard disk drives, example. /sys/devices/pci0000:00/0000:00:11.0/host0/target0:0:0/0:0:0:0/block/sda/
hard disk , entry device/model
in directory contains string toshiba dt01aca1
, identifying thoshiba 1tb hard disk drive.
Comments
Post a Comment