我正在编写一个程序,它将复制 USB 可移动存储中的一些文件。所以我需要所有可用可移动存储的列表。我正在使用 C。可移植性是首选。
最佳答案
libusbx is a library that provides generic access to USB devices. As a library, it is meant to be used by developers, to facilitate the development of applications that communicate with USB hardware.
It is portable: Using a single cross-platform API, it provides access to USB devices on Linux, OS X, Windows and OpenBSD.
It is user-mode: No special privilege or elevation is required for the application to communicate with a device.
It is version-agnostic: All versions of the USB protocol, from 1.0 to 3.0 (latest), are supported.
libusb_context * usb_ctx = NULL;
int main()
{
...
libusb_init(&usb_ctx);
...
libusb_exit(usb_ctx);
...
}
some_func()
{
...
libusb_device **list;
ssize_t number_of_devices = libusb_get_device_list(usb_ctx, &list);
...
}
(警告我在网上找到了这个,我没有个人经验,代码尚未经过测试, 看来使用前需要调用libusb_init/libusb_exit,请参阅
*http://libusbx.sourceforge.net/api-1.0/group__lib.html*
和
http://libusbx.sourceforge.net/api-1.0/contexts.html.h
关于c - 如何使用C获取系统中连接的所有USB可移动存储的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10443969/