开发者

libudev advice needed

I am embarking on a programming project that will need to confirm device identity of removable media (e.g. usb thumb drives) before it will go on to do a bunch of other cool stuff.

Some friends of mine pointed me towards using the Serial Number, and preliminary testing using the udevadm command indicates that this should work. I did some additional checking and it appears that if I can get the software working with libudev then it should (minimally) compile on ubuntu, slackware and gentoo, which would be a really nice benefit.

So I used bing to find a tutorial and got the Signal 11 site (http://www.signal11.us/oss/udev/) it's a very well-written tutorial. It actually seems to have everything I need. I download the code. Fix a couple of platform-specific bugs and then compile. BOOM! Gcc compiles without errors. So far so good.

But when I try to run it, it kicks up a couple of bugs, and I realize that I need 开发者_如何学编程to read some more tutorials so that I can understand libudev well enough to fix the bugs, and to turn out working software. Problem is that there really ISN'T any other tutorials (that I can find) and the kernel.org site that is the (only known?) site of the library documentation is down after a recent server compromise.

I considered just issuing udevadm directives to system() and then parsing results, but that's a really hackish way to put software together, and I am planning on releasing this to the community when I'm finished writing.

So how best for me to learn libudev??


libudev is quite simple library. After reading library you've mentioned and using API documentation (site should be soon up) I was able to get what I wanted. udevadm is great help, after issuing # udevadm info --query=all --name=/path/to/dev you'll get all information that udev has about this device and what's more important, these are parameters used in property functions (e.g. udev_device_get_property_value(device, "ID_VENDOR")). So best way to learn libudev is to start using it with help of signal11 tutorial, API documentation and udevadm informations.

EDIT: libudev is currently part of systemd - documentation is available as manual pages - https://www.freedesktop.org/software/systemd/man/libudev.html#


For those looking in 2023...

As Maciej pointed out, libudev is now a part of systemd.

According to:

https://www.freedesktop.org/software/systemd/man/libudev.html#

...this library is supported, but should not be used in new projects. Please see sd-device(3) for an equivalent replacement with a more modern API.

Documentation for sd-device:

https://www.freedesktop.org/software/systemd/man/sd-device.html#

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜