c - 如何使用C获取系统中连接的所有USB可移动存储的列表?

标签 c usb-flash-drive

我正在编写一个程序,它将复制 USB 可移动存储中的一些文件。所以我需要所有可用可移动存储的列表。我正在使用 C。可移植性是首选。

最佳答案

Possibly libusbx

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_get_device_list

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/

相关文章:

c - 在 uC-OS/II 中从 USB 内存棒读取/写入文件

包含指向堆分配内存的指针的 C 结构体的按值调用

c - IEEE-754: "smallest"溢出条件

c - X11编程显示界面

c++ - 读取输入数据并检查其有效性的通用宏

c - Linux C : How to know the default interface for internet access?

mercurial - 在闪存驱动器上运行 Mercurial?

iphone - iPhone 闪存驱动器的生命周期